mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Query less hints on file open
This commit is contained in:
parent
4912cc35af
commit
2c02aebeb5
@ -21,32 +21,36 @@ const typeHintDecorationType = vscode.window.createTextEditorDecorationType({
|
|||||||
|
|
||||||
export class HintsUpdater {
|
export class HintsUpdater {
|
||||||
private displayHints = true;
|
private displayHints = true;
|
||||||
|
private drawnDecorations = new Map<string, vscode.DecorationOptions[]>();
|
||||||
|
|
||||||
public async loadHints(
|
public async loadHints(editor?: vscode.TextEditor): Promise<void> {
|
||||||
editor: vscode.TextEditor | undefined
|
if (this.displayHints) {
|
||||||
): Promise<void> {
|
const documentUri = this.getEditorDocumentUri(editor);
|
||||||
if (
|
if (documentUri !== null) {
|
||||||
this.displayHints &&
|
const latestDecorations = this.drawnDecorations.get(documentUri);
|
||||||
editor !== undefined &&
|
if (latestDecorations === undefined) {
|
||||||
this.isRustDocument(editor.document)
|
|
||||||
) {
|
|
||||||
await this.updateDecorationsFromServer(
|
await this.updateDecorationsFromServer(
|
||||||
editor.document.uri.toString(),
|
documentUri,
|
||||||
editor
|
editor!
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
await editor!.setDecorations(typeHintDecorationType, latestDecorations);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async toggleHintsDisplay(displayHints: boolean): Promise<void> {
|
public async toggleHintsDisplay(displayHints: boolean): Promise<void> {
|
||||||
if (this.displayHints !== displayHints) {
|
if (this.displayHints !== displayHints) {
|
||||||
this.displayHints = displayHints;
|
this.displayHints = displayHints;
|
||||||
|
this.drawnDecorations.clear();
|
||||||
|
|
||||||
if (displayHints) {
|
if (displayHints) {
|
||||||
return this.updateHints();
|
return this.updateHints();
|
||||||
} else {
|
} else {
|
||||||
const editor = vscode.window.activeTextEditor;
|
const editor = vscode.window.activeTextEditor;
|
||||||
if (editor != null) {
|
if (this.getEditorDocumentUri(editor) !== null) {
|
||||||
return editor.setDecorations(typeHintDecorationType, []);
|
return editor!.setDecorations(typeHintDecorationType, []);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,12 +89,17 @@ export class HintsUpdater {
|
|||||||
range: hint.range,
|
range: hint.range,
|
||||||
renderOptions: { after: { contentText: `: ${hint.label}` } }
|
renderOptions: { after: { contentText: `: ${hint.label}` } }
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
this.drawnDecorations.set(documentUri, newDecorations);
|
||||||
|
|
||||||
|
if (this.getEditorDocumentUri(vscode.window.activeTextEditor) === documentUri) {
|
||||||
return editor.setDecorations(
|
return editor.setDecorations(
|
||||||
typeHintDecorationType,
|
typeHintDecorationType,
|
||||||
newDecorations
|
newDecorations
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async queryHints(documentUri: string): Promise<InlayHint[] | null> {
|
private async queryHints(documentUri: string): Promise<InlayHint[] | null> {
|
||||||
const request: InlayHintsParams = {
|
const request: InlayHintsParams = {
|
||||||
@ -106,4 +115,11 @@ export class HintsUpdater {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getEditorDocumentUri(editor?: vscode.TextEditor): string | null {
|
||||||
|
if (editor && this.isRustDocument(editor.document)) {
|
||||||
|
return editor.document.uri.toString();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user