@@ -13,16 +13,14 @@ import { shouldChangeFromCToCpp } from './utils';
13
13
14
14
export function createProtocolFilter ( ) : Middleware {
15
15
// Disabling lint for invoke handlers
16
- const defaultHandler : ( data : any , callback : ( data : any ) => Promise < void > ) => Promise < void > = async ( data , callback : ( data : any ) => void ) => { clients . ActiveClient . notifyWhenLanguageClientReady ( ( ) => callback ( data ) ) ; } ;
17
- // const invoke1 = async (a: any, next: (a: any) => any) => { await clients.ActiveClient.awaitUntilLanguageClientReady(); return next(a); };
16
+ const invoke1 = async ( a : any , next : ( a : any ) => any ) => { await clients . ActiveClient . awaitUntilLanguageClientReady ( ) ; return next ( a ) ; } ;
18
17
const invoke2 = async ( a : any , b : any , next : ( a : any , b : any ) => any ) => { await clients . ActiveClient . awaitUntilLanguageClientReady ( ) ; return next ( a , b ) ; } ;
19
18
const invoke3 = async ( a : any , b : any , c : any , next : ( a : any , b : any , c : any ) => any ) => { await clients . ActiveClient . awaitUntilLanguageClientReady ( ) ; return next ( a , b , c ) ; } ;
20
- const invoke4 = async ( a : any , b : any , c : any , d : any , next : ( a : any , b : any , c : any , d : any ) => any ) => { await clients . ActiveClient . awaitUntilLanguageClientReady ( ) ; return next ( a , b , c , d ) ; } ;
21
- // const invoke5 = async (a: any, b: any, c: any, d: any, e: any, next: (a: any, b: any, c: any, d: any, e: any) => any) => { await clients.ActiveClient.awaitUntilLanguageClientReady(); return next(a, b, c, d, e); };
22
- /* tslint:enable */
19
+ const invoke4 = async ( a : any , b : any , c : any , d : any , next : ( a : any , b : any , c : any , d : any ) => any ) => { await clients . ActiveClient . awaitUntilLanguageClientReady ( ) ; return next ( a , b , c , d ) ; } ; /* tslint:enable */
23
20
24
21
return {
25
22
didOpen : async ( document , sendMessage ) => {
23
+ await clients . ActiveClient . awaitUntilLanguageClientReady ( ) ;
26
24
const editor : vscode . TextEditor | undefined = vscode . window . visibleTextEditors . find ( e => e . document === document ) ;
27
25
if ( editor ) {
28
26
// If the file was visible editor when we were activated, we will not get a call to
@@ -34,28 +32,22 @@ export function createProtocolFilter(): Middleware {
34
32
clients . timeTelemetryCollector . setDidOpenTime ( document . uri ) ;
35
33
if ( clients . checkOwnership ( me , document ) ) {
36
34
me . TrackedDocuments . add ( document ) ;
37
- const finishDidOpen = ( doc : vscode . TextDocument ) => {
38
- me . provideCustomConfiguration ( doc . uri , undefined ) ;
39
- sendMessage ( doc ) ;
35
+ const finishDidOpen = async ( doc : vscode . TextDocument ) => {
36
+ await me . provideCustomConfiguration ( doc . uri , undefined ) ;
37
+ await sendMessage ( doc ) ;
40
38
me . onDidOpenTextDocument ( doc ) ;
41
39
if ( editor && editor === vscode . window . activeTextEditor ) {
42
40
onDidChangeActiveTextEditor ( editor ) ;
43
41
}
44
42
} ;
45
- let languageChanged : boolean = false ;
46
43
if ( document . languageId === "c" && shouldChangeFromCToCpp ( document ) ) {
47
44
const baesFileName : string = path . basename ( document . fileName ) ;
48
45
const mappingString : string = baesFileName + "@" + document . fileName ;
49
46
me . addFileAssociations ( mappingString , "cpp" ) ;
50
47
me . sendDidChangeSettings ( ) ;
51
- vscode . languages . setTextDocumentLanguage ( document , "cpp" ) . then ( ( newDoc : vscode . TextDocument ) => {
52
- finishDidOpen ( newDoc ) ;
53
- } ) ;
54
- languageChanged = true ;
55
- }
56
- if ( ! languageChanged ) {
57
- finishDidOpen ( document ) ;
48
+ document = await vscode . languages . setTextDocumentLanguage ( document , "cpp" ) ;
58
49
}
50
+ await finishDidOpen ( document ) ;
59
51
}
60
52
}
61
53
} else {
@@ -69,47 +61,49 @@ export function createProtocolFilter(): Middleware {
69
61
}
70
62
} ,
71
63
didChange : async ( textDocumentChangeEvent , sendMessage ) => {
64
+ await clients . ActiveClient . awaitUntilLanguageClientReady ( ) ;
72
65
const me : Client = clients . getClientFor ( textDocumentChangeEvent . document . uri ) ;
73
66
me . onDidChangeTextDocument ( textDocumentChangeEvent ) ;
74
- sendMessage ( textDocumentChangeEvent ) ;
67
+ await sendMessage ( textDocumentChangeEvent ) ;
75
68
} ,
76
- willSave : defaultHandler ,
69
+ willSave : invoke1 ,
77
70
willSaveWaitUntil : async ( event , sendMessage ) => {
71
+ // await clients.ActiveClient.awaitUntilLanguageClientReady();
72
+ // Don't use awaitUntilLanguageClientReady.
73
+ // Otherwise, the message can be delayed too long.
78
74
const me : Client = clients . getClientFor ( event . document . uri ) ;
79
75
if ( me . TrackedDocuments . has ( event . document ) ) {
80
- // Don't use me.requestWhenReady or notifyWhenLanguageClientReady;
81
- // otherwise, the message can be delayed too long.
82
76
return sendMessage ( event ) ;
83
77
}
84
- return Promise . resolve ( [ ] ) ;
78
+ return [ ] ;
85
79
} ,
86
- didSave : defaultHandler ,
80
+ didSave : invoke1 ,
87
81
didClose : async ( document , sendMessage ) => {
82
+ await clients . ActiveClient . awaitUntilLanguageClientReady ( ) ;
88
83
const me : Client = clients . getClientFor ( document . uri ) ;
89
84
if ( me . TrackedDocuments . has ( document ) ) {
90
85
me . onDidCloseTextDocument ( document ) ;
91
86
me . TrackedDocuments . delete ( document ) ;
92
- sendMessage ( document ) ;
87
+ await sendMessage ( document ) ;
93
88
}
94
89
} ,
95
-
96
90
provideCompletionItem : invoke4 ,
97
91
resolveCompletionItem : invoke2 ,
98
- provideHover : ( document , position , token , next : ( document : any , position : any , token : any ) => any ) => {
92
+ provideHover : async ( document , position , token , next : ( document : any , position : any , token : any ) => any ) => {
93
+ await clients . ActiveClient . awaitUntilLanguageClientReady ( ) ;
99
94
const me : Client = clients . getClientFor ( document . uri ) ;
100
- if ( clients . checkOwnership ( me , document ) ) {
101
- return clients . ActiveClient . requestWhenReady ( ( ) => next ( document , position , token ) ) ;
95
+ if ( me . TrackedDocuments . has ( document ) ) {
96
+ return next ( document , position , token ) ;
102
97
}
103
98
return null ;
104
99
} ,
105
100
provideSignatureHelp : invoke4 ,
106
101
provideDefinition : invoke3 ,
107
102
provideReferences : invoke4 ,
108
103
provideDocumentHighlights : invoke3 ,
109
- provideDeclaration : invoke3
110
- // I believe the default handler will do the same thing.
111
- // workspace: {
112
- // didChangeConfiguration: (sections, sendMessage) => sendMessage(sections)
113
- // }
104
+ provideDeclaration : invoke3 ,
105
+ workspace : {
106
+ didChangeConfiguration : invoke1
107
+ }
114
108
} ;
115
109
}
0 commit comments