Add semicolons

This commit is contained in:
Aleksey Kladov 2019-12-31 18:55:34 +01:00
parent cb41ffbbbd
commit ff0ceb30a9
14 changed files with 160 additions and 38 deletions

View file

@ -4,6 +4,26 @@
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "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": { "@rollup/plugin-commonjs": {
"version": "11.0.0", "version": "11.0.0",
"resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-11.0.0.tgz", "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-11.0.0.tgz",
@ -240,6 +260,12 @@
"integrity": "sha1-6S7f2tplN9SE1zwBcv0eugxJdv8=", "integrity": "sha1-6S7f2tplN9SE1zwBcv0eugxJdv8=",
"dev": true "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": { "dom-serializer": {
"version": "0.1.1", "version": "0.1.1",
"resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.1.1.tgz", "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.1.1.tgz",
@ -307,12 +333,24 @@
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
"dev": true "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": { "estree-walker": {
"version": "0.6.1", "version": "0.6.1",
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz",
"integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==",
"dev": true "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": { "fd-slicer": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", "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": { "jsonc-parser": {
"version": "2.2.0", "version": "2.2.0",
"resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-2.2.0.tgz", "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-2.2.0.tgz",
@ -474,6 +528,21 @@
"brace-expansion": "^1.1.7" "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": { "mute-stream": {
"version": "0.0.8", "version": "0.0.8",
"resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz", "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz",
@ -683,6 +752,50 @@
"integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==", "integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==",
"dev": true "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": { "tunnel": {
"version": "0.0.4", "version": "0.0.4",
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.4.tgz", "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.4.tgz",

View file

@ -19,7 +19,7 @@
"vscode:prepublish": "rollup -c", "vscode:prepublish": "rollup -c",
"package": "vsce package", "package": "vsce package",
"watch": "tsc -watch -p ./", "watch": "tsc -watch -p ./",
"fmt": "tsfmt -r" "fmt": "tsfmt -r && tslint -c tslint.json 'src/**/*.ts' --fix"
}, },
"dependencies": { "dependencies": {
"jsonc-parser": "^2.1.0", "jsonc-parser": "^2.1.0",
@ -35,6 +35,7 @@
"@types/vscode": "^1.41.0", "@types/vscode": "^1.41.0",
"rollup": "^1.27.14", "rollup": "^1.27.14",
"tslib": "^1.10.0", "tslib": "^1.10.0",
"tslint": "^5.20.1",
"typescript": "^3.7.3", "typescript": "^3.7.3",
"typescript-formatter": "^7.2.2", "typescript-formatter": "^7.2.2",
"vsce": "^1.71.0" "vsce": "^1.71.0"

View file

@ -79,7 +79,7 @@ export function createClient(config: Config): lc.LanguageClient {
} }
}, },
}; };
res.registerProposedFeatures() res.registerProposedFeatures();
return res; return res;
} }
function expandPathResolving(path: string) { function expandPathResolving(path: string) {

View file

@ -32,29 +32,29 @@ export class ColorTheme {
? [rule.scope] ? [rule.scope]
: rule.scope; : rule.scope;
for (const scope of scopes) { 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 { lookup(scopes: string[]): TextMateRuleSettings {
let res: TextMateRuleSettings = {} let res: TextMateRuleSettings = {};
for (const scope of scopes) { for (const scope of scopes) {
this.rules.forEach((value, key) => { this.rules.forEach((value, key) => {
if (scope.startsWith(key)) { if (scope.startsWith(key)) {
res = mergeRuleSettings(res, value) res = mergeRuleSettings(res, value);
} }
}) });
} }
return res return res;
} }
mergeFrom(other: ColorTheme) { mergeFrom(other: ColorTheme) {
other.rules.forEach((value, key) => { other.rules.forEach((value, key) => {
const merged = mergeRuleSettings(this.rules.get(key), value) const merged = mergeRuleSettings(this.rules.get(key), value);
this.rules.set(key, merged) this.rules.set(key, merged);
}) });
} }
} }
@ -73,15 +73,15 @@ function loadThemeNamed(themeName: string): ColorTheme {
return ext.packageJSON.contributes.themes return ext.packageJSON.contributes.themes
.filter((it: any) => (it.id || it.label) === themeName) .filter((it: any) => (it.id || it.label) === themeName)
.map((it: any) => path.join(ext.extensionPath, it.path)); .map((it: any) => path.join(ext.extensionPath, it.path));
}) });
const res = new ColorTheme(); const res = new ColorTheme();
for (const themePath of themePaths) { for (const themePath of themePaths) {
res.mergeFrom(loadThemeFile(themePath)) res.mergeFrom(loadThemeFile(themePath));
} }
const customizations: any = vscode.workspace.getConfiguration('editor').get('tokenColorCustomizations'); const customizations: any = vscode.workspace.getConfiguration('editor').get('tokenColorCustomizations');
res.mergeFrom(ColorTheme.fromRules(customizations?.textMateRules ?? [])) res.mergeFrom(ColorTheme.fromRules(customizations?.textMateRules ?? []));
return res; return res;
} }
@ -89,7 +89,7 @@ function loadThemeNamed(themeName: string): ColorTheme {
function loadThemeFile(themePath: string): ColorTheme { function loadThemeFile(themePath: string): ColorTheme {
let text; let text;
try { try {
text = fs.readFileSync(themePath, 'utf8') text = fs.readFileSync(themePath, 'utf8');
} catch { } catch {
return new ColorTheme(); return new ColorTheme();
} }
@ -119,5 +119,5 @@ function mergeRuleSettings(
foreground: override.foreground ?? defaultSetting?.foreground, foreground: override.foreground ?? defaultSetting?.foreground,
background: override.background ?? defaultSetting?.background, background: override.background ?? defaultSetting?.background,
fontStyle: override.fontStyle ?? defaultSetting?.fontStyle, fontStyle: override.fontStyle ?? defaultSetting?.fontStyle,
} };
} }

View file

@ -49,7 +49,7 @@ class TextDocumentContentProvider
_uri: vscode.Uri, _uri: vscode.Uri,
): vscode.ProviderResult<string> { ): vscode.ProviderResult<string> {
const editor = vscode.window.activeTextEditor; const editor = vscode.window.activeTextEditor;
const client = this.ctx.client const client = this.ctx.client;
if (!editor || !client) return ''; if (!editor || !client) return '';
return client.sendRequest<string>( return client.sendRequest<string>(

View file

@ -52,7 +52,7 @@ class TextDocumentContentProvider
async provideTextDocumentContent(_uri: vscode.Uri): Promise<string> { async provideTextDocumentContent(_uri: vscode.Uri): Promise<string> {
const editor = vscode.window.activeTextEditor; const editor = vscode.window.activeTextEditor;
const client = this.ctx.client const client = this.ctx.client;
if (!editor || !client) return ''; if (!editor || !client) return '';
const position = editor.selection.active; const position = editor.selection.active;

View file

@ -36,14 +36,14 @@ function showReferences(ctx: Ctx): Cmd {
function applySourceChange(ctx: Ctx): Cmd { function applySourceChange(ctx: Ctx): Cmd {
return async (change: sourceChange.SourceChange) => { return async (change: sourceChange.SourceChange) => {
sourceChange.applySourceChange(ctx, change); sourceChange.applySourceChange(ctx, change);
} };
} }
function reload(ctx: Ctx): Cmd { function reload(ctx: Ctx): Cmd {
return async () => { return async () => {
vscode.window.showInformationMessage('Reloading rust-analyzer...'); vscode.window.showInformationMessage('Reloading rust-analyzer...');
await ctx.restartServer(); await ctx.restartServer();
} };
} }
export { export {

View file

@ -76,7 +76,7 @@ class TextDocumentContentProvider
provideTextDocumentContent(uri: vscode.Uri): vscode.ProviderResult<string> { provideTextDocumentContent(uri: vscode.Uri): vscode.ProviderResult<string> {
const editor = vscode.window.activeTextEditor; const editor = vscode.window.activeTextEditor;
const client = this.ctx.client const client = this.ctx.client;
if (!editor || !client) return ''; if (!editor || !client) return '';
let range: lc.Range | undefined; let range: lc.Range | undefined;

View file

@ -1,7 +1,7 @@
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import * as lc from 'vscode-languageclient'; import * as lc from 'vscode-languageclient';
import { Config } from './config'; import { Config } from './config';
import { createClient } from './client' import { createClient } from './client';
export class Ctx { export class Ctx {
readonly config: Config; readonly config: Config;
@ -10,28 +10,28 @@ export class Ctx {
// deal with it. // deal with it.
// //
// Ideally, this should be replaced with async getter though. // Ideally, this should be replaced with async getter though.
client: lc.LanguageClient | null = null client: lc.LanguageClient | null = null;
private extCtx: vscode.ExtensionContext; private extCtx: vscode.ExtensionContext;
private onDidRestartHooks: Array<(client: lc.LanguageClient) => void> = []; private onDidRestartHooks: Array<(client: lc.LanguageClient) => void> = [];
constructor(extCtx: vscode.ExtensionContext) { constructor(extCtx: vscode.ExtensionContext) {
this.config = new Config(extCtx) this.config = new Config(extCtx);
this.extCtx = extCtx; this.extCtx = extCtx;
} }
async restartServer() { async restartServer() {
let old = this.client; let old = this.client;
if (old) { if (old) {
await old.stop() await old.stop();
} }
this.client = null; this.client = null;
const client = createClient(this.config); const client = createClient(this.config);
this.pushCleanup(client.start()); this.pushCleanup(client.start());
await client.onReady(); await client.onReady();
this.client = client this.client = client;
for (const hook of this.onDidRestartHooks) { for (const hook of this.onDidRestartHooks) {
hook(client) hook(client);
} }
} }
@ -80,7 +80,7 @@ export class Ctx {
} }
onDidRestart(hook: (client: lc.LanguageClient) => void) { onDidRestart(hook: (client: lc.LanguageClient) => void) {
this.onDidRestartHooks.push(hook) this.onDidRestartHooks.push(hook);
} }
} }

View file

@ -30,7 +30,7 @@ export function activateHighlighting(ctx: Ctx) {
highlighter.setHighlights(targetEditor, params.decorations); highlighter.setHighlights(targetEditor, params.decorations);
}, },
); );
}) });
vscode.workspace.onDidChangeConfiguration( vscode.workspace.onDidChangeConfiguration(
_ => highlighter.removeHighlights(), _ => highlighter.removeHighlights(),
@ -173,13 +173,13 @@ class Highlighter {
function initDecorations(): Map<string, vscode.TextEditorDecorationType> { function initDecorations(): Map<string, vscode.TextEditorDecorationType> {
const theme = ColorTheme.load(); const theme = ColorTheme.load();
const res = new Map() const res = new Map();
TAG_TO_SCOPES.forEach((scopes, tag) => { TAG_TO_SCOPES.forEach((scopes, tag) => {
if (!scopes) throw `unmapped tag: ${tag}` if (!scopes) throw `unmapped tag: ${tag}`;
let rule = theme.lookup(scopes) let rule = theme.lookup(scopes);
const decor = createDecorationFromTextmate(rule); const decor = createDecorationFromTextmate(rule);
res.set(tag, decor) res.set(tag, decor);
}) });
return res; return res;
} }

View file

@ -19,7 +19,7 @@ export function activateInlayHints(ctx: Ctx) {
hintsUpdater.setEnabled(ctx.config.displayInlayHints); hintsUpdater.setEnabled(ctx.config.displayInlayHints);
}, ctx.subscriptions); }, ctx.subscriptions);
ctx.onDidRestart(_ => hintsUpdater.setEnabled(ctx.config.displayInlayHints)) ctx.onDidRestart(_ => hintsUpdater.setEnabled(ctx.config.displayInlayHints));
} }
interface InlayHintsParams { interface InlayHintsParams {
@ -96,7 +96,7 @@ class HintsUpdater {
private async queryHints(documentUri: string): Promise<InlayHint[] | null> { private async queryHints(documentUri: string): Promise<InlayHint[] | null> {
let client = this.ctx.client; let client = this.ctx.client;
if (!client) return null if (!client) return null;
const request: InlayHintsParams = { const request: InlayHintsParams = {
textDocument: { uri: documentUri }, textDocument: { uri: documentUri },
}; };

View file

@ -11,7 +11,7 @@ export interface SourceChange {
export async function applySourceChange(ctx: Ctx, change: SourceChange) { export async function applySourceChange(ctx: Ctx, change: SourceChange) {
const client = ctx.client; const client = ctx.client;
if (!client) return if (!client) return;
const wsEdit = client.protocol2CodeConverter.asWorkspaceEdit( const wsEdit = client.protocol2CodeConverter.asWorkspaceEdit(
change.workspaceEdit, change.workspaceEdit,

View file

@ -9,7 +9,7 @@ export function activateStatusDisplay(ctx: Ctx) {
ctx.pushCleanup(statusDisplay); ctx.pushCleanup(statusDisplay);
ctx.onDidRestart(client => { ctx.onDidRestart(client => {
client.onNotification('$/progress', params => statusDisplay.handleProgressNotification(params)); client.onNotification('$/progress', params => statusDisplay.handleProgressNotification(params));
}) });
} }
class StatusDisplay implements vscode.Disposable { class StatusDisplay implements vscode.Disposable {

8
editors/code/tslint.json Normal file
View file

@ -0,0 +1,8 @@
{
"rules": {
"semicolon": [
true,
"always"
]
}
}