@@ -2,6 +2,7 @@ import * as lc from 'vscode-languageclient/node';
22import * as vscode from 'vscode' ;
33import * as ra from '../src/lsp_ext' ;
44import * as Is from 'vscode-languageclient/lib/common/utils/is' ;
5+ import { DocumentSemanticsTokensSignature , DocumentSemanticsTokensEditsSignature , DocumentRangeSemanticTokensSignature } from 'vscode-languageclient/lib/common/semanticTokens' ;
56import { assert } from './util' ;
67
78function renderCommand ( cmd : ra . CommandLink ) {
@@ -18,6 +19,13 @@ function renderHoverActions(actions: ra.CommandLinkGroup[]): vscode.MarkdownStri
1819 return result ;
1920}
2021
22+ // Workaround for https://github.com/microsoft/vscode-languageserver-node/issues/576
23+ async function semanticHighlightingWorkaround < R , F extends ( ...args : any [ ] ) => vscode . ProviderResult < R > > ( next : F , ...args : Parameters < F > ) : Promise < R > {
24+ const res = await next ( ...args ) ;
25+ if ( res == null ) throw new Error ( 'busy' ) ;
26+ return res ;
27+ }
28+
2129export function createClient ( serverPath : string , cwd : string ) : lc . LanguageClient {
2230 // '.' Is the fallback if no folder is open
2331 // TODO?: Workspace folders support Uri's (eg: file://test.txt).
@@ -41,6 +49,15 @@ export function createClient(serverPath: string, cwd: string): lc.LanguageClient
4149 diagnosticCollectionName : "rustc" ,
4250 traceOutputChannel,
4351 middleware : {
52+ provideDocumentSemanticTokens ( document : vscode . TextDocument , token : vscode . CancellationToken , next : DocumentSemanticsTokensSignature ) : vscode . ProviderResult < vscode . SemanticTokens > {
53+ return semanticHighlightingWorkaround ( next , document , token ) ;
54+ } ,
55+ provideDocumentSemanticTokensEdits ( document : vscode . TextDocument , previousResultId : string , token : vscode . CancellationToken , next : DocumentSemanticsTokensEditsSignature ) : vscode . ProviderResult < vscode . SemanticTokensEdits | vscode . SemanticTokens > {
56+ return semanticHighlightingWorkaround ( next , document , previousResultId , token ) ;
57+ } ,
58+ provideDocumentRangeSemanticTokens ( document : vscode . TextDocument , range : vscode . Range , token : vscode . CancellationToken , next : DocumentRangeSemanticTokensSignature ) : vscode . ProviderResult < vscode . SemanticTokens > {
59+ return semanticHighlightingWorkaround ( next , document , range , token ) ;
60+ } ,
4461 async provideHover ( document : vscode . TextDocument , position : vscode . Position , token : vscode . CancellationToken , _next : lc . ProvideHoverSignature ) {
4562 return client . sendRequest ( lc . HoverRequest . type , client . code2ProtocolConverter . asTextDocumentPositionParams ( document , position ) , token ) . then (
4663 ( result ) => {
0 commit comments