Skip to content

Commit 0da8520

Browse files
committed
Avoid overloading dimInactiveRegions setting. (requires native side changes)
1 parent 50cf1ff commit 0da8520

6 files changed

Lines changed: 36 additions & 7 deletions

File tree

‎Extension/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@
10751075
"C_Cpp.autoFoldInactiveRegions": {
10761076
"type": "boolean",
10771077
"default": false,
1078-
"description": "%c_cpp.configuration.autoFoldInactiveRegions.description%",
1078+
"markdownDescription": "%c_cpp.configuration.autoFoldInactiveRegions.description%",
10791079
"scope": "resource"
10801080
},
10811081
"C_Cpp.inactiveRegionOpacity": {

‎Extension/package.nls.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@
488488
"c_cpp.configuration.autocomplete.disabled.description": "Uses the word-based completion provided by Visual Studio Code.",
489489
"c_cpp.configuration.errorSquiggles.description": "Controls whether suspected compile errors detected by the IntelliSense engine will be reported back to the editor. It also controls whether code analysis warnings are reported if includes can't be found. This setting is ignored by the Tag Parser engine.",
490490
"c_cpp.configuration.dimInactiveRegions.description": "Controls whether inactive preprocessor blocks are colored differently than active code. This setting has no effect if IntelliSense is disabled or if using the Default High Contrast theme.",
491-
"c_cpp.configuration.autoFoldInactiveRegions.description": "Controls whether inactive preprocessor blocks are automatically folded when a file is opened. This setting requires IntelliSense and code folding to be enabled.",
491+
"c_cpp.configuration.autoFoldInactiveRegions.description": "Controls whether inactive preprocessor blocks are automatically folded when a file is opened. This setting only applies when `#C_Cpp.intelliSenseEngine#` is `default` and `#C_Cpp.codeFolding#` is `enabled`.",
492492
"c_cpp.configuration.inactiveRegionOpacity.markdownDescription": {
493493
"message": "Controls the opacity of inactive preprocessor blocks. Scales between `0.1` and `1.0`. This setting only applies when inactive region dimming is enabled.",
494494
"comment": [

‎Extension/src/LanguageServer/client.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,7 @@ export class DefaultClient implements Client {
887887
private inactiveRegionsDecorations = new Map<string, DecorationRangesPair>();
888888
private inactiveRegions = new InactiveRegionStore();
889889
private pendingInactiveRegionFoldingOperations = new WeakMap<vscode.TextEditor, InactiveRegionFoldingOperation>();
890+
private inactiveRegionReportingEnabled: boolean;
890891
private settingsTracker: SettingsTracker;
891892
private loggingLevel: number = 1;
892893
private configurationProvider?: string;
@@ -1328,6 +1329,7 @@ export class DefaultClient implements Client {
13281329
}
13291330

13301331
const rootUri: vscode.Uri | undefined = this.RootUri;
1332+
this.inactiveRegionReportingEnabled = new CppSettings(rootUri).inactiveRegionReportingEnabled;
13311333
this.settingsTracker = new SettingsTracker(rootUri);
13321334

13331335
try {
@@ -1477,8 +1479,8 @@ export class DefaultClient implements Client {
14771479
intelliSenseCachePath: util.resolveCachePath(settings.intelliSenseCachePath, this.AdditionalEnvironment),
14781480
intelliSenseCacheSize: settings.intelliSenseCacheSize,
14791481
intelliSenseMemoryLimit: settings.intelliSenseMemoryLimit,
1480-
// Native uses this flag to decide whether to report inactive ranges.
1481-
dimInactiveRegions: settings.dimInactiveRegions || settings.autoFoldInactiveRegions || settings.codeFolding,
1482+
dimInactiveRegions: settings.dimInactiveRegions,
1483+
codeFolding: settings.codeFolding,
14821484
suggestSnippets: settings.suggestSnippets,
14831485
legacyCompilerArgsBehavior: settings.legacyCompilerArgsBehavior,
14841486
defaultSystemIncludePath: settings.defaultSystemIncludePath,
@@ -1851,6 +1853,11 @@ export class DefaultClient implements Client {
18511853
await this.ready;
18521854

18531855
if (Object.keys(changedSettings).length > 0) {
1856+
const inactiveRegionReportingEnabled: boolean = new CppSettings(this.RootUri).inactiveRegionReportingEnabled;
1857+
if (inactiveRegionReportingEnabled !== this.inactiveRegionReportingEnabled) {
1858+
this.inactiveRegionReportingEnabled = inactiveRegionReportingEnabled;
1859+
this.inactiveRegions.clear();
1860+
}
18541861
if (this === defaultClient) {
18551862
if (changedSettings.commentContinuationPatterns2 !== undefined) {
18561863
updateLanguageConfigurations();
@@ -3044,8 +3051,7 @@ export class DefaultClient implements Client {
30443051
}
30453052

30463053
const settings: CppSettings = new CppSettings(editor.document.uri);
3047-
const autoFold: boolean = settings.autoFoldInactiveRegions && settings.codeFolding
3048-
&& !DefaultClient.autoFoldedEditors.has(editor);
3054+
const autoFold: boolean = settings.autoFoldInactiveRegions && !DefaultClient.autoFoldedEditors.has(editor);
30493055
const pendingOperation: InactiveRegionFoldingOperation | undefined =
30503056
this.pendingInactiveRegionFoldingOperations.get(editor);
30513057
const operation: InactiveRegionFoldingOperation | undefined = pendingOperation ?? (autoFold ? 'fold' : undefined);
@@ -3065,6 +3071,7 @@ export class DefaultClient implements Client {
30653071
}
30663072

30673073
try {
3074+
await this.languageClient.refreshFoldingRanges(editor.document);
30683075
await vscode.commands.executeCommand(`editor.${operation}`, {
30693076
selectionLines,
30703077
direction: 'down'

‎Extension/src/LanguageServer/inactiveRegions.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ export class InactiveRegionStore {
4343
this.regionSets.forEach((regionSet, uri) => callback(regionSet.regions, uri));
4444
}
4545

46+
public clear(): void {
47+
this.regionSets.clear();
48+
}
49+
4650
public delete(uri: string): void {
4751
this.regionSets.delete(uri);
4852
}

‎Extension/src/LanguageServer/settings.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export interface WorkspaceFolderSettingsParams {
4949
intelliSenseCacheSize: number;
5050
intelliSenseMemoryLimit: number;
5151
dimInactiveRegions: boolean;
52+
codeFolding: boolean;
5253
suggestSnippets: boolean;
5354
legacyCompilerArgsBehavior: boolean;
5455
defaultSystemIncludePath: string[] | undefined;
@@ -377,7 +378,15 @@ export class CppSettings extends Settings {
377378
public get inactiveRegionOpacity(): number { return this.getAsNumber("inactiveRegionOpacity"); }
378379
public get inactiveRegionForegroundColor(): string | undefined { return changeBlankStringToUndefined(this.getAsStringOrUndefined("inactiveRegionForegroundColor")); }
379380
public get inactiveRegionBackgroundColor(): string | undefined { return changeBlankStringToUndefined(this.getAsStringOrUndefined("inactiveRegionBackgroundColor")); }
380-
public get autoFoldInactiveRegions(): boolean { return this.getAsBoolean("autoFoldInactiveRegions"); }
381+
public get autoFoldInactiveRegions(): boolean {
382+
return this.getAsBoolean("autoFoldInactiveRegions")
383+
&& this.codeFolding
384+
&& this.intelliSenseEngine.toLowerCase() === "default";
385+
}
386+
public get inactiveRegionReportingEnabled(): boolean {
387+
return this.dimInactiveRegions
388+
|| (this.codeFolding && this.intelliSenseEngine.toLowerCase() === "default");
389+
}
381390
public get autocomplete(): string { return this.getAsString("autocomplete"); }
382391
public get autocompleteAddParentheses(): boolean { return this.getAsBoolean("autocompleteAddParentheses"); }
383392
public get loggingLevel(): string { return this.getAsString("loggingLevel"); }

‎Extension/test/unit/inactiveRegions.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ suite("InactiveRegionStore", () => {
6060
assert.deepStrictEqual(entries, [[uri, [firstRegion, secondRegion]]]);
6161
});
6262

63+
test("clears all cached regions", () => {
64+
const store: InactiveRegionStore = new InactiveRegionStore();
65+
store.update(uri, [firstRegion], true, true);
66+
67+
store.clear();
68+
69+
assert.strictEqual(store.getComplete(uri), undefined);
70+
});
71+
6372
test("returns sorted unique start lines", () => {
6473
assert.deepStrictEqual(getInactiveRegionStartLines([secondRegion, firstRegion, secondRegion]), [2, 8]);
6574
});

0 commit comments

Comments
 (0)