@@ -80,6 +80,8 @@ export class CppProperties {
80
80
private defaultCppStandard : string = null ;
81
81
private defaultIncludes : string [ ] = null ;
82
82
private defaultFrameworks : string [ ] = null ;
83
+ private vcpkgIncludes : string [ ] = [ ] ;
84
+ private vcpkgPathReady : boolean = false ;
83
85
private defaultIntelliSenseMode : string = null ;
84
86
private readonly configurationGlobPattern : string = "**/c_cpp_properties.json" ; // TODO: probably should be a single file, not all files...
85
87
private disposables : vscode . Disposable [ ] = [ ] ;
@@ -124,6 +126,8 @@ export class CppProperties {
124
126
this . handleConfigurationChange ( ) ;
125
127
} ) ;
126
128
129
+ this . buildVcpkgIncludePath ( ) ;
130
+
127
131
this . disposables . push ( vscode . Disposable . from ( this . configurationsChanged , this . selectionChanged , this . compileCommandsChanged ) ) ;
128
132
}
129
133
@@ -184,8 +188,8 @@ export class CppProperties {
184
188
this . configurationIncomplete = true ;
185
189
}
186
190
187
- private applyDefaultIncludePathsAndFrameworks ( ) : void {
188
- if ( this . configurationIncomplete && this . defaultIncludes && this . defaultFrameworks ) {
191
+ private applyDefaultIncludePathsAndFrameworks ( ) : void {
192
+ if ( this . configurationIncomplete && this . defaultIncludes && this . defaultFrameworks && this . vcpkgPathReady ) {
189
193
let configuration : Configuration = this . configurationJson . configurations [ this . CurrentConfiguration ] ;
190
194
let settings : CppSettings = new CppSettings ( this . rootUri ) ;
191
195
@@ -197,15 +201,15 @@ export class CppProperties {
197
201
198
202
if ( ! settings . defaultIncludePath ) {
199
203
// We don't add system includes to the includePath anymore. The language server has this information.
200
- configuration . includePath = [ "${workspaceFolder}" ] ;
204
+ configuration . includePath = [ "${workspaceFolder}" ] . concat ( this . vcpkgIncludes ) ;
205
+ }
206
+ if ( ! settings . defaultBrowsePath ) {
207
+ // We don't add system includes to the includePath anymore. The language server has this information.
208
+ configuration . browse . path = [ "${workspaceFolder}" ] . concat ( this . vcpkgIncludes ) ;
201
209
}
202
210
if ( ! settings . defaultDefines ) {
203
211
configuration . defines = ( process . platform === 'win32' ) ? [ "_DEBUG" , "UNICODE" , "_UNICODE" ] : [ ] ;
204
212
}
205
- if ( ! settings . defaultBrowsePath ) {
206
- // We don't add system includes to the browse.path anymore. The language server has this information.
207
- configuration . browse . path = [ "${workspaceFolder}" ] ;
208
- }
209
213
if ( ! settings . defaultMacFrameworkPath && process . platform === 'darwin' ) {
210
214
configuration . macFrameworkPath = this . defaultFrameworks ;
211
215
}
@@ -225,6 +229,35 @@ export class CppProperties {
225
229
}
226
230
}
227
231
232
+ private async buildVcpkgIncludePath ( ) : Promise < void > {
233
+ try {
234
+ // Check for vcpkg instance and include relevent paths if found.
235
+ if ( await util . checkFileExists ( util . getVcpkgPathDescriptorFile ( ) ) ) {
236
+ let vcpkgRoot : string = await util . readFileText ( util . getVcpkgPathDescriptorFile ( ) ) ;
237
+ let vcpkgInstallPath : string = path . join ( vcpkgRoot . trim ( ) , "/vcpkg/installed" ) ;
238
+ if ( await util . checkDirectoryExists ( vcpkgInstallPath ) ) {
239
+ let list : string [ ] = await util . readDir ( vcpkgInstallPath ) ;
240
+ // For every *directory* in the list (non-recursive)
241
+ list . forEach ( ( entry ) => {
242
+ if ( entry !== "vcpkg" ) {
243
+ let pathToCheck : string = path . join ( vcpkgInstallPath , entry ) ;
244
+ if ( fs . existsSync ( pathToCheck ) ) {
245
+ let p : string = path . join ( pathToCheck , "include" ) ;
246
+ if ( fs . existsSync ( p ) ) {
247
+ this . vcpkgIncludes . push ( p ) ;
248
+ }
249
+ }
250
+ }
251
+ } ) ;
252
+ }
253
+ }
254
+ } catch ( error ) { } finally {
255
+ this . vcpkgPathReady = true ;
256
+ this . handleConfigurationChange ( ) ;
257
+ }
258
+
259
+ }
260
+
228
261
private getConfigIndexForPlatform ( config : any ) : number {
229
262
if ( this . configurationJson . configurations . length > 3 ) {
230
263
return this . configurationJson . configurations . length - 1 ; // Default to the last custom configuration.
0 commit comments