From 49e987149c5d0b0620cc407bbc1161a60c46f4b9 Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Sun, 13 Feb 2022 12:10:00 -0800 Subject: [PATCH 1/6] Add setting for SwitchHeaderSource UI behavior headerSourcePaneJumping controls whether the SwitchHeaderSource command will jump to a different editor split if the destination file is already visible. --- Extension/package.json | 6 ++++++ Extension/package.nls.json | 1 + Extension/src/LanguageServer/client.ts | 3 +++ Extension/src/LanguageServer/extension.ts | 18 +++++++++++------- Extension/src/LanguageServer/settings.ts | 1 + 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Extension/package.json b/Extension/package.json index 43bd82680..eeb4bc850 100644 --- a/Extension/package.json +++ b/Extension/package.json @@ -2111,6 +2111,12 @@ "description": "%c_cpp.configuration.errorSquiggles.description%", "scope": "resource" }, + "C_Cpp.headerSourcePaneJumping": { + "type": "boolean", + "default": true, + "description": "%c_cpp.configuration.headerSourcePaneJumping.description%", + "scope": "resource" + }, "C_Cpp.dimInactiveRegions": { "type": "boolean", "default": true, diff --git a/Extension/package.nls.json b/Extension/package.nls.json index ef572d8ce..96afd881c 100644 --- a/Extension/package.nls.json +++ b/Extension/package.nls.json @@ -153,6 +153,7 @@ "c_cpp.configuration.autocomplete.default.description": "Uses the active IntelliSense engine.", "c_cpp.configuration.autocomplete.disabled.description": "Uses the word-based completion provided by Visual Studio Code.", "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.", + "c_cpp.configuration.headerSourcePaneJumping.description": "Controls whether or not the SwitchHeaderSource command will jump to a different editor split if the destination file is already visible.", "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.", "c_cpp.configuration.inactiveRegionOpacity.markdownDescription": { "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.", "comment": [ "Markdown text between `` should not be translated or localized (they represent literal text) and the capitalization, spacing, and punctuation (including the ``) should not be altered." ] }, "c_cpp.configuration.inactiveRegionForegroundColor.description": "Controls the font coloring of inactive preprocessor blocks. Input is in the form a hexadecimal color code or a valid Theme Color. If not set, this defaults to the syntax coloring scheme of the editor. This setting only applies when inactive region dimming is enabled.", diff --git a/Extension/src/LanguageServer/client.ts b/Extension/src/LanguageServer/client.ts index 4edb5cbe9..ca53b7fd4 100644 --- a/Extension/src/LanguageServer/client.ts +++ b/Extension/src/LanguageServer/client.ts @@ -1109,6 +1109,7 @@ export class DefaultClient implements Client { const settings_intelliSenseEngine: (string | undefined)[] = []; const settings_intelliSenseEngineFallback: (string | undefined)[] = []; const settings_errorSquiggles: (string | undefined)[] = []; + const settings_headerSourcePaneJumping: (boolean | undefined)[] = []; const settings_dimInactiveRegions: boolean[] = []; const settings_enhancedColorization: string[] = []; const settings_suggestSnippets: (boolean | undefined)[] = []; @@ -1274,6 +1275,7 @@ export class DefaultClient implements Client { settings_intelliSenseEngine.push(setting.intelliSenseEngine); settings_intelliSenseEngineFallback.push(setting.intelliSenseEngineFallback); settings_errorSquiggles.push(setting.errorSquiggles); + settings_headerSourcePaneJumping.push(setting.headerSourcePaneJumping); settings_dimInactiveRegions.push(setting.dimInactiveRegions); settings_enhancedColorization.push(workspaceSettings.enhancedColorization ? "Enabled" : "Disabled"); settings_suggestSnippets.push(setting.suggestSnippets); @@ -1456,6 +1458,7 @@ export class DefaultClient implements Client { autocomplete: settings_autocomplete, autocompleteAddParentheses: settings_autocompleteAddParentheses, errorSquiggles: settings_errorSquiggles, + headerSourcePaneJumping: settings_headerSourcePaneJumping, dimInactiveRegions: settings_dimInactiveRegions, enhancedColorization: settings_enhancedColorization, suggestSnippets: settings_suggestSnippets, diff --git a/Extension/src/LanguageServer/extension.ts b/Extension/src/LanguageServer/extension.ts index b734d8a3f..372e0babc 100644 --- a/Extension/src/LanguageServer/extension.ts +++ b/Extension/src/LanguageServer/extension.ts @@ -484,14 +484,18 @@ async function onSwitchHeaderSource(): Promise { } }); const document: vscode.TextDocument = await vscode.workspace.openTextDocument(targetFileName); + const settings: CppSettings = new CppSettings(); let foundEditor: boolean = false; - // If the document is already visible in another column, open it there. - vscode.window.visibleTextEditors.forEach((editor, index, array) => { - if (editor.document === document && !foundEditor) { - foundEditor = true; - vscode.window.showTextDocument(document, editor.viewColumn); - } - }); + if (settings.headerSourcePaneJumping) { + // If the document is already visible in another column, open it there. + vscode.window.visibleTextEditors.forEach((editor, index, array) => { + if (editor.document === document && !foundEditor) { + foundEditor = true; + vscode.window.showTextDocument(document, editor.viewColumn); + } + }); + } + if (!foundEditor) { vscode.window.showTextDocument(document); } diff --git a/Extension/src/LanguageServer/settings.ts b/Extension/src/LanguageServer/settings.ts index 33022ca96..59bcdd3b5 100644 --- a/Extension/src/LanguageServer/settings.ts +++ b/Extension/src/LanguageServer/settings.ts @@ -197,6 +197,7 @@ export class CppSettings extends Settings { public get intelliSenseMemoryLimit(): number | undefined { return super.Section.get("intelliSenseMemoryLimit"); } public get intelliSenseUpdateDelay(): number | undefined { return super.Section.get("intelliSenseUpdateDelay"); } public get errorSquiggles(): string | undefined { return super.Section.get("errorSquiggles"); } + public get headerSourcePaneJumping(): boolean | undefined { return super.Section.get("headerSourcePaneJumping"); } public get inactiveRegionOpacity(): number | undefined { return super.Section.get("inactiveRegionOpacity"); } public get inactiveRegionForegroundColor(): string | undefined { return super.Section.get("inactiveRegionForegroundColor"); } public get inactiveRegionBackgroundColor(): string | undefined { return super.Section.get("inactiveRegionBackgroundColor"); } From 378522deb5515acea314f33abdb97f8c7c5342fc Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Tue, 15 Feb 2022 13:17:36 -0800 Subject: [PATCH 2/6] PR feedback: revert unneeded changes to client.ts --- Extension/src/LanguageServer/client.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/Extension/src/LanguageServer/client.ts b/Extension/src/LanguageServer/client.ts index ca53b7fd4..4edb5cbe9 100644 --- a/Extension/src/LanguageServer/client.ts +++ b/Extension/src/LanguageServer/client.ts @@ -1109,7 +1109,6 @@ export class DefaultClient implements Client { const settings_intelliSenseEngine: (string | undefined)[] = []; const settings_intelliSenseEngineFallback: (string | undefined)[] = []; const settings_errorSquiggles: (string | undefined)[] = []; - const settings_headerSourcePaneJumping: (boolean | undefined)[] = []; const settings_dimInactiveRegions: boolean[] = []; const settings_enhancedColorization: string[] = []; const settings_suggestSnippets: (boolean | undefined)[] = []; @@ -1275,7 +1274,6 @@ export class DefaultClient implements Client { settings_intelliSenseEngine.push(setting.intelliSenseEngine); settings_intelliSenseEngineFallback.push(setting.intelliSenseEngineFallback); settings_errorSquiggles.push(setting.errorSquiggles); - settings_headerSourcePaneJumping.push(setting.headerSourcePaneJumping); settings_dimInactiveRegions.push(setting.dimInactiveRegions); settings_enhancedColorization.push(workspaceSettings.enhancedColorization ? "Enabled" : "Disabled"); settings_suggestSnippets.push(setting.suggestSnippets); @@ -1458,7 +1456,6 @@ export class DefaultClient implements Client { autocomplete: settings_autocomplete, autocompleteAddParentheses: settings_autocompleteAddParentheses, errorSquiggles: settings_errorSquiggles, - headerSourcePaneJumping: settings_headerSourcePaneJumping, dimInactiveRegions: settings_dimInactiveRegions, enhancedColorization: settings_enhancedColorization, suggestSnippets: settings_suggestSnippets, From e858ddee0a026a10c6b2695d63777ecbe660e7b0 Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Tue, 15 Feb 2022 14:50:19 -0800 Subject: [PATCH 3/6] PR feedback: fix error in package.json --- Extension/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Extension/package.json b/Extension/package.json index eeb4bc850..af838e5c4 100644 --- a/Extension/package.json +++ b/Extension/package.json @@ -2115,7 +2115,7 @@ "type": "boolean", "default": true, "description": "%c_cpp.configuration.headerSourcePaneJumping.description%", - "scope": "resource" + "scope": "application" }, "C_Cpp.dimInactiveRegions": { "type": "boolean", From 0c0d74b3f0f46212bd5501b2365ca1b91c727eca Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Thu, 17 Feb 2022 15:41:31 -0800 Subject: [PATCH 4/6] Use workbench.editor.revealIfOpen --- Extension/package.json | 6 ------ Extension/package.nls.json | 1 - Extension/src/LanguageServer/extension.ts | 4 ++-- Extension/src/LanguageServer/settings.ts | 1 - 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/Extension/package.json b/Extension/package.json index 4817e4f46..424517cff 100644 --- a/Extension/package.json +++ b/Extension/package.json @@ -2111,12 +2111,6 @@ "description": "%c_cpp.configuration.errorSquiggles.description%", "scope": "resource" }, - "C_Cpp.headerSourcePaneJumping": { - "type": "boolean", - "default": true, - "description": "%c_cpp.configuration.headerSourcePaneJumping.description%", - "scope": "application" - }, "C_Cpp.dimInactiveRegions": { "type": "boolean", "default": true, diff --git a/Extension/package.nls.json b/Extension/package.nls.json index f402841d2..9e8ac51db 100644 --- a/Extension/package.nls.json +++ b/Extension/package.nls.json @@ -153,7 +153,6 @@ "c_cpp.configuration.autocomplete.default.description": "Uses the active IntelliSense engine.", "c_cpp.configuration.autocomplete.disabled.description": "Uses the word-based completion provided by Visual Studio Code.", "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.", - "c_cpp.configuration.headerSourcePaneJumping.description": "Controls whether or not the SwitchHeaderSource command will jump to a different editor split if the destination file is already visible.", "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.", "c_cpp.configuration.inactiveRegionOpacity.markdownDescription": { "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.", "comment": [ "Markdown text between `` should not be translated or localized (they represent literal text) and the capitalization, spacing, and punctuation (including the ``) should not be altered." ] }, "c_cpp.configuration.inactiveRegionForegroundColor.description": "Controls the font coloring of inactive preprocessor blocks. Input is in the form a hexadecimal color code or a valid Theme Color. If not set, this defaults to the syntax coloring scheme of the editor. This setting only applies when inactive region dimming is enabled.", diff --git a/Extension/src/LanguageServer/extension.ts b/Extension/src/LanguageServer/extension.ts index 372e0babc..26f342e74 100644 --- a/Extension/src/LanguageServer/extension.ts +++ b/Extension/src/LanguageServer/extension.ts @@ -484,9 +484,9 @@ async function onSwitchHeaderSource(): Promise { } }); const document: vscode.TextDocument = await vscode.workspace.openTextDocument(targetFileName); - const settings: CppSettings = new CppSettings(); + const workbenchConfig = vscode.workspace.getConfiguration("workbench"); let foundEditor: boolean = false; - if (settings.headerSourcePaneJumping) { + if (workbenchConfig.get("editor.revealIfOpen")) { // If the document is already visible in another column, open it there. vscode.window.visibleTextEditors.forEach((editor, index, array) => { if (editor.document === document && !foundEditor) { diff --git a/Extension/src/LanguageServer/settings.ts b/Extension/src/LanguageServer/settings.ts index 8b10b8df1..6860e2e21 100644 --- a/Extension/src/LanguageServer/settings.ts +++ b/Extension/src/LanguageServer/settings.ts @@ -197,7 +197,6 @@ export class CppSettings extends Settings { public get intelliSenseMemoryLimit(): number | undefined { return super.Section.get("intelliSenseMemoryLimit"); } public get intelliSenseUpdateDelay(): number | undefined { return super.Section.get("intelliSenseUpdateDelay"); } public get errorSquiggles(): string | undefined { return super.Section.get("errorSquiggles"); } - public get headerSourcePaneJumping(): boolean | undefined { return super.Section.get("headerSourcePaneJumping"); } public get inactiveRegionOpacity(): number | undefined { return super.Section.get("inactiveRegionOpacity"); } public get inactiveRegionForegroundColor(): string | undefined { return super.Section.get("inactiveRegionForegroundColor"); } public get inactiveRegionBackgroundColor(): string | undefined { return super.Section.get("inactiveRegionBackgroundColor"); } From 4704a7b19b0ef092393871e1ba9e9666198dc272 Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Fri, 18 Feb 2022 08:14:20 -0800 Subject: [PATCH 5/6] PR feedback: consolidate lambda --- Extension/src/LanguageServer/extension.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Extension/src/LanguageServer/extension.ts b/Extension/src/LanguageServer/extension.ts index 26f342e74..f9b6ea348 100644 --- a/Extension/src/LanguageServer/extension.ts +++ b/Extension/src/LanguageServer/extension.ts @@ -488,7 +488,7 @@ async function onSwitchHeaderSource(): Promise { let foundEditor: boolean = false; if (workbenchConfig.get("editor.revealIfOpen")) { // If the document is already visible in another column, open it there. - vscode.window.visibleTextEditors.forEach((editor, index, array) => { + vscode.window.visibleTextEditors.forEach(editor => { if (editor.document === document && !foundEditor) { foundEditor = true; vscode.window.showTextDocument(document, editor.viewColumn); From 572a10ce4d53a0e750330a9c5970e40cc90e1b63 Mon Sep 17 00:00:00 2001 From: Joel Smith Date: Fri, 18 Feb 2022 08:20:06 -0800 Subject: [PATCH 6/6] Fix build: add typedef for workbenchConfig --- Extension/src/LanguageServer/extension.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Extension/src/LanguageServer/extension.ts b/Extension/src/LanguageServer/extension.ts index f9b6ea348..55963e0de 100644 --- a/Extension/src/LanguageServer/extension.ts +++ b/Extension/src/LanguageServer/extension.ts @@ -484,7 +484,7 @@ async function onSwitchHeaderSource(): Promise { } }); const document: vscode.TextDocument = await vscode.workspace.openTextDocument(targetFileName); - const workbenchConfig = vscode.workspace.getConfiguration("workbench"); + const workbenchConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("workbench"); let foundEditor: boolean = false; if (workbenchConfig.get("editor.revealIfOpen")) { // If the document is already visible in another column, open it there.