@@ -113,10 +113,38 @@ interface CompileCommandsPaths {
113113 paths : string [ ] ;
114114}
115115
116+ interface QueryTranslationUnitSourceParams {
117+ uri : string ;
118+ }
119+
120+ export enum QueryTranslationUnitSourceConfigDisposition {
121+
122+ /**
123+ * No custom config needed for this file
124+ */
125+ ConfigNotNeeded = 0 ,
126+
127+ /**
128+ * Custom config is needed for this file
129+ */
130+ ConfigNeeded = 1 ,
131+
132+ /**
133+ * Custom config is needed for the ancestor file returned in uri
134+ */
135+ AncestorConfigNeeded = 2
136+ }
137+
138+ interface QueryTranslationUnitSourceResult {
139+ uri : string ;
140+ configDisposition : QueryTranslationUnitSourceConfigDisposition ;
141+ }
142+
116143// Requests
117144const NavigationListRequest : RequestType < TextDocumentIdentifier , string , void , void > = new RequestType < TextDocumentIdentifier , string , void , void > ( 'cpptools/requestNavigationList' ) ;
118145const GoToDeclarationRequest : RequestType < void , void , void , void > = new RequestType < void , void , void , void > ( 'cpptools/goToDeclaration' ) ;
119146const QueryCompilerDefaultsRequest : RequestType < QueryCompilerDefaultsParams , configs . CompilerDefaults , void , void > = new RequestType < QueryCompilerDefaultsParams , configs . CompilerDefaults , void , void > ( 'cpptools/queryCompilerDefaults' ) ;
147+ const QueryTranslationUnitSourceRequest : RequestType < QueryTranslationUnitSourceParams , QueryTranslationUnitSourceResult , void , void > = new RequestType < QueryTranslationUnitSourceParams , QueryTranslationUnitSourceResult , void , void > ( 'cpptools/queryTranslationUnitSource' ) ;
120148const SwitchHeaderSourceRequest : RequestType < SwitchHeaderSourceParams , string , void , void > = new RequestType < SwitchHeaderSourceParams , string , void , void > ( 'cpptools/didSwitchHeaderSource' ) ;
121149
122150// Notifications to the server
@@ -609,6 +637,15 @@ class DefaultClient implements Client {
609637 }
610638
611639 public async provideCustomConfiguration ( document : vscode . TextDocument ) : Promise < void > {
640+ let params : QueryTranslationUnitSourceParams = {
641+ uri : document . uri . toString ( )
642+ } ;
643+ let response : QueryTranslationUnitSourceResult = await this . languageClient . sendRequest ( QueryTranslationUnitSourceRequest , params ) ;
644+ if ( response . configDisposition === QueryTranslationUnitSourceConfigDisposition . ConfigNotNeeded ) {
645+ return Promise . resolve ( ) ;
646+ }
647+
648+ let tuUri : vscode . Uri = vscode . Uri . parse ( response . uri ) ;
612649 let tokenSource : CancellationTokenSource = new CancellationTokenSource ( ) ;
613650 let providers : CustomConfigurationProviderCollection = getCustomConfigProviders ( ) ;
614651 if ( providers . size === 0 ) {
@@ -633,8 +670,8 @@ class DefaultClient implements Client {
633670 }
634671
635672 providerName = provider . name ;
636- if ( await provider . canProvideConfiguration ( document . uri , tokenSource . token ) ) {
637- return provider . provideConfigurations ( [ document . uri ] , tokenSource . token ) ;
673+ if ( await provider . canProvideConfiguration ( tuUri , tokenSource . token ) ) {
674+ return provider . provideConfigurations ( [ tuUri ] , tokenSource . token ) ;
638675 }
639676 }
640677 } catch ( err ) {
@@ -647,14 +684,19 @@ class DefaultClient implements Client {
647684 ( configs : SourceFileConfigurationItem [ ] ) => {
648685 if ( configs && configs . length > 0 ) {
649686 this . sendCustomConfigurations ( configs , true ) ;
687+ if ( response . configDisposition === QueryTranslationUnitSourceConfigDisposition . AncestorConfigNeeded ) {
688+ // replacing uri with original uri
689+ let newConfig : SourceFileConfigurationItem = { uri : document . uri , configuration : configs [ 0 ] . configuration } ;
690+ this . sendCustomConfigurations ( [ newConfig ] , true ) ;
691+ }
650692 }
651693 } ,
652694 ( err ) => {
653695 if ( err === notReadyMessage ) {
654696 return ;
655697 }
656698 let settings : CppSettings = new CppSettings ( this . RootUri ) ;
657- if ( settings . configurationWarnings === "Enabled" && ! this . isExternalHeader ( document ) && ! vscode . debug . activeDebugSession ) {
699+ if ( settings . configurationWarnings === "Enabled" && ! this . isExternalHeader ( document . uri ) && ! vscode . debug . activeDebugSession ) {
658700 const dismiss : string = "Dismiss" ;
659701 const disable : string = "Disable Warnings" ;
660702 let message : string = `'${ providerName } ' is unable to provide IntelliSense configuration information for '${ document . uri . fsPath } '. ` +
@@ -675,8 +717,8 @@ class DefaultClient implements Client {
675717 } ) ;
676718 }
677719
678- private isExternalHeader ( document : vscode . TextDocument ) : boolean {
679- return util . isHeader ( document ) && ! document . uri . toString ( ) . startsWith ( this . RootUri . toString ( ) ) ;
720+ private isExternalHeader ( uri : vscode . Uri ) : boolean {
721+ return util . isHeader ( uri ) && ! uri . toString ( ) . startsWith ( this . RootUri . toString ( ) ) ;
680722 }
681723
682724 private getCustomConfigurationProviderId ( ) : Thenable < string | undefined > {
0 commit comments