From 583f5c961239c806e9467da346967e75c87f6618 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 24 Jul 2019 19:52:26 +0300 Subject: Fix linter issues --- editors/code/src/commands/index.ts | 4 +- editors/code/src/commands/inlay_hints.ts | 88 ++++++++++++++++++++++---------- editors/code/src/extension.ts | 12 +++-- 3 files changed, 72 insertions(+), 32 deletions(-) (limited to 'editors') diff --git a/editors/code/src/commands/index.ts b/editors/code/src/commands/index.ts index d17f702e8..c194bd2ea 100644 --- a/editors/code/src/commands/index.ts +++ b/editors/code/src/commands/index.ts @@ -1,12 +1,12 @@ import * as analyzerStatus from './analyzer_status'; import * as applySourceChange from './apply_source_change'; +import * as inlayHints from './inlay_hints'; import * as joinLines from './join_lines'; import * as matchingBrace from './matching_brace'; import * as onEnter from './on_enter'; import * as parentModule from './parent_module'; import * as runnables from './runnables'; import * as syntaxTree from './syntaxTree'; -import * as inlayHints from './inlay_hints'; export { analyzerStatus, @@ -17,5 +17,5 @@ export { runnables, syntaxTree, onEnter, - inlayHints, + inlayHints }; diff --git a/editors/code/src/commands/inlay_hints.ts b/editors/code/src/commands/inlay_hints.ts index cc6620d36..056d7c8e3 100644 --- a/editors/code/src/commands/inlay_hints.ts +++ b/editors/code/src/commands/inlay_hints.ts @@ -1,5 +1,10 @@ import * as vscode from 'vscode'; -import { Range, TextDocumentChangeEvent, TextDocumentContentChangeEvent, TextEditor } from 'vscode'; +import { + Range, + TextDocumentChangeEvent, + TextDocumentContentChangeEvent, + TextEditor +} from 'vscode'; import { TextDocumentIdentifier } from 'vscode-languageclient'; import { Server } from '../server'; @@ -8,23 +13,28 @@ interface InlayHintsParams { } interface InlayHint { - range: Range, - kind: string, - label: string, + range: Range; + kind: string; + label: string; } const typeHintDecorationType = vscode.window.createTextEditorDecorationType({ after: { - color: new vscode.ThemeColor('ralsp.inlayHint'), - }, + color: new vscode.ThemeColor('ralsp.inlayHint') + } }); export class HintsUpdater { private displayHints = true; - public async loadHints(editor: vscode.TextEditor | undefined): Promise { + public async loadHints( + editor: vscode.TextEditor | undefined + ): Promise { if (this.displayHints && editor !== undefined) { - await this.updateDecorationsFromServer(editor.document.uri.toString(), editor); + await this.updateDecorationsFromServer( + editor.document.uri.toString(), + editor + ); } } @@ -37,7 +47,7 @@ export class HintsUpdater { } else { const editor = vscode.window.activeTextEditor; if (editor != null) { - return editor.setDecorations(typeHintDecorationType, []) + return editor.setDecorations(typeHintDecorationType, []); } } } @@ -58,38 +68,62 @@ export class HintsUpdater { // If the dbg! macro is used in the lsp-server, an endless stream of events with `cause.contentChanges` with the dbg messages. // Should not be a real situation, but better to filter such things out. - if (cause !== undefined && cause.contentChanges.filter(changeEvent => this.isEventInFile(document.lineCount, changeEvent)).length === 0) { + if ( + cause !== undefined && + cause.contentChanges.filter(changeEvent => + this.isEventInFile(document.lineCount, changeEvent) + ).length === 0 + ) { return; } - return await this.updateDecorationsFromServer(document.uri.toString(), editor); + return await this.updateDecorationsFromServer( + document.uri.toString(), + editor + ); } - private isEventInFile(documentLineCount: number, event: TextDocumentContentChangeEvent): boolean { + private isEventInFile( + documentLineCount: number, + event: TextDocumentContentChangeEvent + ): boolean { const eventText = event.text; if (eventText.length === 0) { - return event.range.start.line <= documentLineCount || event.range.end.line <= documentLineCount; + return ( + event.range.start.line <= documentLineCount || + event.range.end.line <= documentLineCount + ); } else { - return event.range.start.line <= documentLineCount && event.range.end.line <= documentLineCount; + return ( + event.range.start.line <= documentLineCount && + event.range.end.line <= documentLineCount + ); } } - private async updateDecorationsFromServer(documentUri: string, editor: TextEditor): Promise { - const newHints = await this.queryHints(documentUri) || []; - const newDecorations = newHints.map(hint => ( - { - range: hint.range, - renderOptions: { after: { contentText: `: ${hint.label}` } }, - } - )); + private async updateDecorationsFromServer( + documentUri: string, + editor: TextEditor + ): Promise { + const newHints = (await this.queryHints(documentUri)) || []; + const newDecorations = newHints.map(hint => ({ + range: hint.range, + renderOptions: { after: { contentText: `: ${hint.label}` } } + })); return editor.setDecorations(typeHintDecorationType, newDecorations); } private async queryHints(documentUri: string): Promise { - const request: InlayHintsParams = { textDocument: { uri: documentUri } }; + const request: InlayHintsParams = { + textDocument: { uri: documentUri } + }; const client = Server.client; - return client.onReady().then(() => client.sendRequest( - 'rust-analyzer/inlayHints', - request - )); + return client + .onReady() + .then(() => + client.sendRequest( + 'rust-analyzer/inlayHints', + request + ) + ); } } diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index 3965b881a..2ec3a2b35 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts @@ -152,9 +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 => hintsUpdater.loadHints(editor)); - vscode.workspace.onDidChangeTextDocument(e => hintsUpdater.updateHints(e)); - vscode.workspace.onDidChangeConfiguration(_ => hintsUpdater.toggleHintsDisplay(Server.config.displayInlayHints)); + vscode.window.onDidChangeActiveTextEditor(editor => + hintsUpdater.loadHints(editor) + ); + vscode.workspace.onDidChangeTextDocument(e => + hintsUpdater.updateHints(e) + ); + vscode.workspace.onDidChangeConfiguration(_ => + hintsUpdater.toggleHintsDisplay(Server.config.displayInlayHints) + ); }); } } -- cgit v1.2.3