Skip to content

Commit a6c6c7e

Browse files
authored
Add a setting to manage inactive region colorization (#1604)
1 parent 9937753 commit a6c6c7e

File tree

7 files changed

+43
-9
lines changed

7 files changed

+43
-9
lines changed

Extension/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# C/C++ for Visual Studio Code Change Log
22

33
## Version 0.15.1: March 2018
4+
* Enable autocomplete for local and global scopes. [#13](https://github.com/Microsoft/vscode-cpptools/issues/13)
45
* Support additional multiline comment patterns. [#1100](https://github.com/Microsoft/vscode-cpptools/issues/1100),[#1539](https://github.com/Microsoft/vscode-cpptools/issues/1539)
56
* Added new setting: `C_Cpp.commentContinuationPatterns`
7+
* Add a setting to disable inactive region highlighting. [#1592](https://github.com/Microsoft/vscode-cpptools/issues/1592)
68

79
## Version 0.15.0: February 15, 2018
810
* Add colorization for inactive regions. [#1466](https://github.com/Microsoft/vscode-cpptools/issues/1466)

Extension/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@
139139
"description": "Controls whether suspected compile errors detected by the IntelliSense engine will be reported back to the editor. Warnings about #includes that could not be located will always be reported to the editor. This setting is ignored by the Tag Parser engine.",
140140
"scope": "resource"
141141
},
142+
"C_Cpp.dimInactiveRegions": {
143+
"type": "boolean",
144+
"default": true,
145+
"description": "Controls whether inactive preprocessor blocks are colored differently than active code. This setting is ignored by the Tag Parser engine.",
146+
"scope": "resource"
147+
},
142148
"C_Cpp.formatting": {
143149
"type": "string",
144150
"enum": [
@@ -267,6 +273,11 @@
267273
"title": "Toggle IntelliSense Engine Fallback on Include Errors",
268274
"category": "C/Cpp"
269275
},
276+
{
277+
"command": "C_Cpp.ToggleDimInactiveRegions",
278+
"title": "Toggle Inactive Region Colorization",
279+
"category": "C/Cpp"
280+
},
270281
{
271282
"command": "workbench.action.gotoSymbol",
272283
"title": "Go to Symbol in File..."

Extension/src/LanguageServer/client.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ class DefaultClient implements Client {
394394
intelliSenseEngineFallback: settings.intelliSenseEngineFallback,
395395
autocomplete: settings.autoComplete,
396396
errorSquiggles: settings.errorSquiggles,
397+
dimInactiveRegions: settings.dimInactiveRegions,
397398
loggingLevel: settings.loggingLevel,
398399
workspaceParsingPriority: settings.workspaceParsingPriority,
399400
exclusionPolicy: settings.exclusionPolicy
@@ -450,11 +451,14 @@ class DefaultClient implements Client {
450451
}
451452

452453
public onDidChangeVisibleTextEditors(editors: vscode.TextEditor[]): void {
453-
//Apply text decorations to inactive regions
454-
for (let e of editors) {
455-
let valuePair: DecorationRangesPair = this.inactiveRegionsDecorations.get(e.document.uri.toString());
456-
if (valuePair) {
457-
e.setDecorations(valuePair.decoration, valuePair.ranges); // VSCode clears the decorations when the text editor becomes invisible
454+
let settings: CppSettings = new CppSettings(this.RootUri);
455+
if (settings.dimInactiveRegions) {
456+
//Apply text decorations to inactive regions
457+
for (let e of editors) {
458+
let valuePair: DecorationRangesPair = this.inactiveRegionsDecorations.get(e.document.uri.toString());
459+
if (valuePair) {
460+
e.setDecorations(valuePair.decoration, valuePair.ranges); // VSCode clears the decorations when the text editor becomes invisible
461+
}
458462
}
459463
}
460464
}
@@ -729,10 +733,13 @@ class DefaultClient implements Client {
729733
this.inactiveRegionsDecorations.set(params.uri, toInsert);
730734
}
731735

732-
// Apply the decorations to all *visible* text editors
733-
let editors: vscode.TextEditor[] = vscode.window.visibleTextEditors.filter(e => e.document.uri.toString() === params.uri);
734-
for (let e of editors) {
735-
e.setDecorations(decoration, ranges);
736+
let settings: CppSettings = new CppSettings(this.RootUri);
737+
if (settings.dimInactiveRegions) {
738+
// Apply the decorations to all *visible* text editors
739+
let editors: vscode.TextEditor[] = vscode.window.visibleTextEditors.filter(e => e.document.uri.toString() === params.uri);
740+
for (let e of editors) {
741+
e.setDecorations(decoration, ranges);
742+
}
736743
}
737744
}
738745

Extension/src/LanguageServer/extension.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ function registerCommands(): void {
193193
disposables.push(vscode.commands.registerCommand('C_Cpp.AddToIncludePath', onAddToIncludePath));
194194
disposables.push(vscode.commands.registerCommand('C_Cpp.ToggleErrorSquiggles', onToggleSquiggles));
195195
disposables.push(vscode.commands.registerCommand('C_Cpp.ToggleIncludeFallback', onToggleIncludeFallback));
196+
disposables.push(vscode.commands.registerCommand('C_Cpp.ToggleDimInactiveRegions', onToggleDimInactiveRegions));
196197
disposables.push(vscode.commands.registerCommand('C_Cpp.ShowReleaseNotes', onShowReleaseNotes));
197198
disposables.push(vscode.commands.registerCommand('C_Cpp.PauseParsing', onPauseParsing));
198199
disposables.push(vscode.commands.registerCommand('C_Cpp.ResumeParsing', onResumeParsing));
@@ -335,6 +336,13 @@ function onToggleIncludeFallback(): void {
335336
settings.toggleSetting("intelliSenseEngineFallback", "Enabled", "Disabled");
336337
}
337338

339+
function onToggleDimInactiveRegions(): void {
340+
onActivationEvent();
341+
// This only applies to the active client.
342+
let settings: CppSettings = new CppSettings(clients.ActiveClient.RootUri);
343+
settings.update<boolean>("dimInactiveRegions", !settings.dimInactiveRegions);
344+
}
345+
338346
function onShowReleaseNotes(): void {
339347
onActivationEvent();
340348
util.showReleaseNotes();

Extension/src/LanguageServer/settings.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export class CppSettings extends Settings {
3939
public get intelliSenseEngine(): string { return super.Section.get<string>("intelliSenseEngine"); }
4040
public get intelliSenseEngineFallback(): string { return super.Section.get<string>("intelliSenseEngineFallback"); }
4141
public get errorSquiggles(): string { return super.Section.get<string>("errorSquiggles"); }
42+
public get dimInactiveRegions(): boolean { return super.Section.get<boolean>("dimInactiveRegions"); }
4243
public get autoComplete(): string { return super.Section.get<string>("autocomplete"); }
4344
public get loggingLevel(): string { return super.Section.get<string>("loggingLevel"); }
4445
public get navigationLength(): number { return super.Section.get<number>("navigation.length", 60); }
@@ -51,6 +52,9 @@ export class CppSettings extends Settings {
5152
let value: string = super.Section.get<string>(name);
5253
super.Section.update(name, value === value1 ? value2 : value1, getTarget());
5354
}
55+
public update<T>(name: string, value: T): void {
56+
super.Section.update(name, value);
57+
}
5458
}
5559

5660
export class OtherSettings {

Extension/src/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class TemporaryCommandRegistrar {
2121
"C_Cpp.PeekDeclaration",
2222
"C_Cpp.ToggleErrorSquiggles",
2323
"C_Cpp.ToggleIncludeFallback",
24+
"C_Cpp.ToggleDimInactiveRegions",
2425
"C_Cpp.ShowReleaseNotes",
2526
"C_Cpp.ResetDatabase",
2627
"C_Cpp.PauseParsing",

Extension/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ function rewriteManifest(): Promise<void> {
300300
"onCommand:C_Cpp.PeekDeclaration",
301301
"onCommand:C_Cpp.ToggleErrorSquiggles",
302302
"onCommand:C_Cpp.ToggleIncludeFallback",
303+
"onCommand:C_Cpp.ToggleDimInactiveRegions",
303304
"onCommand:C_Cpp.ShowReleaseNotes",
304305
"onCommand:C_Cpp.ResetDatabase",
305306
"onCommand:C_Cpp.PauseParsing",

0 commit comments

Comments
 (0)