From 8153b60e1d8abdcefbf6c7c9657f1ce65a216d7a Mon Sep 17 00:00:00 2001 From: Veetaha Date: Wed, 5 Feb 2020 22:39:47 +0200 Subject: vscode: eliminate floating promises and insane amount of resource handle leaks --- editors/code/package.json | 2 +- editors/code/src/commands/index.ts | 2 +- editors/code/src/commands/syntax_tree.ts | 2 ++ editors/code/src/config.ts | 2 +- editors/code/src/highlighting.ts | 2 ++ editors/code/src/inlay_hints.ts | 34 ++++++++++++++++++++------------ editors/code/src/status_display.ts | 10 ++++++---- editors/code/tslint.json | 3 ++- 8 files changed, 36 insertions(+), 21 deletions(-) (limited to 'editors/code') diff --git a/editors/code/package.json b/editors/code/package.json index c9404a4dd..11d37053e 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -21,7 +21,7 @@ "vscode:prepublish": "tsc && rollup -c", "package": "vsce package", "watch": "tsc --watch", - "fmt": "tsfmt -r && tslint -c tslint.json 'src/**/*.ts' --fix" + "fmt": "tsfmt -r && tslint -p tsconfig.json -c tslint.json 'src/**/*.ts' --fix" }, "dependencies": { "jsonc-parser": "^2.1.0", diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index 5a4c1df5e..aee969432 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts @@ -35,7 +35,7 @@ export function showReferences(ctx: Ctx): Cmd { export function applySourceChange(ctx: Ctx): Cmd { return async (change: sourceChange.SourceChange) => { - sourceChange.applySourceChange(ctx, change); + await sourceChange.applySourceChange(ctx, change); }; } diff --git a/editors/code/src/commands/syntax_tree.ts b/editors/code/src/commands/syntax_tree.ts index 211f2251f..7dde66ad1 100644 --- a/editors/code/src/commands/syntax_tree.ts +++ b/editors/code/src/commands/syntax_tree.ts @@ -22,6 +22,7 @@ export function syntaxTree(ctx: Ctx): Cmd { if (doc.languageId !== 'rust') return; afterLs(() => tdcp.eventEmitter.fire(tdcp.uri)); }, + null, ctx.subscriptions, ); @@ -30,6 +31,7 @@ export function syntaxTree(ctx: Ctx): Cmd { if (!editor || editor.document.languageId !== 'rust') return; tdcp.eventEmitter.fire(tdcp.uri); }, + null, ctx.subscriptions, ); diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index fc21c8813..585229ed0 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts @@ -45,7 +45,7 @@ export class Config { private prevCargoWatchOptions: null | CargoWatchOptions = null; constructor(ctx: vscode.ExtensionContext) { - vscode.workspace.onDidChangeConfiguration(_ => this.refresh(), ctx.subscriptions); + vscode.workspace.onDidChangeConfiguration(_ => this.refresh(), null, ctx.subscriptions); this.refresh(); } diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts index 66216e0fc..22458a391 100644 --- a/editors/code/src/highlighting.ts +++ b/editors/code/src/highlighting.ts @@ -32,6 +32,7 @@ export function activateHighlighting(ctx: Ctx) { vscode.workspace.onDidChangeConfiguration( _ => highlighter.removeHighlights(), + null, ctx.subscriptions, ); @@ -52,6 +53,7 @@ export function activateHighlighting(ctx: Ctx) { ); highlighter.setHighlights(editor, decorations); }, + null, ctx.subscriptions, ); } diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts index ae7510183..1c019a51b 100644 --- a/editors/code/src/inlay_hints.ts +++ b/editors/code/src/inlay_hints.ts @@ -5,19 +5,27 @@ import { Ctx, sendRequestWithRetry } from './ctx'; export function activateInlayHints(ctx: Ctx) { const hintsUpdater = new HintsUpdater(ctx); - vscode.window.onDidChangeVisibleTextEditors(async _ => { - await hintsUpdater.refresh(); - }, ctx.subscriptions); - - vscode.workspace.onDidChangeTextDocument(async e => { - if (e.contentChanges.length === 0) return; - if (e.document.languageId !== 'rust') return; - await hintsUpdater.refresh(); - }, ctx.subscriptions); - - vscode.workspace.onDidChangeConfiguration(_ => { - hintsUpdater.setEnabled(ctx.config.displayInlayHints); - }, ctx.subscriptions); + vscode.window.onDidChangeVisibleTextEditors( + async _ => hintsUpdater.refresh(), + null, + ctx.subscriptions + ); + + vscode.workspace.onDidChangeTextDocument( + async event => { + if (event.contentChanges.length !== 0) return; + if (event.document.languageId !== 'rust') return; + await hintsUpdater.refresh(); + }, + null, + ctx.subscriptions + ); + + vscode.workspace.onDidChangeConfiguration( + async _ => hintsUpdater.setEnabled(ctx.config.displayInlayHints), + null, + ctx.subscriptions + ); ctx.onDidRestart(_ => hintsUpdater.setEnabled(ctx.config.displayInlayHints)); } diff --git a/editors/code/src/status_display.ts b/editors/code/src/status_display.ts index 4317410c7..51dbf388b 100644 --- a/editors/code/src/status_display.ts +++ b/editors/code/src/status_display.ts @@ -9,12 +9,14 @@ const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', ' export function activateStatusDisplay(ctx: Ctx) { const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command); ctx.pushCleanup(statusDisplay); - ctx.onDidRestart(client => { - client.onProgress(WorkDoneProgress.type, 'rustAnalyzer/cargoWatcher', params => statusDisplay.handleProgressNotification(params)); - }); + ctx.onDidRestart(client => ctx.pushCleanup(client.onProgress( + WorkDoneProgress.type, + 'rustAnalyzer/cargoWatcher', + params => statusDisplay.handleProgressNotification(params) + ))); } -class StatusDisplay implements vscode.Disposable, Disposable { +class StatusDisplay implements Disposable { packageName?: string; private i: number = 0; diff --git a/editors/code/tslint.json b/editors/code/tslint.json index 0df11b2f1..333e2a321 100644 --- a/editors/code/tslint.json +++ b/editors/code/tslint.json @@ -4,6 +4,7 @@ true, "always" ], - "prefer-const": true + "prefer-const": true, + "no-floating-promises": true } } -- cgit v1.2.3