@@ -92,6 +92,10 @@ interface CustomConfigurationParams {
9292 configurationItems : SourceFileConfigurationItem [ ] ;
9393}
9494
95+ interface CompileCommandsPaths {
96+ paths : string [ ] ;
97+ }
98+
9599// Requests
96100const NavigationListRequest : RequestType < TextDocumentIdentifier , string , void , void > = new RequestType < TextDocumentIdentifier , string , void , void > ( 'cpptools/requestNavigationList' ) ;
97101const GoToDeclarationRequest : RequestType < void , void , void , void > = new RequestType < void , void , void , void > ( 'cpptools/goToDeclaration' ) ;
@@ -122,6 +126,7 @@ const ReportStatusNotification: NotificationType<ReportStatusNotificationBody, v
122126const DebugProtocolNotification : NotificationType < OutputNotificationBody , void > = new NotificationType < OutputNotificationBody , void > ( 'cpptools/debugProtocol' ) ;
123127const DebugLogNotification : NotificationType < OutputNotificationBody , void > = new NotificationType < OutputNotificationBody , void > ( 'cpptools/debugLog' ) ;
124128const InactiveRegionNotification : NotificationType < InactiveRegionParams , void > = new NotificationType < InactiveRegionParams , void > ( 'cpptools/inactiveRegions' ) ;
129+ const CompileCommandsPathsNotification : NotificationType < CompileCommandsPaths , void > = new NotificationType < CompileCommandsPaths , void > ( 'cpptools/compileCommandsPaths' ) ;
125130
126131let failureMessageShown : boolean = false ;
127132
@@ -521,6 +526,7 @@ class DefaultClient implements Client {
521526 this . languageClient . onNotification ( ReportStatusNotification , ( e ) => this . updateStatus ( e ) ) ;
522527 this . languageClient . onNotification ( ReportTagParseStatusNotification , ( e ) => this . updateTagParseStatus ( e ) ) ;
523528 this . languageClient . onNotification ( InactiveRegionNotification , ( e ) => this . updateInactiveRegions ( e ) ) ;
529+ this . languageClient . onNotification ( CompileCommandsPathsNotification , ( e ) => this . promptCompileCommands ( e ) ) ;
524530 this . setupOutputHandlers ( ) ;
525531 }
526532
@@ -745,6 +751,46 @@ class DefaultClient implements Client {
745751 }
746752 }
747753
754+ private promptCompileCommands ( params : CompileCommandsPaths ) : void {
755+ if ( this . configuration . Configurations [ this . configuration . CurrentConfiguration ] . compileCommands !== undefined ) {
756+ return ;
757+ }
758+
759+ let showCompileCommandsSelection : PersistentState < boolean > = new PersistentState < boolean > ( "CPP.showCompileCommandsSelection" , true ) ;
760+ if ( ! showCompileCommandsSelection . Value ) {
761+ return ;
762+ }
763+
764+ let compileCommandStr : string = params . paths . length > 1 ? "a compile_commands.json file" : params . paths [ 0 ] ;
765+ let folderStr : string = ( vscode . workspace . workspaceFolders && vscode . workspace . workspaceFolders . length > 1 ) ? "the " + this . Name : "this" ;
766+ const message : string = `Would you like to use ${ compileCommandStr } to auto-configure IntelliSense for ${ folderStr } folder?` ;
767+
768+ const yes : string = "Yes" ;
769+ const notNow : string = "Not Now" ;
770+ const dontAskAgain : string = "Don't Ask Again" ;
771+ vscode . window . showInformationMessage ( message , yes , notNow , dontAskAgain ) . then ( ( value ) => {
772+ switch ( value ) {
773+ case yes :
774+ if ( params . paths . length > 1 ) {
775+ ui . showCompileCommands ( params . paths ) . then ( ( index ) => {
776+ if ( index < 0 ) {
777+ return ;
778+ }
779+ this . configuration . setCompileCommands ( params . paths [ index ] ) ;
780+ } ) ;
781+ } else {
782+ this . configuration . setCompileCommands ( params . paths [ 0 ] ) ;
783+ }
784+ break ;
785+ case notNow :
786+ break ;
787+ case dontAskAgain :
788+ showCompileCommandsSelection . Value = false ;
789+ break ;
790+ }
791+ } ) ;
792+ }
793+
748794 /*********************************************
749795 * requests to the language server
750796 *********************************************/
0 commit comments