mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Encapsulate inlay hints activation
This commit is contained in:
parent
b8368f09b4
commit
9ead314005
2 changed files with 39 additions and 38 deletions
|
@ -1,6 +1,42 @@
|
|||
import * as vscode from 'vscode';
|
||||
import * as lc from 'vscode-languageclient';
|
||||
import { Server } from './server';
|
||||
import { Ctx } from './ctx';
|
||||
|
||||
export function activateInlayHints(ctx: Ctx) {
|
||||
const hintsUpdater = new HintsUpdater();
|
||||
hintsUpdater.refreshHintsForVisibleEditors().then(() => {
|
||||
// vscode may ignore top level hintsUpdater.refreshHintsForVisibleEditors()
|
||||
// so update the hints once when the focus changes to guarantee their presence
|
||||
let editorChangeDisposable: vscode.Disposable | null = null;
|
||||
editorChangeDisposable = vscode.window.onDidChangeActiveTextEditor(
|
||||
_ => {
|
||||
if (editorChangeDisposable !== null) {
|
||||
editorChangeDisposable.dispose();
|
||||
}
|
||||
return hintsUpdater.refreshHintsForVisibleEditors();
|
||||
},
|
||||
);
|
||||
|
||||
ctx.pushCleanup(
|
||||
vscode.window.onDidChangeVisibleTextEditors(_ =>
|
||||
hintsUpdater.refreshHintsForVisibleEditors(),
|
||||
),
|
||||
);
|
||||
ctx.pushCleanup(
|
||||
vscode.workspace.onDidChangeTextDocument(e =>
|
||||
hintsUpdater.refreshHintsForVisibleEditors(e),
|
||||
),
|
||||
);
|
||||
ctx.pushCleanup(
|
||||
vscode.workspace.onDidChangeConfiguration(_ =>
|
||||
hintsUpdater.toggleHintsDisplay(
|
||||
Server.config.displayInlayHints,
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
interface InlayHintsParams {
|
||||
textDocument: lc.TextDocumentIdentifier;
|
||||
|
@ -18,7 +54,7 @@ const typeHintDecorationType = vscode.window.createTextEditorDecorationType({
|
|||
},
|
||||
});
|
||||
|
||||
export class HintsUpdater {
|
||||
class HintsUpdater {
|
||||
private displayHints = true;
|
||||
|
||||
public async toggleHintsDisplay(displayHints: boolean): Promise<void> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue