From d2bf2ebe15bd58e6d8937a5894a2363a1ca46b59 Mon Sep 17 00:00:00 2001 From: Charles Pierce Date: Wed, 4 Nov 2020 10:26:58 -0800 Subject: Restore semantic token flickering workaround removed in #5697 --- editors/code/src/client.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index 1ba2352ee..d032b45b7 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts @@ -2,6 +2,7 @@ import * as lc from 'vscode-languageclient/node'; import * as vscode from 'vscode'; import * as ra from '../src/lsp_ext'; import * as Is from 'vscode-languageclient/lib/common/utils/is'; +import { DocumentSemanticsTokensSignature, DocumentSemanticsTokensEditsSignature, DocumentRangeSemanticTokensSignature } from 'vscode-languageclient/lib/common/semanticTokens'; import { assert } from './util'; function renderCommand(cmd: ra.CommandLink) { @@ -18,6 +19,13 @@ function renderHoverActions(actions: ra.CommandLinkGroup[]): vscode.MarkdownStri return result; } +// Workaround for https://github.com/microsoft/vscode-languageserver-node/issues/576 +async function semanticHighlightingWorkaround vscode.ProviderResult>(next: F, ...args: Parameters): Promise { + const res = await next(...args); + if (res == null) throw new Error('busy'); + return res; +} + export function createClient(serverPath: string, cwd: string): lc.LanguageClient { // '.' Is the fallback if no folder is open // TODO?: Workspace folders support Uri's (eg: file://test.txt). @@ -41,6 +49,15 @@ export function createClient(serverPath: string, cwd: string): lc.LanguageClient diagnosticCollectionName: "rustc", traceOutputChannel, middleware: { + provideDocumentSemanticTokens(document: vscode.TextDocument, token: vscode.CancellationToken, next: DocumentSemanticsTokensSignature): vscode.ProviderResult { + return semanticHighlightingWorkaround(next, document, token); + }, + provideDocumentSemanticTokensEdits(document: vscode.TextDocument, previousResultId: string, token: vscode.CancellationToken, next: DocumentSemanticsTokensEditsSignature): vscode.ProviderResult { + return semanticHighlightingWorkaround(next, document, previousResultId, token); + }, + provideDocumentRangeSemanticTokens(document: vscode.TextDocument, range: vscode.Range, token: vscode.CancellationToken, next: DocumentRangeSemanticTokensSignature): vscode.ProviderResult { + return semanticHighlightingWorkaround(next, document, range, token); + }, async provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, _next: lc.ProvideHoverSignature) { return client.sendRequest(lc.HoverRequest.type, client.code2ProtocolConverter.asTextDocumentPositionParams(document, position), token).then( (result) => { -- cgit v1.2.3