Skip to content

Commit

Permalink
Allow workspaceFolderBasename in default settings (#2503)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-arjones authored and bobbrow committed Sep 10, 2018
1 parent c206a4b commit f44e906
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Extension/src/LanguageServer/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class CppProperties {
public get Configurations(): Configuration[] { return this.configurationJson.configurations; }
public get CurrentConfigurationIndex(): number { return this.currentConfigurationIndex.Value; }
public get CurrentConfiguration(): Configuration { return this.Configurations[this.CurrentConfigurationIndex]; }

public get CurrentConfigurationProvider(): string|null {
if (this.CurrentConfiguration.configurationProvider) {
return this.CurrentConfiguration.configurationProvider;
Expand Down Expand Up @@ -202,6 +202,7 @@ export class CppProperties {

private resetToDefaultSettings(resetIndex: boolean): void {
this.configurationJson = getDefaultCppProperties();
this.extendConfigurationEnvironment();
if (resetIndex || this.CurrentConfigurationIndex < 0 ||
this.CurrentConfigurationIndex >= this.configurationJson.configurations.length) {
this.currentConfigurationIndex.Value = this.getConfigIndexForPlatform(this.configurationJson);
Expand Down Expand Up @@ -252,6 +253,14 @@ export class CppProperties {
}
}

private extendConfigurationEnvironment(): void {
if (!this.configurationJson.env) {
this.configurationJson.env = {};
}

this.configurationJson.env["workspaceFolderBasename"] = path.basename(this.rootUri.fsPath);
}

private async buildVcpkgIncludePath(): Promise<void> {
try {
// Check for vcpkgRoot and include relevent paths if found.
Expand Down Expand Up @@ -611,11 +620,9 @@ export class CppProperties {
delete this.configurationJson.env['workspaceRoot'];
delete this.configurationJson.env['workspaceFolder'];
delete this.configurationJson.env['default'];
} else {
this.configurationJson.env = {};
}

this.configurationJson.env["workspaceFolderBasename"] = path.basename(this.rootUri.fsPath);
this.extendConfigurationEnvironment();

// Warning: There is a chance that this is incorrect in the event that the c_cpp_properties.json file was created before
// the system includes were available.
Expand All @@ -630,7 +637,7 @@ export class CppProperties {
if (this.configurationJson.version === 2) {
this.updateToVersion3();
}

if (this.configurationJson.version === 3) {
this.updateToVersion4();
} else {
Expand Down

0 comments on commit f44e906

Please sign in to comment.