Skip to content

Commit febb880

Browse files
authored
Fix launch.json creation with intelliSenseEngine Disabled. (#3612)
* Fix launch.json creation with intelliSenseEngine Disabled.
1 parent d1c344b commit febb880

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Extension/src/LanguageServer/extension.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ let buildInfoCache: BuildInfo | null = null;
4242
const taskSourceStr: string = "C/C++";
4343
const cppInstallVsixStr: string = 'C/C++: Install vsix -- ';
4444
let taskProvider: vscode.Disposable;
45+
const intelliSenseDisabledError: string = "Do not activate the extension when IntelliSense is disabled.";
4546

4647
/**
4748
* activate: set up the extension for language services
@@ -150,7 +151,15 @@ export async function getBuildTasks(returnComplerPath: boolean): Promise<vscode.
150151
// for the active file, remove duplicate compiler names, then finally add the user's compilerPath setting.
151152
let compilerPaths: string[];
152153
const isWindows: boolean = os.platform() === 'win32';
153-
const activeClient: Client = getActiveClient();
154+
let activeClient: Client;
155+
try {
156+
activeClient = getActiveClient();
157+
} catch (e) {
158+
if (!e || e.message !== intelliSenseDisabledError) {
159+
console.error("Unknown error calling getActiveClient().");
160+
}
161+
return []; // Language service features may be disabled.
162+
}
154163
let userCompilerPath: string = await activeClient.getCompilerPath();
155164
if (userCompilerPath) {
156165
userCompilerPath = userCompilerPath.trim();
@@ -280,7 +289,7 @@ function onActivationEvent(): void {
280289

281290
function realActivation(): void {
282291
if (new CppSettings().intelliSenseEngine === "Disabled") {
283-
throw new Error("Do not activate the extension when IntelliSense is disabled.");
292+
throw new Error(intelliSenseDisabledError);
284293
} else {
285294
console.log("activating extension");
286295
let checkForConflictingExtensions: PersistentState<boolean> = new PersistentState<boolean>("CPP." + util.packageJson.version + ".checkForConflictingExtensions", true);

0 commit comments

Comments
 (0)