@@ -1223,7 +1223,7 @@ export class DefaultClient implements Client {
12231223 // Resume parsing on either resolve or reject, only if parsing was not resumed due to timeout
12241224 let hasCompleted : boolean = false ;
12251225 task ( ) . then ( async config => {
1226- this . sendCustomBrowseConfiguration ( config , currentProvider . extensionId ) ;
1226+ await this . sendCustomBrowseConfiguration ( config , currentProvider . extensionId ) ;
12271227 if ( ! hasCompleted ) {
12281228 hasCompleted = true ;
12291229 if ( currentProvider . version >= Version . v2 ) {
@@ -1243,7 +1243,7 @@ export class DefaultClient implements Client {
12431243 global . setTimeout ( async ( ) => {
12441244 if ( ! hasCompleted ) {
12451245 hasCompleted = true ;
1246- this . sendCustomBrowseConfiguration ( null , null , true ) ;
1246+ await this . sendCustomBrowseConfiguration ( null , null , true ) ;
12471247 if ( currentProvider . version >= Version . v2 ) {
12481248 console . warn ( "Configuration Provider timed out in {0}ms." , configProviderTimeout ) ;
12491249 this . resumeParsing ( ) ;
@@ -1340,7 +1340,7 @@ export class DefaultClient implements Client {
13401340 return this . callTaskWithTimeout ( provideConfigurationAsync , configProviderTimeout , tokenSource ) . then (
13411341 ( configs : SourceFileConfigurationItem [ ] ) => {
13421342 if ( configs && configs . length > 0 ) {
1343- this . sendCustomConfigurations ( configs ) ;
1343+ this . sendCustomConfigurations ( configs , false ) ;
13441344 }
13451345 onFinished ( ) ;
13461346 } ,
@@ -1497,12 +1497,16 @@ export class DefaultClient implements Client {
14971497 return this . queueTask ( request ) ;
14981498 }
14991499
1500- public notifyWhenReady ( notify : ( ) => void ) : Thenable < void > {
1500+ public notifyWhenReady ( notify : ( ) => void , blockingTask ?: boolean ) : Thenable < void > {
15011501 let task : ( ) => Thenable < void > = ( ) => new Promise ( resolve => {
15021502 notify ( ) ;
15031503 resolve ( ) ;
15041504 } ) ;
1505- return this . queueTask ( task ) ;
1505+ if ( blockingTask ) {
1506+ return this . queueBlockingTask ( task ) ;
1507+ } else {
1508+ return this . queueTask ( task ) ;
1509+ }
15061510 }
15071511
15081512 /**
@@ -1937,27 +1941,30 @@ export class DefaultClient implements Client {
19371941 c . compilerPath = compilerPathAndArgs . compilerPath ;
19381942 c . compilerArgs = compilerPathAndArgs . additionalArgs ;
19391943 } ) ;
1940- if ( ! this . doneInitialCustomBrowseConfigurationCheck ) {
1941- // Send the last custom browse configuration we received from this provider.
1942- // This ensures we don't start tag parsing without it, and undo'ing work we have to re-do when the (likely same) browse config arrives
1943- // Should only execute on launch, for the initial delivery of configurations
1944- let lastCustomBrowseConfigurationProviderId : PersistentFolderState < string > = new PersistentFolderState < string > ( "CPP.lastCustomBrowseConfigurationProviderId" , null , this . RootPath ) ;
1945- if ( isSameProviderExtensionId ( lastCustomBrowseConfigurationProviderId . Value , configurations [ params . currentConfiguration ] . configurationProvider ) ) {
1946- let lastCustomBrowseConfiguration : PersistentFolderState < WorkspaceBrowseConfiguration > = new PersistentFolderState < WorkspaceBrowseConfiguration > ( "CPP.lastCustomBrowseConfiguration" , null , this . RootPath ) ;
1947- if ( lastCustomBrowseConfiguration . Value ) {
1948- this . sendCustomBrowseConfiguration ( lastCustomBrowseConfiguration . Value , lastCustomBrowseConfigurationProviderId . Value ) ;
1944+ this . notifyWhenReady ( ( ) => {
1945+ if ( ! this . doneInitialCustomBrowseConfigurationCheck ) {
1946+ // Send the last custom browse configuration we received from this provider.
1947+ // This ensures we don't start tag parsing without it, and undo'ing work we have to re-do when the (likely same) browse config arrives
1948+ // Should only execute on launch, for the initial delivery of configurations
1949+ let lastCustomBrowseConfigurationProviderId : PersistentFolderState < string > = new PersistentFolderState < string > ( "CPP.lastCustomBrowseConfigurationProviderId" , null , this . RootPath ) ;
1950+ if ( lastCustomBrowseConfigurationProviderId . Value === configurations [ params . currentConfiguration ] . configurationProvider ) {
1951+ let lastCustomBrowseConfiguration : PersistentFolderState < WorkspaceBrowseConfiguration > = new PersistentFolderState < WorkspaceBrowseConfiguration > ( "CPP.lastCustomBrowseConfiguration" , null , this . RootPath ) ;
1952+ if ( lastCustomBrowseConfiguration . Value ) {
1953+ this . sendCustomBrowseConfiguration ( lastCustomBrowseConfiguration . Value , lastCustomBrowseConfigurationProviderId . Value ) ;
1954+ }
19491955 }
1956+ this . doneInitialCustomBrowseConfigurationCheck = true ;
19501957 }
1951- this . doneInitialCustomBrowseConfigurationCheck = true ;
1952- }
1953- this . languageClient . sendNotification ( ChangeFolderSettingsNotification , params ) ;
1954- this . model . activeConfigName . Value = configurations [ params . currentConfiguration ] . name ;
1955- let newProvider : string = this . configuration . CurrentConfigurationProvider ;
1956- if ( ! isSameProviderExtensionId ( newProvider , this . configurationProvider ) ) {
1957- this . configurationProvider = newProvider ;
1958- this . updateCustomBrowseConfiguration ( ) ;
1959- this . updateCustomConfigurations ( ) ;
1960- }
1958+ this . languageClient . sendNotification ( ChangeFolderSettingsNotification , params ) ;
1959+ this . model . activeConfigName . Value = configurations [ params . currentConfiguration ] . name ;
1960+ } ) . then ( ( ) => {
1961+ let newProvider : string = this . configuration . CurrentConfigurationProvider ;
1962+ if ( ! isSameProviderExtensionId ( newProvider , this . configurationProvider ) ) {
1963+ this . configurationProvider = newProvider ;
1964+ this . updateCustomBrowseConfiguration ( ) ;
1965+ this . updateCustomConfigurations ( ) ;
1966+ }
1967+ } ) ;
19611968 }
19621969
19631970 private onSelectedConfigurationChanged ( index : number ) : void {
@@ -1990,7 +1997,7 @@ export class DefaultClient implements Client {
19901997 util . isOptionalArrayOfString ( input . configuration . forcedInclude ) ) ;
19911998 }
19921999
1993- private sendCustomConfigurations ( configs : any ) : void {
2000+ private sendCustomConfigurations ( configs : any , blockingTask ?: boolean ) : void {
19942001 // configs is marked as 'any' because it is untrusted data coming from a 3rd-party. We need to sanitize it before sending it to the language server.
19952002 if ( ! configs || ! ( configs instanceof Array ) ) {
19962003 console . warn ( "discarding invalid SourceFileConfigurationItems[]: " + configs ) ;
@@ -2038,10 +2045,16 @@ export class DefaultClient implements Client {
20382045 configurationItems : sanitized
20392046 } ;
20402047
2041- this . languageClient . sendNotification ( CustomConfigurationNotification , params ) ;
2048+ if ( blockingTask ) {
2049+ this . notifyWhenReady ( ( ) => {
2050+ this . languageClient . sendNotification ( CustomConfigurationNotification , params ) ;
2051+ } , blockingTask ) ;
2052+ } else {
2053+ this . languageClient . sendNotification ( CustomConfigurationNotification , params ) ;
2054+ }
20422055 }
20432056
2044- private sendCustomBrowseConfiguration ( config : any , providerId : string , timeoutOccured ?: boolean ) : void {
2057+ private sendCustomBrowseConfiguration ( config : any , providerId : string , timeoutOccured ?: boolean ) : Thenable < void > {
20452058 let lastCustomBrowseConfiguration : PersistentFolderState < WorkspaceBrowseConfiguration > = new PersistentFolderState < WorkspaceBrowseConfiguration > ( "CPP.lastCustomBrowseConfiguration" , null , this . RootPath ) ;
20462059 let lastCustomBrowseConfigurationProviderId : PersistentFolderState < string > = new PersistentFolderState < string > ( "CPP.lastCustomBrowseConfigurationProviderId" , null , this . RootPath ) ;
20472060 let sanitized : util . Mutable < WorkspaceBrowseConfiguration > ;
@@ -2059,7 +2072,7 @@ export class DefaultClient implements Client {
20592072 break ;
20602073 }
20612074 console . log ( "No browse configuration is available." ) ;
2062- return ;
2075+ return Promise . resolve ( ) ;
20632076 }
20642077
20652078 sanitized = { ...< WorkspaceBrowseConfiguration > config } ;
@@ -2074,7 +2087,7 @@ export class DefaultClient implements Client {
20742087 console . log ( "Falling back to last received browse configuration: " , JSON . stringify ( sanitized , null , 2 ) ) ;
20752088 break ;
20762089 }
2077- return ;
2090+ return Promise . resolve ( ) ;
20782091 }
20792092
20802093 let settings : CppSettings = new CppSettings ( this . RootUri ) ;
@@ -2101,7 +2114,7 @@ export class DefaultClient implements Client {
21012114 browseConfiguration : sanitized
21022115 } ;
21032116
2104- this . languageClient . sendNotification ( CustomBrowseConfigurationNotification , params ) ;
2117+ return this . notifyWhenReady ( ( ) => this . languageClient . sendNotification ( CustomBrowseConfigurationNotification , params ) ) ;
21052118 }
21062119
21072120 private clearCustomConfigurations ( ) : void {
0 commit comments