Skip to content

Commit a4075e3

Browse files
authored
Merge pull request #7037 from dibarbet/intellicode_activation_failure
Gracefully handle failures activating the intellicode extension
2 parents 06cacb2 + b75b82e commit a4075e3

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

l10n/bundle.l10n.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@
135135
"Choose": "Choose",
136136
"Choose and set default": "Choose and set default",
137137
"Do not load any": "Do not load any",
138+
"IntelliCode features will not be available, {0} failed to activate.": "IntelliCode features will not be available, {0} failed to activate.",
139+
"Go to output": "Go to output",
140+
"Suppress notification": "Suppress notification",
138141
"Restore {0}": "Restore {0}",
139142
"Restore already in progress": "Restore already in progress",
140143
"Restore": "Restore",

src/lsptoolshost/roslynLanguageServer.ts

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,8 @@ export class RoslynLanguageServer {
529529
if (csharpDevkitIntelliCodeExtension) {
530530
_channel.appendLine('Activating C# + C# Dev Kit + C# IntelliCode...');
531531
const csharpDevkitIntelliCodeArgs = await this.getCSharpDevkitIntelliCodeExportArgs(
532-
csharpDevkitIntelliCodeExtension
532+
csharpDevkitIntelliCodeExtension,
533+
context
533534
);
534535
args = args.concat(csharpDevkitIntelliCodeArgs);
535536
} else {
@@ -822,14 +823,48 @@ export class RoslynLanguageServer {
822823
}
823824

824825
private static async getCSharpDevkitIntelliCodeExportArgs(
825-
csharpDevkitIntelliCodeExtension: vscode.Extension<CSharpIntelliCodeExports>
826+
csharpDevkitIntelliCodeExtension: vscode.Extension<CSharpIntelliCodeExports>,
827+
extensionContext: vscode.ExtensionContext
826828
): Promise<string[]> {
827-
const exports = await csharpDevkitIntelliCodeExtension.activate();
829+
try {
830+
const exports = await csharpDevkitIntelliCodeExtension.activate();
831+
832+
const starredCompletionComponentPath = exports.components['@vsintellicode/starred-suggestions-csharp'];
833+
834+
const csharpIntelliCodeArgs: string[] = [
835+
'--starredCompletionComponentPath',
836+
starredCompletionComponentPath,
837+
];
838+
return csharpIntelliCodeArgs;
839+
} catch (e) {
840+
_channel.appendLine(`Activation of ${csharpDevkitIntelliCodeExtensionId} failed`);
841+
_channel.appendLine(e instanceof Error ? e.message : (e as string));
842+
if (e instanceof Error && e.stack) {
843+
_channel.appendLine(e.stack);
844+
}
845+
846+
const stateKey = 'disableIntellicodeFailedPopup';
847+
if (extensionContext.globalState.get(stateKey) === true) {
848+
return [];
849+
}
828850

829-
const starredCompletionComponentPath = exports.components['@vsintellicode/starred-suggestions-csharp'];
851+
const message = vscode.l10n.t(
852+
'IntelliCode features will not be available, {0} failed to activate.',
853+
csharpDevkitIntelliCodeExtensionId
854+
);
855+
const showOutput = vscode.l10n.t('Go to output');
856+
const suppressNotification = vscode.l10n.t('Suppress notification');
857+
// Buttons are shown in right-to-left order, with a close button to the right of everything;
858+
vscode.window.showErrorMessage(message, showOutput, suppressNotification).then((value) => {
859+
if (value === showOutput) {
860+
_channel.show();
861+
} else if (value == suppressNotification) {
862+
extensionContext.globalState.update(stateKey, true);
863+
}
864+
});
830865

831-
const csharpIntelliCodeArgs: string[] = ['--starredCompletionComponentPath', starredCompletionComponentPath];
832-
return csharpIntelliCodeArgs;
866+
return [];
867+
}
833868
}
834869

835870
private static async setupDevKitEnvironment(

0 commit comments

Comments
 (0)