Skip to content

Commit c4aac33

Browse files
authored
Fix activation failure when c_cpp_properties.json can't be opened. (#13832)
* Fix activation failure when c_cpp_properties.json can't be opened.
1 parent a322554 commit c4aac33

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Extension/src/main.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,15 @@ export async function activate(context: vscode.ExtensionContext): Promise<CppToo
125125
for (let i: number = 0; i < vscode.workspace.workspaceFolders.length; ++i) {
126126
const config: string = path.join(vscode.workspace.workspaceFolders[i].uri.fsPath, ".vscode/c_cpp_properties.json");
127127
if (await util.checkFileExists(config)) {
128-
const doc: vscode.TextDocument = await vscode.workspace.openTextDocument(config);
129-
void vscode.languages.setTextDocumentLanguage(doc, "jsonc");
130-
util.setWorkspaceIsCpp();
128+
try {
129+
const doc: vscode.TextDocument = await vscode.workspace.openTextDocument(config);
130+
void vscode.languages.setTextDocumentLanguage(doc, "jsonc");
131+
util.setWorkspaceIsCpp();
132+
} catch (err) {
133+
// The c_cpp_properties.json might not be openable (e.g. an executable).
134+
// Catching the exception prevents our extension activation from failing.
135+
// VS Code itself will report an error message.
136+
}
131137
}
132138
}
133139
}

0 commit comments

Comments
 (0)