diff --git a/editors/code/package-lock.json b/editors/code/package-lock.json index a7e32e2881..adb01760a1 100644 --- a/editors/code/package-lock.json +++ b/editors/code/package-lock.json @@ -4,6 +4,26 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@babel/code-frame": { + "version": "7.5.5", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.5.5.tgz", + "integrity": "sha512-27d4lZoomVyo51VegxI20xZPuSHusqbQag/ztrBC7wegWoQ1nLREPVSKSW8byhTlzTKyNE4ifaTA6lCp7JjpFw==", + "dev": true, + "requires": { + "@babel/highlight": "^7.0.0" + } + }, + "@babel/highlight": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.5.0.tgz", + "integrity": "sha512-7dV4eu9gBxoM0dAnj/BCFDW9LFU0zvTrkq0ugM7pnHEgguOEeOz1so2ZghEdzviYzQEED0r4EAgpsBChKy1TRQ==", + "dev": true, + "requires": { + "chalk": "^2.0.0", + "esutils": "^2.0.2", + "js-tokens": "^4.0.0" + } + }, "@rollup/plugin-commonjs": { "version": "11.0.0", "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-11.0.0.tgz", @@ -240,6 +260,12 @@ "integrity": "sha1-6S7f2tplN9SE1zwBcv0eugxJdv8=", "dev": true }, + "diff": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.1.tgz", + "integrity": "sha512-s2+XdvhPCOF01LRQBC8hf4vhbVmI2CGS5aZnxLJlT5FtdhPCDFq80q++zK2KlrVorVDdL5BOGZ/VfLrVtYNF+Q==", + "dev": true + }, "dom-serializer": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.1.1.tgz", @@ -307,12 +333,24 @@ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "dev": true }, + "esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "dev": true + }, "estree-walker": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", "dev": true }, + "esutils": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", + "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", + "dev": true + }, "fd-slicer": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", @@ -401,6 +439,22 @@ } } }, + "js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", + "dev": true + }, + "js-yaml": { + "version": "3.13.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", + "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", + "dev": true, + "requires": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + } + }, "jsonc-parser": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-2.2.0.tgz", @@ -474,6 +528,21 @@ "brace-expansion": "^1.1.7" } }, + "minimist": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "dev": true + }, + "mkdirp": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "dev": true, + "requires": { + "minimist": "0.0.8" + } + }, "mute-stream": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz", @@ -683,6 +752,50 @@ "integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==", "dev": true }, + "tslint": { + "version": "5.20.1", + "resolved": "https://registry.npmjs.org/tslint/-/tslint-5.20.1.tgz", + "integrity": "sha512-EcMxhzCFt8k+/UP5r8waCf/lzmeSyVlqxqMEDQE7rWYiQky8KpIBz1JAoYXfROHrPZ1XXd43q8yQnULOLiBRQg==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "builtin-modules": "^1.1.1", + "chalk": "^2.3.0", + "commander": "^2.12.1", + "diff": "^4.0.1", + "glob": "^7.1.1", + "js-yaml": "^3.13.1", + "minimatch": "^3.0.4", + "mkdirp": "^0.5.1", + "resolve": "^1.3.2", + "semver": "^5.3.0", + "tslib": "^1.8.0", + "tsutils": "^2.29.0" + }, + "dependencies": { + "builtin-modules": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz", + "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=", + "dev": true + }, + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true + } + } + }, + "tsutils": { + "version": "2.29.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz", + "integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==", + "dev": true, + "requires": { + "tslib": "^1.8.1" + } + }, "tunnel": { "version": "0.0.4", "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.4.tgz", diff --git a/editors/code/package.json b/editors/code/package.json index 429d63f72a..7d809a2d37 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -19,7 +19,7 @@ "vscode:prepublish": "rollup -c", "package": "vsce package", "watch": "tsc -watch -p ./", - "fmt": "tsfmt -r" + "fmt": "tsfmt -r && tslint -c tslint.json 'src/**/*.ts' --fix" }, "dependencies": { "jsonc-parser": "^2.1.0", @@ -35,6 +35,7 @@ "@types/vscode": "^1.41.0", "rollup": "^1.27.14", "tslib": "^1.10.0", + "tslint": "^5.20.1", "typescript": "^3.7.3", "typescript-formatter": "^7.2.2", "vsce": "^1.71.0" diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index 94948b10fe..743384bd78 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts @@ -79,7 +79,7 @@ export function createClient(config: Config): lc.LanguageClient { } }, }; - res.registerProposedFeatures() + res.registerProposedFeatures(); return res; } function expandPathResolving(path: string) { diff --git a/editors/code/src/color_theme.ts b/editors/code/src/color_theme.ts index 1df7eba7a4..cbad47f357 100644 --- a/editors/code/src/color_theme.ts +++ b/editors/code/src/color_theme.ts @@ -32,29 +32,29 @@ export class ColorTheme { ? [rule.scope] : rule.scope; for (const scope of scopes) { - res.rules.set(scope, rule.settings) + res.rules.set(scope, rule.settings); } } - return res + return res; } lookup(scopes: string[]): TextMateRuleSettings { - let res: TextMateRuleSettings = {} + let res: TextMateRuleSettings = {}; for (const scope of scopes) { this.rules.forEach((value, key) => { if (scope.startsWith(key)) { - res = mergeRuleSettings(res, value) + res = mergeRuleSettings(res, value); } - }) + }); } - return res + return res; } mergeFrom(other: ColorTheme) { other.rules.forEach((value, key) => { - const merged = mergeRuleSettings(this.rules.get(key), value) - this.rules.set(key, merged) - }) + const merged = mergeRuleSettings(this.rules.get(key), value); + this.rules.set(key, merged); + }); } } @@ -73,15 +73,15 @@ function loadThemeNamed(themeName: string): ColorTheme { return ext.packageJSON.contributes.themes .filter((it: any) => (it.id || it.label) === themeName) .map((it: any) => path.join(ext.extensionPath, it.path)); - }) + }); const res = new ColorTheme(); for (const themePath of themePaths) { - res.mergeFrom(loadThemeFile(themePath)) + res.mergeFrom(loadThemeFile(themePath)); } const customizations: any = vscode.workspace.getConfiguration('editor').get('tokenColorCustomizations'); - res.mergeFrom(ColorTheme.fromRules(customizations?.textMateRules ?? [])) + res.mergeFrom(ColorTheme.fromRules(customizations?.textMateRules ?? [])); return res; } @@ -89,7 +89,7 @@ function loadThemeNamed(themeName: string): ColorTheme { function loadThemeFile(themePath: string): ColorTheme { let text; try { - text = fs.readFileSync(themePath, 'utf8') + text = fs.readFileSync(themePath, 'utf8'); } catch { return new ColorTheme(); } @@ -119,5 +119,5 @@ function mergeRuleSettings( foreground: override.foreground ?? defaultSetting?.foreground, background: override.background ?? defaultSetting?.background, fontStyle: override.fontStyle ?? defaultSetting?.fontStyle, - } + }; } diff --git a/editors/code/src/commands/analyzer_status.ts b/editors/code/src/commands/analyzer_status.ts index cf37dc6f03..cfe7d1af05 100644 --- a/editors/code/src/commands/analyzer_status.ts +++ b/editors/code/src/commands/analyzer_status.ts @@ -49,7 +49,7 @@ class TextDocumentContentProvider _uri: vscode.Uri, ): vscode.ProviderResult { const editor = vscode.window.activeTextEditor; - const client = this.ctx.client + const client = this.ctx.client; if (!editor || !client) return ''; return client.sendRequest( diff --git a/editors/code/src/commands/expand_macro.ts b/editors/code/src/commands/expand_macro.ts index 472f43b8db..dcdde78af5 100644 --- a/editors/code/src/commands/expand_macro.ts +++ b/editors/code/src/commands/expand_macro.ts @@ -52,7 +52,7 @@ class TextDocumentContentProvider async provideTextDocumentContent(_uri: vscode.Uri): Promise { const editor = vscode.window.activeTextEditor; - const client = this.ctx.client + const client = this.ctx.client; if (!editor || !client) return ''; const position = editor.selection.active; diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index 4431fdcf68..9a1697dcbe 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts @@ -36,14 +36,14 @@ function showReferences(ctx: Ctx): Cmd { function applySourceChange(ctx: Ctx): Cmd { return async (change: sourceChange.SourceChange) => { sourceChange.applySourceChange(ctx, change); - } + }; } function reload(ctx: Ctx): Cmd { return async () => { vscode.window.showInformationMessage('Reloading rust-analyzer...'); await ctx.restartServer(); - } + }; } export { diff --git a/editors/code/src/commands/syntax_tree.ts b/editors/code/src/commands/syntax_tree.ts index 2ee80f910c..02ea9f1667 100644 --- a/editors/code/src/commands/syntax_tree.ts +++ b/editors/code/src/commands/syntax_tree.ts @@ -76,7 +76,7 @@ class TextDocumentContentProvider provideTextDocumentContent(uri: vscode.Uri): vscode.ProviderResult { const editor = vscode.window.activeTextEditor; - const client = this.ctx.client + const client = this.ctx.client; if (!editor || !client) return ''; let range: lc.Range | undefined; diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index 13988056aa..a2a4e42a9b 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts @@ -1,7 +1,7 @@ import * as vscode from 'vscode'; import * as lc from 'vscode-languageclient'; import { Config } from './config'; -import { createClient } from './client' +import { createClient } from './client'; export class Ctx { readonly config: Config; @@ -10,28 +10,28 @@ export class Ctx { // deal with it. // // Ideally, this should be replaced with async getter though. - client: lc.LanguageClient | null = null + client: lc.LanguageClient | null = null; private extCtx: vscode.ExtensionContext; private onDidRestartHooks: Array<(client: lc.LanguageClient) => void> = []; constructor(extCtx: vscode.ExtensionContext) { - this.config = new Config(extCtx) + this.config = new Config(extCtx); this.extCtx = extCtx; } async restartServer() { let old = this.client; if (old) { - await old.stop() + await old.stop(); } this.client = null; const client = createClient(this.config); this.pushCleanup(client.start()); await client.onReady(); - this.client = client + this.client = client; for (const hook of this.onDidRestartHooks) { - hook(client) + hook(client); } } @@ -80,7 +80,7 @@ export class Ctx { } onDidRestart(hook: (client: lc.LanguageClient) => void) { - this.onDidRestartHooks.push(hook) + this.onDidRestartHooks.push(hook); } } diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts index f9d2e9d909..014e96f753 100644 --- a/editors/code/src/highlighting.ts +++ b/editors/code/src/highlighting.ts @@ -30,7 +30,7 @@ export function activateHighlighting(ctx: Ctx) { highlighter.setHighlights(targetEditor, params.decorations); }, ); - }) + }); vscode.workspace.onDidChangeConfiguration( _ => highlighter.removeHighlights(), @@ -173,13 +173,13 @@ class Highlighter { function initDecorations(): Map { const theme = ColorTheme.load(); - const res = new Map() + const res = new Map(); TAG_TO_SCOPES.forEach((scopes, tag) => { - if (!scopes) throw `unmapped tag: ${tag}` - let rule = theme.lookup(scopes) + if (!scopes) throw `unmapped tag: ${tag}`; + let rule = theme.lookup(scopes); const decor = createDecorationFromTextmate(rule); - res.set(tag, decor) - }) + res.set(tag, decor); + }); return res; } diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts index e74d6996f8..6dd767d724 100644 --- a/editors/code/src/inlay_hints.ts +++ b/editors/code/src/inlay_hints.ts @@ -19,7 +19,7 @@ export function activateInlayHints(ctx: Ctx) { hintsUpdater.setEnabled(ctx.config.displayInlayHints); }, ctx.subscriptions); - ctx.onDidRestart(_ => hintsUpdater.setEnabled(ctx.config.displayInlayHints)) + ctx.onDidRestart(_ => hintsUpdater.setEnabled(ctx.config.displayInlayHints)); } interface InlayHintsParams { @@ -96,7 +96,7 @@ class HintsUpdater { private async queryHints(documentUri: string): Promise { let client = this.ctx.client; - if (!client) return null + if (!client) return null; const request: InlayHintsParams = { textDocument: { uri: documentUri }, }; diff --git a/editors/code/src/source_change.ts b/editors/code/src/source_change.ts index 887191d9e5..a336269baa 100644 --- a/editors/code/src/source_change.ts +++ b/editors/code/src/source_change.ts @@ -11,7 +11,7 @@ export interface SourceChange { export async function applySourceChange(ctx: Ctx, change: SourceChange) { const client = ctx.client; - if (!client) return + if (!client) return; const wsEdit = client.protocol2CodeConverter.asWorkspaceEdit( change.workspaceEdit, diff --git a/editors/code/src/status_display.ts b/editors/code/src/status_display.ts index 1454bf8b00..08cdc8bdf6 100644 --- a/editors/code/src/status_display.ts +++ b/editors/code/src/status_display.ts @@ -9,7 +9,7 @@ export function activateStatusDisplay(ctx: Ctx) { ctx.pushCleanup(statusDisplay); ctx.onDidRestart(client => { client.onNotification('$/progress', params => statusDisplay.handleProgressNotification(params)); - }) + }); } class StatusDisplay implements vscode.Disposable { diff --git a/editors/code/tslint.json b/editors/code/tslint.json new file mode 100644 index 0000000000..318e02b4b3 --- /dev/null +++ b/editors/code/tslint.json @@ -0,0 +1,8 @@ +{ + "rules": { + "semicolon": [ + true, + "always" + ] + } +}