mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
Simplify startup
This commit is contained in:
parent
dcdbbddd16
commit
d24e612106
5 changed files with 25 additions and 33 deletions
|
@ -17,7 +17,6 @@ export class Ctx {
|
|||
// on the event loop to get a better picture of what we can do here)
|
||||
client: lc.LanguageClient | null = null;
|
||||
private extCtx: vscode.ExtensionContext;
|
||||
private onStartHooks: Array<(client: lc.LanguageClient) => void> = [];
|
||||
|
||||
constructor(extCtx: vscode.ExtensionContext) {
|
||||
this.config = new Config(extCtx);
|
||||
|
@ -39,9 +38,6 @@ export class Ctx {
|
|||
await client.onReady();
|
||||
|
||||
this.client = client;
|
||||
for (const hook of this.onStartHooks) {
|
||||
hook(client);
|
||||
}
|
||||
}
|
||||
|
||||
get activeRustEditor(): vscode.TextEditor | undefined {
|
||||
|
@ -69,15 +65,6 @@ export class Ctx {
|
|||
pushCleanup(d: Disposable) {
|
||||
this.extCtx.subscriptions.push(d);
|
||||
}
|
||||
|
||||
onStart(hook: (client: lc.LanguageClient) => void) {
|
||||
const client = this.client;
|
||||
if (client == null) {
|
||||
this.onStartHooks.push(hook);
|
||||
} else {
|
||||
hook(client)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export interface Disposable {
|
||||
|
|
|
@ -7,7 +7,8 @@ import { Ctx, sendRequestWithRetry } from './ctx';
|
|||
|
||||
export function activateHighlighting(ctx: Ctx) {
|
||||
const highlighter = new Highlighter(ctx);
|
||||
ctx.onStart(client => {
|
||||
const client = ctx.client;
|
||||
if (client != null) {
|
||||
client.onNotification(
|
||||
'rust-analyzer/publishDecorations',
|
||||
(params: PublishDecorationsParams) => {
|
||||
|
@ -28,7 +29,7 @@ export function activateHighlighting(ctx: Ctx) {
|
|||
highlighter.setHighlights(targetEditor, params.decorations);
|
||||
},
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
vscode.workspace.onDidChangeConfiguration(
|
||||
_ => highlighter.removeHighlights(),
|
||||
|
|
|
@ -33,9 +33,9 @@ export function activateInlayHints(ctx: Ctx) {
|
|||
}
|
||||
})
|
||||
|
||||
// We pass async function though it will not be awaited when called,
|
||||
// thus Promise rejections won't be handled, but this should never throw in fact...
|
||||
ctx.onStart(async _ => hintsUpdater.setEnabled(ctx.config.displayInlayHints));
|
||||
// XXX: we don't await this, thus Promise rejections won't be handled, but
|
||||
// this should never throw in fact...
|
||||
hintsUpdater.setEnabled(ctx.config.displayInlayHints)
|
||||
}
|
||||
|
||||
interface InlayHintsParams {
|
||||
|
|
|
@ -11,6 +11,17 @@ let ctx: Ctx | undefined;
|
|||
export async function activate(context: vscode.ExtensionContext) {
|
||||
ctx = new Ctx(context);
|
||||
|
||||
// Note: we try to start the server before we activate type hints so that it
|
||||
// registers its `onDidChangeDocument` handler before us.
|
||||
//
|
||||
// This a horribly, horribly wrong way to deal with this problem.
|
||||
try {
|
||||
await ctx.startServer();
|
||||
} catch (e) {
|
||||
vscode.window.showErrorMessage(e.message);
|
||||
}
|
||||
|
||||
// Commands which invokes manually via command palette, shortcut, etc.
|
||||
ctx.registerCommand('reload', (ctx) => {
|
||||
return async () => {
|
||||
vscode.window.showInformationMessage('Reloading rust-analyzer...');
|
||||
|
@ -28,7 +39,6 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||
}
|
||||
})
|
||||
|
||||
// Commands which invokes manually via command palette, shortcut, etc.
|
||||
ctx.registerCommand('analyzerStatus', commands.analyzerStatus);
|
||||
ctx.registerCommand('collectGarbage', commands.collectGarbage);
|
||||
ctx.registerCommand('matchingBrace', commands.matchingBrace);
|
||||
|
@ -49,15 +59,6 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||
activateStatusDisplay(ctx);
|
||||
|
||||
activateHighlighting(ctx);
|
||||
// Note: we try to start the server before we activate type hints so that it
|
||||
// registers its `onDidChangeDocument` handler before us.
|
||||
//
|
||||
// This a horribly, horribly wrong way to deal with this problem.
|
||||
try {
|
||||
await ctx.startServer();
|
||||
} catch (e) {
|
||||
vscode.window.showErrorMessage(e.message);
|
||||
}
|
||||
activateInlayHints(ctx);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,11 +9,14 @@ const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '
|
|||
export function activateStatusDisplay(ctx: Ctx) {
|
||||
const statusDisplay = new StatusDisplay(ctx.config.cargoWatchOptions.command);
|
||||
ctx.pushCleanup(statusDisplay);
|
||||
ctx.onStart(client => ctx.pushCleanup(client.onProgress(
|
||||
WorkDoneProgress.type,
|
||||
'rustAnalyzer/cargoWatcher',
|
||||
params => statusDisplay.handleProgressNotification(params)
|
||||
)));
|
||||
const client = ctx.client;
|
||||
if (client != null) {
|
||||
ctx.pushCleanup(client.onProgress(
|
||||
WorkDoneProgress.type,
|
||||
'rustAnalyzer/cargoWatcher',
|
||||
params => statusDisplay.handleProgressNotification(params)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
class StatusDisplay implements Disposable {
|
||||
|
|
Loading…
Reference in a new issue