@@ -734,11 +734,12 @@ export interface Client {
734734 getVcpkgEnabled ( ) : Thenable < boolean > ;
735735 getCurrentCompilerPathAndArgs ( ) : Thenable < util . CompilerPathAndArgs | undefined > ;
736736 getKnownCompilers ( ) : Thenable < configs . KnownCompiler [ ] | undefined > ;
737- takeOwnership ( document : vscode . TextDocument ) : void ;
737+ takeOwnership ( document : vscode . TextDocument ) : Promise < void > ;
738+ sendDidOpen ( document : vscode . TextDocument ) : Promise < void > ;
738739 queueTask < T > ( task : ( ) => Thenable < T > ) : Promise < T > ;
739- requestWhenReady < T > ( request : ( ) => Thenable < T > ) : Thenable < T > ;
740- notifyWhenLanguageClientReady ( notify : ( ) => void ) : void ;
741- awaitUntilLanguageClientReady ( ) : Thenable < void > ;
740+ requestWhenReady < T > ( request : ( ) => Thenable < T > ) : Promise < T > ;
741+ notifyWhenLanguageClientReady < T > ( notify : ( ) => T ) : Promise < T > ;
742+ awaitUntilLanguageClientReady ( ) : Promise < void > ;
742743 requestSwitchHeaderSource ( rootUri : vscode . Uri , fileName : string ) : Thenable < string > ;
743744 activeDocumentChanged ( document : vscode . TextDocument ) : Promise < void > ;
744745 restartIntelliSenseForFile ( document : vscode . TextDocument ) : Promise < void > ;
@@ -1934,7 +1935,13 @@ export class DefaultClient implements Client {
19341935 * that it knows about the file, as well as adding it to this client's set of
19351936 * tracked documents.
19361937 */
1937- public takeOwnership ( document : vscode . TextDocument ) : void {
1938+ public async takeOwnership ( document : vscode . TextDocument ) : Promise < void > {
1939+ this . trackedDocuments . add ( document ) ;
1940+ this . updateActiveDocumentTextOptions ( ) ;
1941+ await this . requestWhenReady ( ( ) => this . sendDidOpen ( document ) ) ;
1942+ }
1943+
1944+ public async sendDidOpen ( document : vscode . TextDocument ) : Promise < void > {
19381945 const params : DidOpenTextDocumentParams = {
19391946 textDocument : {
19401947 uri : document . uri . toString ( ) ,
@@ -1943,9 +1950,7 @@ export class DefaultClient implements Client {
19431950 text : document . getText ( )
19441951 }
19451952 } ;
1946- this . updateActiveDocumentTextOptions ( ) ;
1947- this . notifyWhenLanguageClientReady ( ( ) => this . languageClient . sendNotification ( DidOpenNotification , params ) ) ;
1948- this . trackedDocuments . add ( document ) ;
1953+ await this . languageClient . sendNotification ( DidOpenNotification , params ) ;
19491954 }
19501955
19511956 /**
@@ -2016,7 +2021,7 @@ export class DefaultClient implements Client {
20162021 } ) ;
20172022 }
20182023
2019- public requestWhenReady < T > ( request : ( ) => Thenable < T > ) : Thenable < T > {
2024+ public requestWhenReady < T > ( request : ( ) => Thenable < T > ) : Promise < T > {
20202025 return this . queueTask ( request ) ;
20212026 }
20222027
@@ -2027,7 +2032,7 @@ export class DefaultClient implements Client {
20272032 return this . queueTask ( task ) ;
20282033 }
20292034
2030- public awaitUntilLanguageClientReady ( ) : Thenable < void > {
2035+ public awaitUntilLanguageClientReady ( ) : Promise < void > {
20312036 const task : ( ) => Thenable < void > = ( ) => new Promise < void > ( resolve => {
20322037 resolve ( ) ;
20332038 } ) ;
@@ -2116,7 +2121,7 @@ export class DefaultClient implements Client {
21162121 if ( fileName === ".editorconfig" ) {
21172122 cachedEditorConfigSettings . clear ( ) ;
21182123 cachedEditorConfigLookups . clear ( ) ;
2119- await this . updateActiveDocumentTextOptions ( ) ;
2124+ this . updateActiveDocumentTextOptions ( ) ;
21202125 }
21212126 if ( fileName === ".clang-format" || fileName === "_clang-format" ) {
21222127 cachedEditorConfigLookups . clear ( ) ;
@@ -2144,7 +2149,7 @@ export class DefaultClient implements Client {
21442149 if ( fileName === ".editorconfig" ) {
21452150 cachedEditorConfigSettings . clear ( ) ;
21462151 cachedEditorConfigLookups . clear ( ) ;
2147- await this . updateActiveDocumentTextOptions ( ) ;
2152+ this . updateActiveDocumentTextOptions ( ) ;
21482153 }
21492154 if ( dotIndex !== - 1 ) {
21502155 const ext : string = uri . fsPath . substring ( dotIndex + 1 ) ;
@@ -2456,7 +2461,7 @@ export class DefaultClient implements Client {
24562461 return this . languageClient . sendRequest ( QueryCompilerDefaultsRequest , params ) ;
24572462 }
24582463
2459- private async updateActiveDocumentTextOptions ( ) : Promise < void > {
2464+ private updateActiveDocumentTextOptions ( ) : void {
24602465 const editor : vscode . TextEditor | undefined = vscode . window . activeTextEditor ;
24612466 if ( editor ?. document ?. uri . scheme === "file"
24622467 && ( editor . document . languageId === "c"
@@ -2493,7 +2498,7 @@ export class DefaultClient implements Client {
24932498 * notifications to the language server
24942499 */
24952500 public async activeDocumentChanged ( document : vscode . TextDocument ) : Promise < void > {
2496- await this . updateActiveDocumentTextOptions ( ) ;
2501+ this . updateActiveDocumentTextOptions ( ) ;
24972502 await this . awaitUntilLanguageClientReady ( ) ;
24982503 this . languageClient . sendNotification ( ActiveDocumentChangeNotification , this . languageClient . code2ProtocolConverter . asTextDocumentIdentifier ( document ) ) ;
24992504 }
@@ -3417,11 +3422,12 @@ class NullClient implements Client {
34173422 getVcpkgEnabled ( ) : Thenable < boolean > { return Promise . resolve ( false ) ; }
34183423 getCurrentCompilerPathAndArgs ( ) : Thenable < util . CompilerPathAndArgs | undefined > { return Promise . resolve ( undefined ) ; }
34193424 getKnownCompilers ( ) : Thenable < configs . KnownCompiler [ ] | undefined > { return Promise . resolve ( [ ] ) ; }
3420- takeOwnership ( document : vscode . TextDocument ) : void { }
3425+ takeOwnership ( document : vscode . TextDocument ) : Promise < void > { return Promise . resolve ( ) ; }
3426+ sendDidOpen ( document : vscode . TextDocument ) : Promise < void > { return Promise . resolve ( ) ; }
34213427 queueTask < T > ( task : ( ) => Thenable < T > ) : Promise < T > { return Promise . resolve ( task ( ) ) ; }
3422- requestWhenReady < T > ( request : ( ) => Thenable < T > ) : Thenable < T > { return request ( ) ; }
3423- notifyWhenLanguageClientReady ( notify : ( ) => void ) : void { }
3424- awaitUntilLanguageClientReady ( ) : Thenable < void > { return Promise . resolve ( ) ; }
3428+ requestWhenReady < T > ( request : ( ) => Thenable < T > ) : Promise < T > { return Promise . resolve ( request ( ) ) ; }
3429+ notifyWhenLanguageClientReady < T > ( notify : ( ) => T ) : Promise < T > { return Promise . resolve ( notify ( ) ) ; }
3430+ awaitUntilLanguageClientReady ( ) : Promise < void > { return Promise . resolve ( ) ; }
34253431 requestSwitchHeaderSource ( rootUri : vscode . Uri , fileName : string ) : Thenable < string > { return Promise . resolve ( "" ) ; }
34263432 activeDocumentChanged ( document : vscode . TextDocument ) : Promise < void > { return Promise . resolve ( ) ; }
34273433 restartIntelliSenseForFile ( document : vscode . TextDocument ) : Promise < void > { return Promise . resolve ( ) ; }
0 commit comments