From 02f18abc559930e5efec5af1ec4f3a7dbb8b4429 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 25 Jul 2019 15:17:37 +0300 Subject: Code review fixes --- editors/code/src/commands/inlay_hints.ts | 14 +++++++------- editors/code/src/extension.ts | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/editors/code/src/commands/inlay_hints.ts b/editors/code/src/commands/inlay_hints.ts index 0ce3edcbf..ba9966161 100644 --- a/editors/code/src/commands/inlay_hints.ts +++ b/editors/code/src/commands/inlay_hints.ts @@ -1,9 +1,5 @@ import * as vscode from 'vscode'; -import { - Range, - TextDocumentChangeEvent, - TextEditor -} from 'vscode'; +import { Range, TextDocumentChangeEvent, TextEditor } from 'vscode'; import { TextDocumentIdentifier } from 'vscode-languageclient'; import { Server } from '../server'; @@ -29,7 +25,7 @@ export class HintsUpdater { public async loadHints( editor: vscode.TextEditor | undefined ): Promise { - if (this.displayHints && editor !== undefined) { + if (this.displayHints && editor !== undefined && this.isRustDocument(editor.document)) { await this.updateDecorationsFromServer( editor.document.uri.toString(), editor @@ -61,7 +57,7 @@ export class HintsUpdater { return; } const document = cause == null ? editor.document : cause.document; - if (document.languageId !== 'rust') { + if (!this.isRustDocument(document)) { return; } @@ -71,6 +67,10 @@ export class HintsUpdater { ); } + private isRustDocument(document: vscode.TextDocument): boolean { + return document && document.languageId === 'rust'; + } + private async updateDecorationsFromServer( documentUri: string, editor: TextEditor diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index 2ec3a2b35..9bee75394 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts @@ -152,15 +152,15 @@ export function activate(context: vscode.ExtensionContext) { if (Server.config.displayInlayHints) { const hintsUpdater = new HintsUpdater(); hintsUpdater.loadHints(vscode.window.activeTextEditor).then(() => { - vscode.window.onDidChangeActiveTextEditor(editor => + disposeOnDeactivation(vscode.window.onDidChangeActiveTextEditor(editor => hintsUpdater.loadHints(editor) - ); - vscode.workspace.onDidChangeTextDocument(e => + )); + disposeOnDeactivation(vscode.workspace.onDidChangeTextDocument(e => hintsUpdater.updateHints(e) - ); - vscode.workspace.onDidChangeConfiguration(_ => + )); + disposeOnDeactivation(vscode.workspace.onDidChangeConfiguration(_ => hintsUpdater.toggleHintsDisplay(Server.config.displayInlayHints) - ); + )); }); } } -- cgit v1.2.3