Skip to content

Commit 8153b60

Browse files
author
Veetaha
committed
vscode: eliminate floating promises and insane amount of resource handle leaks
1 parent 8d0f7da commit 8153b60

File tree

8 files changed

+36
-21
lines changed

8 files changed

+36
-21
lines changed

editors/code/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"vscode:prepublish": "tsc && rollup -c",
2222
"package": "vsce package",
2323
"watch": "tsc --watch",
24-
"fmt": "tsfmt -r && tslint -c tslint.json 'src/**/*.ts' --fix"
24+
"fmt": "tsfmt -r && tslint -p tsconfig.json -c tslint.json 'src/**/*.ts' --fix"
2525
},
2626
"dependencies": {
2727
"jsonc-parser": "^2.1.0",

editors/code/src/commands/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function showReferences(ctx: Ctx): Cmd {
3535

3636
export function applySourceChange(ctx: Ctx): Cmd {
3737
return async (change: sourceChange.SourceChange) => {
38-
sourceChange.applySourceChange(ctx, change);
38+
await sourceChange.applySourceChange(ctx, change);
3939
};
4040
}
4141

editors/code/src/commands/syntax_tree.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export function syntaxTree(ctx: Ctx): Cmd {
2222
if (doc.languageId !== 'rust') return;
2323
afterLs(() => tdcp.eventEmitter.fire(tdcp.uri));
2424
},
25+
null,
2526
ctx.subscriptions,
2627
);
2728

@@ -30,6 +31,7 @@ export function syntaxTree(ctx: Ctx): Cmd {
3031
if (!editor || editor.document.languageId !== 'rust') return;
3132
tdcp.eventEmitter.fire(tdcp.uri);
3233
},
34+
null,
3335
ctx.subscriptions,
3436
);
3537

editors/code/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class Config {
4545
private prevCargoWatchOptions: null | CargoWatchOptions = null;
4646

4747
constructor(ctx: vscode.ExtensionContext) {
48-
vscode.workspace.onDidChangeConfiguration(_ => this.refresh(), ctx.subscriptions);
48+
vscode.workspace.onDidChangeConfiguration(_ => this.refresh(), null, ctx.subscriptions);
4949
this.refresh();
5050
}
5151

editors/code/src/highlighting.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export function activateHighlighting(ctx: Ctx) {
3232

3333
vscode.workspace.onDidChangeConfiguration(
3434
_ => highlighter.removeHighlights(),
35+
null,
3536
ctx.subscriptions,
3637
);
3738

@@ -52,6 +53,7 @@ export function activateHighlighting(ctx: Ctx) {
5253
);
5354
highlighter.setHighlights(editor, decorations);
5455
},
56+
null,
5557
ctx.subscriptions,
5658
);
5759
}

editors/code/src/inlay_hints.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,27 @@ import { Ctx, sendRequestWithRetry } from './ctx';
55

66
export function activateInlayHints(ctx: Ctx) {
77
const hintsUpdater = new HintsUpdater(ctx);
8-
vscode.window.onDidChangeVisibleTextEditors(async _ => {
9-
await hintsUpdater.refresh();
10-
}, ctx.subscriptions);
11-
12-
vscode.workspace.onDidChangeTextDocument(async e => {
13-
if (e.contentChanges.length === 0) return;
14-
if (e.document.languageId !== 'rust') return;
15-
await hintsUpdater.refresh();
16-
}, ctx.subscriptions);
17-
18-
vscode.workspace.onDidChangeConfiguration(_ => {
19-
hintsUpdater.setEnabled(ctx.config.displayInlayHints);
20-
}, ctx.subscriptions);
8+
vscode.window.onDidChangeVisibleTextEditors(
9+
async _ => hintsUpdater.refresh(),
10+
null,
11+
ctx.subscriptions
12+
);
13+
14+
vscode.workspace.onDidChangeTextDocument(
15+
async event => {
16+
if (event.contentChanges.length !== 0) return;
17+
if (event.document.languageId !== 'rust') return;
18+
await hintsUpdater.refresh();
19+
},
20+
null,
21+
ctx.subscriptions
22+
);
23+
24+
vscode.workspace.onDidChangeConfiguration(
25+
async _ => hintsUpdater.setEnabled(ctx.config.displayInlayHints),
26+
null,
27+
ctx.subscriptions
28+
);
2129

2230
ctx.onDidRestart(_ => hintsUpdater.setEnabled(ctx.config.displayInlayHints));
2331
}

editors/code/src/status_display.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '
99
export function activateStatusDisplay(ctx: Ctx) {
1010
const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command);
1111
ctx.pushCleanup(statusDisplay);
12-
ctx.onDidRestart(client => {
13-
client.onProgress(WorkDoneProgress.type, 'rustAnalyzer/cargoWatcher', params => statusDisplay.handleProgressNotification(params));
14-
});
12+
ctx.onDidRestart(client => ctx.pushCleanup(client.onProgress(
13+
WorkDoneProgress.type,
14+
'rustAnalyzer/cargoWatcher',
15+
params => statusDisplay.handleProgressNotification(params)
16+
)));
1517
}
1618

17-
class StatusDisplay implements vscode.Disposable, Disposable {
19+
class StatusDisplay implements Disposable {
1820
packageName?: string;
1921

2022
private i: number = 0;

editors/code/tslint.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
true,
55
"always"
66
],
7-
"prefer-const": true
7+
"prefer-const": true,
8+
"no-floating-promises": true
89
}
910
}

0 commit comments

Comments
 (0)