@@ -18,14 +18,8 @@ export const ServerCancelled: number = -32802;
1818let anyFileOpened : boolean = false ;
1919
2020export function createProtocolFilter ( ) : Middleware {
21- // Disabling lint for invoke handlers
22- const invoke1 = ( a : any , next : ( a : any ) => any ) : any => clients . ActiveClient . enqueue ( ( ) => next ( a ) ) ;
23- const invoke2 = ( a : any , b : any , next : ( a : any , b : any ) => any ) : any => clients . ActiveClient . enqueue ( ( ) => next ( a , b ) ) ;
24- const invoke3 = ( a : any , b : any , c : any , next : ( a : any , b : any , c : any ) => any ) : any => clients . ActiveClient . enqueue ( ( ) => next ( a , b , c ) ) ;
25- const invoke4 = ( a : any , b : any , c : any , d : any , next : ( a : any , b : any , c : any , d : any ) => any ) : any => clients . ActiveClient . enqueue ( ( ) => next ( a , b , c , d ) ) ;
26-
2721 return {
28- didOpen : async ( document , sendMessage ) => clients . ActiveClient . enqueue ( async ( ) => {
22+ didOpen : async ( document , sendMessage ) => {
2923 if ( ! util . isCpp ( document ) ) {
3024 return ;
3125 }
@@ -41,62 +35,41 @@ export function createProtocolFilter(): Middleware {
4135 const mappingString : string = baseFileName + "@" + document . fileName ;
4236 client . addFileAssociations ( mappingString , "cpp" ) ;
4337 client . sendDidChangeSettings ( ) ;
44- document = await vscode . languages . setTextDocumentLanguage ( document , "cpp" ) ;
38+ // This will cause the file to be closed and reopened.
39+ vscode . languages . setTextDocumentLanguage ( document , "cpp" ) ;
40+ return ;
4541 }
4642 // client.takeOwnership() will call client.TrackedDocuments.add() again, but that's ok. It's a Set.
4743 client . onDidOpenTextDocument ( document ) ;
4844 client . takeOwnership ( document ) ;
49- await sendMessage ( document ) ;
50-
51- // For a file already open when we activate, sometimes we don't get any notifications about visible
52- // or active text editors, visible ranges, or text selection. As a workaround, we trigger
53- // onDidChangeVisibleTextEditors here, only for the first file opened.
54- if ( ! anyFileOpened ) {
55- anyFileOpened = true ;
56- const cppEditors : vscode . TextEditor [ ] = vscode . window . visibleTextEditors . filter ( e => util . isCpp ( e . document ) ) ;
57- await client . onDidChangeVisibleTextEditors ( cppEditors ) ;
58- }
45+ sendMessage ( document ) . then ( ( ) => {
46+ // For a file already open when we activate, sometimes we don't get any notifications about visible
47+ // or active text editors, visible ranges, or text selection. As a workaround, we trigger
48+ // onDidChangeVisibleTextEditors here, only for the first file opened.
49+ if ( ! anyFileOpened ) {
50+ anyFileOpened = true ;
51+ const cppEditors : vscode . TextEditor [ ] = vscode . window . visibleTextEditors . filter ( e => util . isCpp ( e . document ) ) ;
52+ client . onDidChangeVisibleTextEditors ( cppEditors ) ;
53+ }
54+ } ) ;
5955 }
6056 }
61- } ) ,
62- didChange : invoke1 ,
63- willSave : invoke1 ,
57+ } ,
6458 willSaveWaitUntil : async ( event , sendMessage ) => {
65- // await clients.ActiveClient.ready;
66- // Don't use awaitUntilLanguageClientReady.
67- // Otherwise, the message can be delayed too long.
6859 const me : Client = clients . getClientFor ( event . document . uri ) ;
6960 if ( me . TrackedDocuments . has ( event . document . uri . toString ( ) ) ) {
7061 return sendMessage ( event ) ;
7162 }
7263 return [ ] ;
7364 } ,
74- didSave : invoke1 ,
75- didClose : async ( document , sendMessage ) => clients . ActiveClient . enqueue ( async ( ) => {
65+ didClose : async ( document , sendMessage ) => {
7666 const me : Client = clients . getClientFor ( document . uri ) ;
7767 const uriString : string = document . uri . toString ( ) ;
7868 if ( me . TrackedDocuments . has ( uriString ) ) {
7969 me . onDidCloseTextDocument ( document ) ;
8070 me . TrackedDocuments . delete ( uriString ) ;
81- await sendMessage ( document ) ;
71+ sendMessage ( document ) ;
8272 }
83- } ) ,
84- provideCompletionItem : invoke4 ,
85- resolveCompletionItem : invoke2 ,
86- provideHover : async ( document , position , token , next : ( document : any , position : any , token : any ) => any ) => clients . ActiveClient . enqueue ( async ( ) => {
87- const me : Client = clients . getClientFor ( document . uri ) ;
88- if ( me . TrackedDocuments . has ( document . uri . toString ( ) ) ) {
89- return next ( document , position , token ) ;
90- }
91- return null ;
92- } ) ,
93- provideSignatureHelp : invoke4 ,
94- provideDefinition : invoke3 ,
95- provideReferences : invoke4 ,
96- provideDocumentHighlights : invoke3 ,
97- provideDeclaration : invoke3 ,
98- workspace : {
99- didChangeConfiguration : invoke1
100- }
73+ } ,
10174 } ;
10275}
0 commit comments