Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added system to store and query properties from the active C/C++ configuration #5453

Merged
merged 8 commits into from
Jun 15, 2020
10 changes: 10 additions & 0 deletions Extension/c_cpp_properties.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@
}
},
"additionalProperties": false
},
"properties": {
bugengine marked this conversation as resolved.
Show resolved Hide resolved
"type": "object",
"description": "Custom properties that can be queried through the command ${cpptools:getCurrentConfigurationProperty}.",
"patternProperties": {
"(?!^workspaceFolder$)(?!^workspaceRoot$)(?!^workspaceFolderBasename$)(?!^default$)(^.+$)": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
Expand Down
6 changes: 6 additions & 0 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ export interface Client {
toggleReferenceResultsView(): void;
setCurrentConfigName(configurationName: string): Thenable<void>;
getCurrentConfigName(): Thenable<string | undefined>;
getCurrentConfigProperty(propertyName: string): Thenable<string>;
getVcpkgInstalled(): Thenable<boolean>;
getVcpkgEnabled(): Thenable<boolean>;
getCurrentCompilerPathAndArgs(): Thenable<util.CompilerPathAndArgs | undefined>;
Expand Down Expand Up @@ -1778,6 +1779,10 @@ export class DefaultClient implements Client {
return this.queueTask(() => Promise.resolve(this.configuration.CurrentConfiguration?.name));
}

public getCurrentConfigProperty(propertyName: string): Thenable<string> {
return this.queueTask(() => Promise.resolve(this.configuration.CurrentConfiguration?.properties?.[propertyName] || ''));
}

public setCurrentConfigName(configurationName: string): Thenable<void> {
return this.queueTask(() => new Promise((resolve, reject) => {
let configurations: configs.Configuration[] = this.configuration.Configurations || [];
Expand Down Expand Up @@ -2658,6 +2663,7 @@ class NullClient implements Client {
toggleReferenceResultsView(): void {}
setCurrentConfigName(configurationName: string): Thenable<void> { return Promise.resolve(); }
getCurrentConfigName(): Thenable<string> { return Promise.resolve(""); }
getCurrentConfigProperty(propertyName: string): Thenable<string> { return Promise.resolve(""); }
getVcpkgInstalled(): Thenable<boolean> { return Promise.resolve(false); }
getVcpkgEnabled(): Thenable<boolean> { return Promise.resolve(false); }
getCurrentCompilerPathAndArgs(): Thenable<util.CompilerPathAndArgs | undefined> { return Promise.resolve(undefined); }
Expand Down
1 change: 1 addition & 0 deletions Extension/src/LanguageServer/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface Configuration {
forcedInclude?: string[];
configurationProvider?: string;
browse?: Browse;
properties?: {[key: string]: string};
}

export interface ConfigurationErrors {
Expand Down
5 changes: 5 additions & 0 deletions Extension/src/LanguageServer/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ export function registerCommands(): void {
disposables.push(vscode.commands.registerCommand('C_Cpp.VcpkgClipboardInstallSuggested', onVcpkgClipboardInstallSuggested));
disposables.push(vscode.commands.registerCommand('C_Cpp.VcpkgOnlineHelpSuggested', onVcpkgOnlineHelpSuggested));
disposables.push(vscode.commands.registerCommand('cpptools.activeConfigName', onGetActiveConfigName));
disposables.push(vscode.commands.registerCommand('cpptools.activeConfigProperty', onGetActiveConfigProperty));
disposables.push(vscode.commands.registerCommand('cpptools.setActiveConfigName', onSetActiveConfigName));
getTemporaryCommandRegistrarInstance().executeDelayedCommands();
}
Expand Down Expand Up @@ -1166,6 +1167,10 @@ function onGetActiveConfigName(): Thenable<string | undefined> {
return clients.ActiveClient.getCurrentConfigName();
}

function onGetActiveConfigProperty(propertyName: string): Thenable<string> {
return clients.ActiveClient.getCurrentConfigProperty(propertyName);
}

function onLogDiagnostics(): void {
onActivationEvent();
clients.ActiveClient.logDiagnostics();
Expand Down