Cache decorations before the first change only
This commit is contained in:
parent
f358b4c0c0
commit
777552b6a8
1 changed files with 21 additions and 20 deletions
|
@ -21,8 +21,8 @@ const typeHintDecorationType = vscode.window.createTextEditorDecorationType({
|
||||||
|
|
||||||
export class HintsUpdater {
|
export class HintsUpdater {
|
||||||
private displayHints = true;
|
private displayHints = true;
|
||||||
private drawnDecorations = new WeakMap<
|
private decorationsSinceLastChange = new Map<
|
||||||
vscode.Uri,
|
string,
|
||||||
vscode.DecorationOptions[]
|
vscode.DecorationOptions[]
|
||||||
>();
|
>();
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@ export class HintsUpdater {
|
||||||
if (this.displayHints) {
|
if (this.displayHints) {
|
||||||
const documentUri = this.getEditorDocumentUri(editor);
|
const documentUri = this.getEditorDocumentUri(editor);
|
||||||
if (documentUri !== null) {
|
if (documentUri !== null) {
|
||||||
const latestDecorations = this.drawnDecorations.get(
|
const latestDecorations = this.decorationsSinceLastChange.get(
|
||||||
documentUri
|
documentUri.toString()
|
||||||
);
|
);
|
||||||
if (latestDecorations === undefined) {
|
if (latestDecorations === undefined) {
|
||||||
await this.updateDecorationsFromServer(
|
await this.updateDecorationsFromServer(
|
||||||
|
@ -51,7 +51,7 @@ export class HintsUpdater {
|
||||||
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 = new WeakMap();
|
this.decorationsSinceLastChange.clear();
|
||||||
|
|
||||||
if (displayHints) {
|
if (displayHints) {
|
||||||
return this.updateHints();
|
return this.updateHints();
|
||||||
|
@ -72,14 +72,15 @@ export class HintsUpdater {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const editor = vscode.window.activeTextEditor;
|
const editor = vscode.window.activeTextEditor;
|
||||||
if (editor == null) {
|
if (editor === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const document = cause == null ? editor.document : cause.document;
|
const document = cause === undefined ? editor.document : cause.document;
|
||||||
if (!this.isRustDocument(document)) {
|
if (!this.isRustDocument(document)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.decorationsSinceLastChange.clear();
|
||||||
return await this.updateDecorationsFromServer(document.uri, editor);
|
return await this.updateDecorationsFromServer(document.uri, editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,25 +93,25 @@ export class HintsUpdater {
|
||||||
editor: TextEditor
|
editor: TextEditor
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const newHints = await this.queryHints(documentUri.toString());
|
const newHints = await this.queryHints(documentUri.toString());
|
||||||
if (newHints != null) {
|
if (
|
||||||
|
newHints !== null &&
|
||||||
|
this.getEditorDocumentUri(vscode.window.activeTextEditor) ===
|
||||||
|
documentUri
|
||||||
|
) {
|
||||||
const newDecorations = newHints.map(hint => ({
|
const newDecorations = newHints.map(hint => ({
|
||||||
range: hint.range,
|
range: hint.range,
|
||||||
renderOptions: { after: { contentText: `: ${hint.label}` } }
|
renderOptions: { after: { contentText: `: ${hint.label}` } }
|
||||||
}));
|
}));
|
||||||
|
this.decorationsSinceLastChange.set(
|
||||||
this.drawnDecorations.set(documentUri, newDecorations);
|
documentUri.toString(),
|
||||||
|
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 = {
|
||||||
|
|
Loading…
Add table
Reference in a new issue