Skip to content

Commit d5af9a1

Browse files
thejcannonbobbrow
authored andcommitted
Adding configuration variable replacement in c_cpp_properties.json. (#1529)
* Adding configuration variable replacement in c_cpp_properties.json. #314 * Fixing issues brought up by linter
1 parent e6d8d1f commit d5af9a1

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

Extension/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Fix duplicate `cannot open source file` errors. [#1469](https://github.com/Microsoft/vscode-cpptools/issues/1469)
99
* Fix error popup appearing with non-workspace files when using `compile_commands.json`. [#1475](https://github.com/Microsoft/vscode-cpptools/issues/1475)
1010
* Add more macros to `cpp.hint` (fixing missing symbols).
11+
* Added support for config variables to `c_cpp_properties.json` [#314](https://github.com/Microsoft/vscode-cpptools/issues/314)
1112

1213
## Version 0.14.6: January 17, 2018
1314
* Fix tag parser failing (and continuing to fail after edits) when it shouldn't. [#1367](https://github.com/Microsoft/vscode-cpptools/issues/1367)

Extension/src/common.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import HttpsProxyAgent = require('https-proxy-agent');
1313
import * as url from 'url';
1414
import { PlatformInformation } from './platform';
1515
import { getOutputChannelLogger, showOutputChannel } from './logger';
16+
import * as assert from 'assert';
1617

1718
export let extensionContext: vscode.ExtensionContext;
1819
export function setExtensionContext(context: vscode.ExtensionContext): void {
@@ -45,7 +46,7 @@ export const extensionNotReadyString: string = 'The C/C++ extension is still ins
4546
export function displayExtensionNotReadyPrompt(): void {
4647

4748
if (!isExtensionNotReadyPromptDisplayed) {
48-
isExtensionNotReadyPromptDisplayed = true;
49+
isExtensionNotReadyPromptDisplayed = true;
4950
showOutputChannel();
5051

5152
getOutputChannelLogger().showInformationMessage(extensionNotReadyString).then(
@@ -123,10 +124,26 @@ export function resolveVariables(input: string): string {
123124
return "";
124125
}
125126

126-
// Replace environment variables. (support both ${env:VAR} and ${VAR} syntax)
127-
let regexp: RegExp = /\$\{(env:|env.)?(.*?)\}/g;
128-
let ret: string = input.replace(regexp, (match: string, ignored: string, name: string) => {
129-
let newValue: string = process.env[name];
127+
// Replace environment and configuration variables.
128+
let regexp: RegExp = /\$\{((env|config)(.|:))?(.*?)\}/g;
129+
let ret: string = input.replace(regexp, (match: string, ignored1: string, varType: string, ignored2: string, name: string) => {
130+
// Historically, if the variable didn't have anything before the "." or ":"
131+
// it was assumed to be an environment variable
132+
if (varType === undefined) {
133+
varType = "env";
134+
}
135+
let newValue: string = undefined;
136+
switch (varType) {
137+
case "env": { newValue = process.env[name]; break; }
138+
case "config": {
139+
let config: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration();
140+
let keys: string[] = name.split('.');
141+
keys.forEach((key: string) => { config = (config) ? config.get(key) : config; });
142+
newValue = (config) ? config.toString() : undefined;
143+
break;
144+
}
145+
default: { assert.fail("unknown varType matched"); }
146+
}
130147
return (newValue) ? newValue : match;
131148
});
132149

0 commit comments

Comments
 (0)