Skip to content

Commit 0545a5b

Browse files
committed
Update.
1 parent 86ff338 commit 0545a5b

File tree

7 files changed

+102
-26
lines changed

7 files changed

+102
-26
lines changed

Extension/c_cpp_properties.schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@
180180
"type": "string"
181181
},
182182
"mergeConfigurations": {
183-
"markdownDescription": "Set to `true` to merge `includePath`, `defines`, `forcedInclude`, and `browse.path` with those received from the configuration provider. Changes to `mergeConfigurations` won't take effect until the configuration provider resends the configuration.",
184-
"descriptionHint": "{Locked=\"`true`\"} {Locked=\"`includePath`\"} {Locked=\"`defines`\"} {Locked=\"`forcedInclude`\"} {Locked=\"`browse.path`\"} {Locked=\"`mergeConfigurations`\"}",
183+
"markdownDescription": "Set to `true` to merge `includePath`, `defines`, `forcedInclude`, and `browse.path` with those received from the configuration provider.",
184+
"descriptionHint": "{Locked=\"`true`\"} {Locked=\"`includePath`\"} {Locked=\"`defines`\"} {Locked=\"`forcedInclude`\"} {Locked=\"`browse.path`\"}",
185185
"type": "boolean"
186186
},
187187
"browse": {

Extension/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,7 @@
841841
},
842842
"C_Cpp.default.mergeConfigurations": {
843843
"type": "boolean",
844+
"default": false,
844845
"markdownDescription": "%c_cpp.configuration.default.mergeConfigurations.markdownDescription%",
845846
"scope": "resource"
846847
},

Extension/src/LanguageServer/client.ts

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import { CloseAction, DidOpenTextDocumentParams, ErrorAction, LanguageClientOpti
3232
import { LanguageClient, ServerOptions } from 'vscode-languageclient/node';
3333
import * as nls from 'vscode-nls';
3434
import { DebugConfigurationProvider } from '../Debugger/configurationProvider';
35-
import { CustomConfigurationProvider1, getCustomConfigProviders, isSameProviderExtensionId } from '../LanguageServer/customProviders';
3635
import { ManualPromise } from '../Utility/Async/manualPromise';
3736
import { ManualSignal } from '../Utility/Async/manualSignal';
3837
import { logAndReturn } from '../Utility/Async/returns';
@@ -57,6 +56,7 @@ import {
5756
import { Location, TextEdit, WorkspaceEdit } from './commonTypes';
5857
import * as configs from './configurations';
5958
import { CopilotCompletionContextFeatures, CopilotCompletionContextProvider } from './copilotCompletionContextProvider';
59+
import { CustomConfigurationProvider1, getCustomConfigProviders, isSameProviderExtensionId } from './customProviders';
6060
import { DataBinding } from './dataBinding';
6161
import { cachedEditorConfigSettings, getEditorConfigSettings } from './editorConfig';
6262
import { CppSourceStr, clients, configPrefix, initializeIntervalTimer, updateLanguageConfigurations, usesCrashHandler, watchForCrashes } from './extension';
@@ -244,7 +244,6 @@ interface CustomConfigurationParams extends WorkspaceFolderParams {
244244

245245
interface CustomBrowseConfigurationParams extends WorkspaceFolderParams {
246246
browseConfiguration: InternalWorkspaceBrowseConfiguration;
247-
mergeConfigurations: boolean;
248247
}
249248

250249
interface CompileCommandsPaths extends WorkspaceFolderParams {
@@ -890,6 +889,11 @@ export class DefaultClient implements Client {
890889
private settingsTracker: SettingsTracker;
891890
private loggingLevel: number = 1;
892891
private configurationProvider?: string;
892+
private mergeConfigurations: boolean = false;
893+
private includePath?: string[];
894+
private defines?: string[];
895+
private forcedInclude?: string[];
896+
private browsePath?: string[];
893897
private hoverProvider: HoverProvider | undefined;
894898
private copilotHoverProvider: CopilotHoverProvider | undefined;
895899
private copilotCompletionProvider?: CopilotCompletionContextProvider;
@@ -3140,11 +3144,45 @@ export class DefaultClient implements Client {
31403144
const configName: string | undefined = configurations[params.currentConfiguration].name ?? "";
31413145
this.model.activeConfigName.setValueIfActive(configName);
31423146
const newProvider: string | undefined = this.configuration.CurrentConfigurationProvider;
3143-
if (!isSameProviderExtensionId(newProvider, this.configurationProvider)) {
3144-
if (this.configurationProvider) {
3147+
const previousProvider: string | undefined = this.configurationProvider;
3148+
let updateCustomConfigs: boolean = false;
3149+
if (!isSameProviderExtensionId(previousProvider, newProvider)) {
3150+
this.configurationProvider = newProvider;
3151+
updateCustomConfigs = true;
3152+
}
3153+
if (newProvider !== undefined) {
3154+
const newMergeConfigurations: boolean = this.configuration.CurrentMergeConfigurations;
3155+
if (this.mergeConfigurations != newMergeConfigurations) {
3156+
this.mergeConfigurations = newMergeConfigurations;
3157+
updateCustomConfigs = true;
3158+
}
3159+
if (newMergeConfigurations) {
3160+
const newIncludePath: string[] | undefined = this.configuration.CurrentIncludePath;
3161+
if (!util.equals(this.includePath, newIncludePath)) {
3162+
this.includePath = newIncludePath;
3163+
updateCustomConfigs = true;
3164+
}
3165+
const newDefines: string[] | undefined = this.configuration.CurrentDefines;
3166+
if (!util.equals(this.defines, newDefines)) {
3167+
this.defines = newDefines;
3168+
updateCustomConfigs = true;
3169+
}
3170+
const newForcedInclude: string[] | undefined = this.configuration.CurrentForcedInclude;
3171+
if (!util.equals(this.forcedInclude, newForcedInclude)) {
3172+
this.forcedInclude = newForcedInclude;
3173+
updateCustomConfigs = true;
3174+
}
3175+
const newBrowsePath: string[] | undefined = this.configuration.CurrentBrowsePath;
3176+
if (!util.equals(this.browsePath, newBrowsePath)) {
3177+
this.browsePath = newBrowsePath;
3178+
updateCustomConfigs = true;
3179+
}
3180+
}
3181+
}
3182+
if (updateCustomConfigs) {
3183+
if (previousProvider) {
31453184
void this.clearCustomBrowseConfiguration().catch(logAndReturn.undefined);
31463185
}
3147-
this.configurationProvider = newProvider;
31483186
void this.updateCustomBrowseConfiguration().catch(logAndReturn.undefined);
31493187
void this.updateCustomConfigurations().catch(logAndReturn.undefined);
31503188
}
@@ -3350,8 +3388,7 @@ export class DefaultClient implements Client {
33503388

33513389
const params: CustomBrowseConfigurationParams = {
33523390
browseConfiguration: sanitized,
3353-
workspaceFolderUri: this.RootUri?.toString(),
3354-
mergeConfigurations: this.configuration.CurrentConfiguration?.mergeConfigurations ?? false
3391+
workspaceFolderUri: this.RootUri?.toString()
33553392
};
33563393

33573394
void this.languageClient.sendNotification(CustomBrowseConfigurationNotification, params).catch(logAndReturn.undefined);

Extension/src/LanguageServer/configurations.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,41 @@ export class CppProperties {
204204
return new CppSettings(this.rootUri).defaultConfigurationProvider;
205205
}
206206

207+
public get CurrentMergeConfigurations(): boolean {
208+
if (this.CurrentConfiguration?.mergeConfigurations) {
209+
return this.CurrentConfiguration.mergeConfigurations;
210+
}
211+
return new CppSettings(this.rootUri).defaultMergeConfigurations;
212+
}
213+
214+
public get CurrentIncludePath(): string[] | undefined {
215+
if (this.CurrentConfiguration?.includePath) {
216+
return this.CurrentConfiguration.includePath;
217+
}
218+
return new CppSettings(this.rootUri).defaultIncludePath;
219+
}
220+
221+
public get CurrentDefines(): string[] | undefined {
222+
if (this.CurrentConfiguration?.defines) {
223+
return this.CurrentConfiguration.defines;
224+
}
225+
return new CppSettings(this.rootUri).defaultDefines;
226+
}
227+
228+
public get CurrentForcedInclude(): string[] | undefined {
229+
if (this.CurrentConfiguration?.forcedInclude) {
230+
return this.CurrentConfiguration.forcedInclude;
231+
}
232+
return new CppSettings(this.rootUri).defaultForcedInclude;
233+
}
234+
235+
public get CurrentBrowsePath(): string[] | undefined {
236+
if (this.CurrentConfiguration?.browse?.path) {
237+
return this.CurrentConfiguration.browse.path;
238+
}
239+
return new CppSettings(this.rootUri).defaultBrowsePath;
240+
}
241+
207242
public get ConfigurationNames(): string[] | undefined {
208243
const result: string[] = [];
209244
if (this.configurationJson) {

Extension/src/LanguageServer/settings.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ export class CppSettings extends Settings {
440440
public get defaultCStandard(): string | undefined { return this.getAsStringOrUndefined("default.cStandard"); }
441441
public get defaultCppStandard(): string | undefined { return this.getAsStringOrUndefined("default.cppStandard"); }
442442
public get defaultConfigurationProvider(): string | undefined { return changeBlankStringToUndefined(this.getAsStringOrUndefined("default.configurationProvider")); }
443-
public get defaultMergeConfigurations(): boolean | undefined { return this.getAsBooleanOrUndefined("default.mergeConfigurations"); }
443+
public get defaultMergeConfigurations(): boolean { return this.getAsBoolean("default.mergeConfigurations"); }
444444
public get defaultBrowsePath(): string[] | undefined { return this.getArrayOfStringsWithUndefinedDefault("default.browse.path"); }
445445
public get defaultDatabaseFilename(): string | undefined { return changeBlankStringToUndefined(this.getAsStringOrUndefined("default.browse.databaseFilename")); }
446446
public get defaultLimitSymbolsToIncludedHeaders(): boolean { return this.getAsBoolean("default.browse.limitSymbolsToIncludedHeaders"); }
@@ -569,21 +569,6 @@ export class CppSettings extends Settings {
569569
return undefined;
570570
}
571571

572-
// Returns the value of a setting as a boolean with proper type validation and checks for valid enum values while returning an undefined value if necessary.
573-
private getAsBooleanOrUndefined(settingName: string): boolean | undefined {
574-
const value: any = super.Section.get<any>(settingName);
575-
const setting = getRawSetting("C_Cpp." + settingName, true);
576-
if (setting.default !== undefined) {
577-
console.error(`Default value for ${settingName} is expected to be undefined.`);
578-
}
579-
580-
if (isBoolean(value)) {
581-
return value;
582-
}
583-
584-
return undefined;
585-
}
586-
587572
private isValidDefault(isValid: (x: any) => boolean, value: any, allowNull: boolean): boolean {
588573
return isValid(value) || (allowNull && value === null);
589574
}

Extension/src/common.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,3 +1810,21 @@ export function findExePathInArgs(args: CommandString[]): string | undefined {
18101810
export function getVsCodeVersion(): number[] {
18111811
return vscode.version.split('.').map(num => parseInt(num, undefined));
18121812
}
1813+
1814+
export function equals(array1: string[] | undefined, array2: string[] | undefined): boolean {
1815+
if (array1 === undefined && array2 === undefined) {
1816+
return true;
1817+
}
1818+
if (array1 === undefined || array2 === undefined) {
1819+
return false;
1820+
}
1821+
if (array1.length !== array2.length) {
1822+
return false;
1823+
}
1824+
for (let i: number = 0; i < array1.length; ++i) {
1825+
if (array1[i] !== array2[i]) {
1826+
return false;
1827+
}
1828+
}
1829+
return true;
1830+
}

Extension/ui/settings.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@
687687
<div class="section-title" data-loc-id="merge.configurations">Merge configurations</div>
688688
<div>
689689
<input type="checkbox" id="mergeConfigurations" style="vertical-align: middle; transform: scale(1.5)">
690-
<span data-loc-id="merge.configurations.description">When <code>true</code> (or checked), merge <code>includePath</code>, <code>defines</code>, <code>forcedInclude</code>, and <code>browse.path</code> with those received from the configuration provider. Changes to <code>mergeConfigurations</code> won't take effect until the the configuration provider resends the configuration.</span>
690+
<span data-loc-id="merge.configurations.description">When <code>true</code> (or checked), merge <code>includePath</code>, <code>defines</code>, <code>forcedInclude</code>, and <code>browse.path</code> with those received from the configuration provider.</span>
691691
</input>
692692
</div>
693693
</div>

0 commit comments

Comments
 (0)