Skip to content

Commit

Permalink
Set jsonc for c_cpp_properties.json. (#5911)
Browse files Browse the repository at this point in the history
Fix c_cpp_properties.json not opening as JSON with comments. Follow up to #5885
Fix the configuration UI disappearing when selection moves to the C/C++ or Log Diagnostics window, mentioned at #5822 .
Fix an unreported bug where the configuration UI wouldn't appear for non-cpp files that are active on startup (until the selection changed).
Add more more C/C++ related files to ShowConfigurations.
  • Loading branch information
sean-mcmanus authored Aug 6, 2020
1 parent a051c15 commit cd04d2a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions Extension/src/LanguageServer/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ function realActivation(): void {

disposables.push(vscode.workspace.onDidChangeConfiguration(onDidChangeSettings));
disposables.push(vscode.window.onDidChangeActiveTextEditor(onDidChangeActiveTextEditor));
ui.activeDocumentChanged(); // Handle already active documents (for non-cpp files that we don't register didOpen).
disposables.push(vscode.window.onDidChangeTextEditorSelection(onDidChangeTextEditorSelection));
disposables.push(vscode.window.onDidChangeVisibleTextEditors(onDidChangeVisibleTextEditors));

Expand Down
15 changes: 12 additions & 3 deletions Extension/src/LanguageServer/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,19 @@ export class UI {
} else {
const isCpp: boolean = (activeEditor.document.uri.scheme === "file" && (activeEditor.document.languageId === "cpp" || activeEditor.document.languageId === "c"));

// It's sometimes desirable to see the config and icons when making settings changes.
const isSettingsJson: boolean = ((activeEditor.document.fileName.endsWith("c_cpp_properties.json") || activeEditor.document.fileName.endsWith("settings.json")));
const isCppPropertiesJson: boolean = activeEditor.document.fileName.endsWith("c_cpp_properties.json");
if (isCppPropertiesJson) {
vscode.languages.setTextDocumentLanguage(activeEditor.document, "jsonc");
}

this.ShowConfiguration = isCpp || isSettingsJson;
// It's sometimes desirable to see the config and icons when making changes to files with C/C++-related content.
// TODO: Check some "AlwaysShow" setting here.
this.ShowConfiguration = isCpp || isCppPropertiesJson ||
activeEditor.document.uri.scheme === "output" ||
activeEditor.document.fileName.endsWith("settings.json") ||
activeEditor.document.fileName.endsWith("tasks.json") ||
activeEditor.document.fileName.endsWith("launch.json") ||
activeEditor.document.fileName.endsWith(".code-workspace");
}
}

Expand Down

0 comments on commit cd04d2a

Please sign in to comment.