mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 14:03:35 +00:00
vscode: eliminate floating promises and insane amount of resource handle leaks
This commit is contained in:
parent
8d0f7da2f5
commit
8153b60e1d
8 changed files with 34 additions and 19 deletions
|
@ -21,7 +21,7 @@
|
||||||
"vscode:prepublish": "tsc && rollup -c",
|
"vscode:prepublish": "tsc && rollup -c",
|
||||||
"package": "vsce package",
|
"package": "vsce package",
|
||||||
"watch": "tsc --watch",
|
"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": {
|
"dependencies": {
|
||||||
"jsonc-parser": "^2.1.0",
|
"jsonc-parser": "^2.1.0",
|
||||||
|
|
|
@ -35,7 +35,7 @@ export function showReferences(ctx: Ctx): Cmd {
|
||||||
|
|
||||||
export function applySourceChange(ctx: Ctx): Cmd {
|
export function applySourceChange(ctx: Ctx): Cmd {
|
||||||
return async (change: sourceChange.SourceChange) => {
|
return async (change: sourceChange.SourceChange) => {
|
||||||
sourceChange.applySourceChange(ctx, change);
|
await sourceChange.applySourceChange(ctx, change);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ export function syntaxTree(ctx: Ctx): Cmd {
|
||||||
if (doc.languageId !== 'rust') return;
|
if (doc.languageId !== 'rust') return;
|
||||||
afterLs(() => tdcp.eventEmitter.fire(tdcp.uri));
|
afterLs(() => tdcp.eventEmitter.fire(tdcp.uri));
|
||||||
},
|
},
|
||||||
|
null,
|
||||||
ctx.subscriptions,
|
ctx.subscriptions,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -30,6 +31,7 @@ export function syntaxTree(ctx: Ctx): Cmd {
|
||||||
if (!editor || editor.document.languageId !== 'rust') return;
|
if (!editor || editor.document.languageId !== 'rust') return;
|
||||||
tdcp.eventEmitter.fire(tdcp.uri);
|
tdcp.eventEmitter.fire(tdcp.uri);
|
||||||
},
|
},
|
||||||
|
null,
|
||||||
ctx.subscriptions,
|
ctx.subscriptions,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ export class Config {
|
||||||
private prevCargoWatchOptions: null | CargoWatchOptions = null;
|
private prevCargoWatchOptions: null | CargoWatchOptions = null;
|
||||||
|
|
||||||
constructor(ctx: vscode.ExtensionContext) {
|
constructor(ctx: vscode.ExtensionContext) {
|
||||||
vscode.workspace.onDidChangeConfiguration(_ => this.refresh(), ctx.subscriptions);
|
vscode.workspace.onDidChangeConfiguration(_ => this.refresh(), null, ctx.subscriptions);
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ export function activateHighlighting(ctx: Ctx) {
|
||||||
|
|
||||||
vscode.workspace.onDidChangeConfiguration(
|
vscode.workspace.onDidChangeConfiguration(
|
||||||
_ => highlighter.removeHighlights(),
|
_ => highlighter.removeHighlights(),
|
||||||
|
null,
|
||||||
ctx.subscriptions,
|
ctx.subscriptions,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -52,6 +53,7 @@ export function activateHighlighting(ctx: Ctx) {
|
||||||
);
|
);
|
||||||
highlighter.setHighlights(editor, decorations);
|
highlighter.setHighlights(editor, decorations);
|
||||||
},
|
},
|
||||||
|
null,
|
||||||
ctx.subscriptions,
|
ctx.subscriptions,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,19 +5,27 @@ import { Ctx, sendRequestWithRetry } from './ctx';
|
||||||
|
|
||||||
export function activateInlayHints(ctx: Ctx) {
|
export function activateInlayHints(ctx: Ctx) {
|
||||||
const hintsUpdater = new HintsUpdater(ctx);
|
const hintsUpdater = new HintsUpdater(ctx);
|
||||||
vscode.window.onDidChangeVisibleTextEditors(async _ => {
|
vscode.window.onDidChangeVisibleTextEditors(
|
||||||
await hintsUpdater.refresh();
|
async _ => hintsUpdater.refresh(),
|
||||||
}, ctx.subscriptions);
|
null,
|
||||||
|
ctx.subscriptions
|
||||||
|
);
|
||||||
|
|
||||||
vscode.workspace.onDidChangeTextDocument(async e => {
|
vscode.workspace.onDidChangeTextDocument(
|
||||||
if (e.contentChanges.length === 0) return;
|
async event => {
|
||||||
if (e.document.languageId !== 'rust') return;
|
if (event.contentChanges.length !== 0) return;
|
||||||
|
if (event.document.languageId !== 'rust') return;
|
||||||
await hintsUpdater.refresh();
|
await hintsUpdater.refresh();
|
||||||
}, ctx.subscriptions);
|
},
|
||||||
|
null,
|
||||||
|
ctx.subscriptions
|
||||||
|
);
|
||||||
|
|
||||||
vscode.workspace.onDidChangeConfiguration(_ => {
|
vscode.workspace.onDidChangeConfiguration(
|
||||||
hintsUpdater.setEnabled(ctx.config.displayInlayHints);
|
async _ => hintsUpdater.setEnabled(ctx.config.displayInlayHints),
|
||||||
}, ctx.subscriptions);
|
null,
|
||||||
|
ctx.subscriptions
|
||||||
|
);
|
||||||
|
|
||||||
ctx.onDidRestart(_ => hintsUpdater.setEnabled(ctx.config.displayInlayHints));
|
ctx.onDidRestart(_ => hintsUpdater.setEnabled(ctx.config.displayInlayHints));
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,14 @@ const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '
|
||||||
export function activateStatusDisplay(ctx: Ctx) {
|
export function activateStatusDisplay(ctx: Ctx) {
|
||||||
const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command);
|
const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command);
|
||||||
ctx.pushCleanup(statusDisplay);
|
ctx.pushCleanup(statusDisplay);
|
||||||
ctx.onDidRestart(client => {
|
ctx.onDidRestart(client => ctx.pushCleanup(client.onProgress(
|
||||||
client.onProgress(WorkDoneProgress.type, 'rustAnalyzer/cargoWatcher', params => statusDisplay.handleProgressNotification(params));
|
WorkDoneProgress.type,
|
||||||
});
|
'rustAnalyzer/cargoWatcher',
|
||||||
|
params => statusDisplay.handleProgressNotification(params)
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
class StatusDisplay implements vscode.Disposable, Disposable {
|
class StatusDisplay implements Disposable {
|
||||||
packageName?: string;
|
packageName?: string;
|
||||||
|
|
||||||
private i: number = 0;
|
private i: number = 0;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
true,
|
true,
|
||||||
"always"
|
"always"
|
||||||
],
|
],
|
||||||
"prefer-const": true
|
"prefer-const": true,
|
||||||
|
"no-floating-promises": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue