mirror of
https://github.com/mtshiba/pylyzer.git
synced 2025-07-07 17:45:00 +00:00
renovate VSCode extension
This commit is contained in:
parent
6a2afdef2f
commit
5c769f7ab8
15 changed files with 2841 additions and 35 deletions
3
extension/.vscode/extensions.json
vendored
Normal file
3
extension/.vscode/extensions.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"recommendations": ["amodio.tsl-problem-matcher", "rome.rome"]
|
||||
}
|
37
extension/.vscode/tasks.json
vendored
Normal file
37
extension/.vscode/tasks.json
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "watch",
|
||||
"problemMatcher": ["$ts-webpack-watch", "$tslint-webpack-watch"],
|
||||
"isBackground": true,
|
||||
"presentation": {
|
||||
"reveal": "never",
|
||||
"group": "watchers"
|
||||
},
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "watch-tests",
|
||||
"problemMatcher": "$tsc-watch",
|
||||
"isBackground": true,
|
||||
"presentation": {
|
||||
"reveal": "never",
|
||||
"group": "watchers"
|
||||
},
|
||||
"group": "build"
|
||||
},
|
||||
{
|
||||
"label": "tasks: watch-tests",
|
||||
"dependsOn": ["npm: watch", "npm: watch-tests"],
|
||||
"problemMatcher": []
|
||||
}
|
||||
]
|
||||
}
|
1
extension/dist/extension.js
vendored
Normal file
1
extension/dist/extension.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
extension/dist/extension.js.map
vendored
Normal file
1
extension/dist/extension.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -1,32 +0,0 @@
|
|||
"use strict";
|
||||
const vscode = require("vscode");
|
||||
const languageclient = require("vscode-languageclient");
|
||||
|
||||
let client;
|
||||
|
||||
function activate(context) {
|
||||
try {
|
||||
const serverOptions = {
|
||||
command: "pylyzer",
|
||||
args: ["--server", "--", "--disable", "inlayHints"]
|
||||
};
|
||||
const clientOptions = {
|
||||
documentSelector: [
|
||||
{
|
||||
scheme: "file",
|
||||
language: "python",
|
||||
}
|
||||
],
|
||||
};
|
||||
client = new languageclient.LanguageClient("pylyzer", serverOptions, clientOptions);
|
||||
context.subscriptions.push(client.start());
|
||||
} catch (e) {
|
||||
vscode.window.showErrorMessage("failed to start pylyzer.");
|
||||
}
|
||||
}
|
||||
|
||||
function deactivate() {
|
||||
if (client) return client.stop();
|
||||
}
|
||||
|
||||
module.exports = { activate, deactivate }
|
2465
extension/package-lock.json
generated
2465
extension/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -3,7 +3,7 @@
|
|||
"displayName": "pylyzer",
|
||||
"description": "A fast Python static code analyzer & language server for VSCode",
|
||||
"publisher": "pylyzer",
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.2",
|
||||
"engines": {
|
||||
"vscode": "^1.70.0"
|
||||
},
|
||||
|
@ -15,11 +15,18 @@
|
|||
"type": "git",
|
||||
"url": "https://github.com/mtshiba/pylyzer.git"
|
||||
},
|
||||
"main": "./extension.js",
|
||||
"main": "./dist/extension.js",
|
||||
"activationEvents": [
|
||||
"onLanguage:python"
|
||||
],
|
||||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
"title": "Restart the pylyzer language server",
|
||||
"category": "python",
|
||||
"command": "pylyzer.restartLanguageServer"
|
||||
}
|
||||
],
|
||||
"languages": [
|
||||
{
|
||||
"id": "python",
|
||||
|
@ -31,9 +38,65 @@
|
|||
".py"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"configuration": {
|
||||
"type": "object",
|
||||
"title": "pylyzer",
|
||||
"properties": {
|
||||
"pylyzer.inlayHints": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"markdownDescription": "Enable inlay hints (this feature is unstable)"
|
||||
},
|
||||
"pylyzer.smartCompletion": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"markdownDescription": "Enable smart completion (see [ELS features](https://github.com/erg-lang/erg/blob/main/crates/els/doc/features.md))"
|
||||
},
|
||||
"pylyzer.checkOnType": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"markdownDescription": "Perform checking each time any character is entered. This improves the accuracy of completion, etc., but may slow down the execution"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:publish": "vsce publish",
|
||||
"vscode:prepublish": "npm run package",
|
||||
"vscode:package": "vsce package",
|
||||
"compile": "webpack",
|
||||
"watch": "webpack --watch",
|
||||
"package": "webpack --mode production --devtool hidden-source-map",
|
||||
"compile-tests": "tsc -p . --outDir out",
|
||||
"watch-tests": "tsc -p . -w --outDir out",
|
||||
"pretest": "npm run compile-tests && npm run compile && npm run lint",
|
||||
"test": "node ./out/test/runTest.js",
|
||||
"type-check": "tsc --noEmit",
|
||||
"lint": "rome check .",
|
||||
"format": "rome format .",
|
||||
"lint:fix": "rome check --apply .",
|
||||
"lint:fix-suggested": "rome check --apply-suggested .",
|
||||
"format:fix": "rome format --write ."
|
||||
},
|
||||
"dependencies": {
|
||||
"vscode-languageclient": "^8.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/glob": "^8.0.0",
|
||||
"@types/mocha": "^10.0.1",
|
||||
"@types/node": "18.x",
|
||||
"@types/vscode": "^1.70.0",
|
||||
"@vscode/test-electron": "^2.2.1",
|
||||
"glob": "^8.0.3",
|
||||
"mocha": "^10.2.0",
|
||||
"rome": "^10.0.1",
|
||||
"ts-loader": "^9.4.2",
|
||||
"typescript": "^4.9.4",
|
||||
"webpack": "^5.75.0",
|
||||
"webpack-cli": "^5.0.1"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*": "rome format --write"
|
||||
}
|
||||
}
|
||||
|
|
11
extension/rome.json
Normal file
11
extension/rome.json
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"linter": {
|
||||
"rules": {
|
||||
"recommended": true
|
||||
},
|
||||
"ignore": ["/dist/", "/out/", "/.vscode-test/"]
|
||||
},
|
||||
"formatter": {
|
||||
"ignore": ["/dist/", "/out/", "/.vscode-test/"]
|
||||
}
|
||||
}
|
19
extension/src/commands.ts
Normal file
19
extension/src/commands.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
// copied and modified from https://github.com/rust-lang/rust-analyzer/blob/27239fbb58a115915ffc1ce65ededc951eb00fd2/editors/code/src/commands.ts
|
||||
import { LanguageClient, Location, Position } from 'vscode-languageclient/node';
|
||||
import { Uri, commands } from 'vscode';
|
||||
|
||||
export async function showReferences(
|
||||
client: LanguageClient | undefined,
|
||||
uri: string,
|
||||
position: Position,
|
||||
locations: Location[]
|
||||
) {
|
||||
if (client) {
|
||||
await commands.executeCommand(
|
||||
"editor.action.showReferences",
|
||||
Uri.parse(uri),
|
||||
client.protocol2CodeConverter.asPosition(position),
|
||||
locations.map(client.protocol2CodeConverter.asLocation)
|
||||
);
|
||||
}
|
||||
}
|
97
extension/src/extension.ts
Normal file
97
extension/src/extension.ts
Normal file
|
@ -0,0 +1,97 @@
|
|||
import { ExtensionContext, commands, window, workspace } from "vscode";
|
||||
import {
|
||||
LanguageClient,
|
||||
LanguageClientOptions,
|
||||
ServerOptions,
|
||||
} from "vscode-languageclient/node";
|
||||
import { showReferences } from "./commands";
|
||||
|
||||
let client: LanguageClient | undefined;
|
||||
|
||||
async function startLanguageClient(context: ExtensionContext) {
|
||||
try {
|
||||
const executablePath = (() => {
|
||||
let executablePath = workspace
|
||||
.getConfiguration("pylyzer")
|
||||
.get<string>("executablePath", "");
|
||||
return executablePath === "" ? "pylyzer" : executablePath;
|
||||
})();
|
||||
const enableInlayHints = workspace.getConfiguration("pylyzer").get<boolean>("inlayHints", false);
|
||||
const enableSemanticTokens = workspace.getConfiguration("pylyzer").get<boolean>("semanticTokens", true);
|
||||
const enableHover = workspace.getConfiguration("pylyzer").get<boolean>("hover", true);
|
||||
const smartCompletion = workspace.getConfiguration("pylyzer").get<boolean>("smartCompletion", true);
|
||||
/* optional features */
|
||||
const checkOnType = workspace.getConfiguration("pylyzer").get<boolean>("checkOnType", false);
|
||||
let args = ["--server"];
|
||||
if (!(enableInlayHints && enableSemanticTokens && enableHover && smartCompletion) || checkOnType) {
|
||||
args.push("--");
|
||||
}
|
||||
if (!enableInlayHints) {
|
||||
args.push("--disable");
|
||||
args.push("inlayHints");
|
||||
}
|
||||
if (!enableSemanticTokens) {
|
||||
args.push("--disable");
|
||||
args.push("semanticTokens");
|
||||
}
|
||||
if (!enableHover) {
|
||||
args.push("--disable");
|
||||
args.push("hover");
|
||||
}
|
||||
if (!smartCompletion) {
|
||||
args.push("--disable");
|
||||
args.push("smartCompletion");
|
||||
}
|
||||
if (checkOnType) {
|
||||
args.push("--enable");
|
||||
args.push("checkOnType");
|
||||
}
|
||||
let serverOptions: ServerOptions = {
|
||||
command: executablePath,
|
||||
args,
|
||||
};
|
||||
const clientOptions: LanguageClientOptions = {
|
||||
documentSelector: [
|
||||
{
|
||||
scheme: "file",
|
||||
language: "python",
|
||||
},
|
||||
],
|
||||
};
|
||||
client = new LanguageClient("pylyzer", serverOptions, clientOptions);
|
||||
await client.start();
|
||||
} catch (e) {
|
||||
window.showErrorMessage(
|
||||
"Failed to start the pylyzer language server. Please make sure you have pylyzer installed.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function restartLanguageClient() {
|
||||
try {
|
||||
if (client === undefined) {
|
||||
throw new Error();
|
||||
}
|
||||
await client.restart();
|
||||
} catch (e) {
|
||||
window.showErrorMessage("Failed to restart the pylyzer language server.");
|
||||
}
|
||||
}
|
||||
|
||||
export async function activate(context: ExtensionContext) {
|
||||
context.subscriptions.push(
|
||||
commands.registerCommand("pylyzer.restartLanguageServer", () => restartLanguageClient())
|
||||
);
|
||||
context.subscriptions.push(
|
||||
commands.registerCommand("pylyzer.showReferences", async (uri, position, locations) => {
|
||||
await showReferences(client, uri, position, locations)
|
||||
})
|
||||
);
|
||||
await startLanguageClient(context);
|
||||
}
|
||||
|
||||
export function deactivate() {
|
||||
if (client) {
|
||||
return client.stop();
|
||||
}
|
||||
}
|
23
extension/src/test/runTest.ts
Normal file
23
extension/src/test/runTest.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import * as path from "path";
|
||||
|
||||
import { runTests } from "@vscode/test-electron";
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
// The folder containing the Extension Manifest package.json
|
||||
// Passed to `--extensionDevelopmentPath`
|
||||
const extensionDevelopmentPath = path.resolve(__dirname, "../../");
|
||||
|
||||
// The path to test runner
|
||||
// Passed to --extensionTestsPath
|
||||
const extensionTestsPath = path.resolve(__dirname, "./suite/index");
|
||||
|
||||
// Download VS Code, unzip it and run the integration test
|
||||
await runTests({ extensionDevelopmentPath, extensionTestsPath });
|
||||
} catch (err) {
|
||||
console.error("Failed to run tests");
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
15
extension/src/test/suite/extension.test.ts
Normal file
15
extension/src/test/suite/extension.test.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import * as assert from "assert";
|
||||
|
||||
// You can import and use all API from the 'vscode' module
|
||||
// as well as import your extension to test it
|
||||
import * as vscode from "vscode";
|
||||
// import * as myExtension from '../../extension';
|
||||
|
||||
suite("Extension Test Suite", () => {
|
||||
vscode.window.showInformationMessage("Start all tests.");
|
||||
|
||||
test("Sample test", () => {
|
||||
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
|
||||
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
|
||||
});
|
||||
});
|
38
extension/src/test/suite/index.ts
Normal file
38
extension/src/test/suite/index.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
import * as path from "path";
|
||||
import Mocha from "mocha";
|
||||
import glob from "glob";
|
||||
|
||||
export function run(): Promise<void> {
|
||||
// Create the mocha test
|
||||
const mocha = new Mocha({
|
||||
ui: "tdd",
|
||||
color: true,
|
||||
});
|
||||
|
||||
const testsRoot = path.resolve(__dirname, "..");
|
||||
|
||||
return new Promise((c, e) => {
|
||||
glob("**/**.test.js", { cwd: testsRoot }, (err, files) => {
|
||||
if (err) {
|
||||
return e(err);
|
||||
}
|
||||
|
||||
// Add files to the test suite
|
||||
files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f)));
|
||||
|
||||
try {
|
||||
// Run the mocha test
|
||||
mocha.run((failures) => {
|
||||
if (failures > 0) {
|
||||
e(new Error(`${failures} tests failed.`));
|
||||
} else {
|
||||
c();
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
e(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
17
extension/tsconfig.json
Normal file
17
extension/tsconfig.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "ES2020",
|
||||
"moduleResolution": "node",
|
||||
"lib": ["ES2020"],
|
||||
"sourceMap": true,
|
||||
"esModuleInterop": true,
|
||||
"rootDir": "src",
|
||||
"strict": true /* enable all strict type-checking options */
|
||||
/* Additional Checks */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
},
|
||||
"exclude": ["node_modules", ".vscode-test"]
|
||||
}
|
48
extension/webpack.config.js
Normal file
48
extension/webpack.config.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
//@ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
|
||||
//@ts-check
|
||||
/** @typedef {import('webpack').Configuration} WebpackConfig **/
|
||||
|
||||
/** @type WebpackConfig */
|
||||
const extensionConfig = {
|
||||
target: "node", // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
|
||||
mode: "none", // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
|
||||
|
||||
entry: "./src/extension.ts", // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
|
||||
output: {
|
||||
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
|
||||
path: path.resolve(__dirname, "dist"),
|
||||
filename: "extension.js",
|
||||
libraryTarget: "commonjs2",
|
||||
},
|
||||
externals: {
|
||||
vscode: "commonjs vscode", // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
|
||||
// modules added here also need to be added in the .vscodeignore file
|
||||
},
|
||||
resolve: {
|
||||
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
|
||||
extensions: [".ts", ".js"],
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.ts$/,
|
||||
exclude: /node_modules/,
|
||||
use: [
|
||||
{
|
||||
loader: "ts-loader",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
devtool: "nosources-source-map",
|
||||
infrastructureLogging: {
|
||||
level: "log", // enables logging required for problem matchers
|
||||
},
|
||||
};
|
||||
module.exports = [extensionConfig];
|
Loading…
Add table
Add a link
Reference in a new issue