Skip to content

Commit b4b22c1

Browse files
CopilotJoeRobich
andcommitted
Add logging for missing optional components and restore isOptional property
Co-authored-by: JoeRobich <611219+JoeRobich@users.noreply.github.com>
1 parent bd3a498 commit b4b22c1

File tree

5 files changed

+27
-13
lines changed

5 files changed

+27
-13
lines changed

src/lsptoolshost/extensions/builtInComponents.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,21 @@ export const componentInfo: { [key: string]: ComponentInfo } = {
4646
},
4747
};
4848

49-
export function getComponentPaths(componentName: string, options: LanguageServerOptions | undefined): string[] {
49+
export function getComponentPaths(
50+
componentName: string,
51+
options: LanguageServerOptions | undefined,
52+
channel?: { warn: (message: string) => void }
53+
): string[] {
5054
const component = componentInfo[componentName];
5155
const baseFolder = getComponentFolderPath(component, options);
5256
const paths = component.componentDllPaths.map((dllPath) => path.join(baseFolder, dllPath));
5357
for (const dllPath of paths) {
5458
if (!fs.existsSync(dllPath)) {
5559
if (component.isOptional) {
56-
// Component is optional and doesn't exist - return empty array
60+
// Component is optional and doesn't exist - log warning and return empty array
61+
if (channel) {
62+
channel.warn(`Optional component '${componentName}' could not be found at '${dllPath}'.`);
63+
}
5764
return [];
5865
}
5966
throw new Error(`Component DLL not found: ${dllPath}`);

src/lsptoolshost/server/roslynLanguageServer.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ export class RoslynLanguageServer {
651651
: razorOptions.razorServerPath;
652652

653653
let razorComponentPath = '';
654-
getComponentPaths('razorExtension', languageServerOptions).forEach((extPath) => {
654+
getComponentPaths('razorExtension', languageServerOptions, channel).forEach((extPath) => {
655655
additionalExtensionPaths.push(extPath);
656656
razorComponentPath = path.dirname(extPath);
657657
});
@@ -695,10 +695,10 @@ export class RoslynLanguageServer {
695695
// Set command enablement as soon as we know devkit is available.
696696
await vscode.commands.executeCommand('setContext', 'dotnet.server.activationContext', 'RoslynDevKit');
697697

698-
const csharpDevKitArgs = this.getCSharpDevKitExportArgs(additionalExtensionPaths);
698+
const csharpDevKitArgs = this.getCSharpDevKitExportArgs(additionalExtensionPaths, channel);
699699
args = args.concat(csharpDevKitArgs);
700700

701-
await this.setupDevKitEnvironment(dotnetInfo.env, csharpDevkitExtension, additionalExtensionPaths);
701+
await this.setupDevKitEnvironment(dotnetInfo.env, csharpDevkitExtension, additionalExtensionPaths, channel);
702702
} else {
703703
// C# Dev Kit is not installed - continue C#-only activation.
704704
channel.info('Activating C# standalone...');
@@ -1012,10 +1012,13 @@ export class RoslynLanguageServer {
10121012
);
10131013
}
10141014

1015-
private static getCSharpDevKitExportArgs(additionalExtensionPaths: string[]): string[] {
1015+
private static getCSharpDevKitExportArgs(
1016+
additionalExtensionPaths: string[],
1017+
channel: vscode.LogOutputChannel
1018+
): string[] {
10161019
const args: string[] = [];
10171020

1018-
const devKitDepsPath = getComponentPaths('roslynDevKit', languageServerOptions);
1021+
const devKitDepsPath = getComponentPaths('roslynDevKit', languageServerOptions, channel);
10191022
if (devKitDepsPath.length > 1) {
10201023
throw new Error('Expected only one devkit deps path');
10211024
}
@@ -1026,7 +1029,7 @@ export class RoslynLanguageServer {
10261029

10271030
// Also include the Xaml Dev Kit extensions, if enabled.
10281031
if (languageServerOptions.enableXamlTools) {
1029-
getComponentPaths('xamlTools', languageServerOptions).forEach((path) =>
1032+
getComponentPaths('xamlTools', languageServerOptions, channel).forEach((path) =>
10301033
additionalExtensionPaths.push(path)
10311034
);
10321035
}
@@ -1086,7 +1089,8 @@ export class RoslynLanguageServer {
10861089
private static async setupDevKitEnvironment(
10871090
env: NodeJS.ProcessEnv,
10881091
csharpDevkitExtension: vscode.Extension<CSharpDevKitExports>,
1089-
additionalExtensionPaths: string[]
1092+
additionalExtensionPaths: string[],
1093+
channel: vscode.LogOutputChannel
10901094
): Promise<void> {
10911095
const exports: CSharpDevKitExports = await csharpDevkitExtension.activate();
10921096

@@ -1096,7 +1100,7 @@ export class RoslynLanguageServer {
10961100
await exports.setupTelemetryEnvironmentAsync(env);
10971101
}
10981102

1099-
getComponentPaths('roslynCopilot', languageServerOptions).forEach((extPath) => {
1103+
getComponentPaths('roslynCopilot', languageServerOptions, channel).forEach((extPath) => {
11001104
additionalExtensionPaths.push(extPath);
11011105
});
11021106
}

src/packageManager/IPackage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ export interface IPackage {
1313
platformId?: string;
1414
integrity?: string;
1515
isFramework?: boolean;
16+
isOptional?: boolean;
1617
}

src/packageManager/absolutePathPackage.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export class AbsolutePathPackage implements IPackage {
2020
public fallbackUrl?: string,
2121
public platformId?: string,
2222
public integrity?: string,
23-
public isFramework?: boolean
23+
public isFramework?: boolean,
24+
public isOptional?: boolean
2425
) {}
2526

2627
public static getAbsolutePathPackage(pkg: Package, extensionPath: string) {
@@ -36,7 +37,8 @@ export class AbsolutePathPackage implements IPackage {
3637
pkg.fallbackUrl,
3738
pkg.platformId,
3839
pkg.integrity,
39-
pkg.isFramework
40+
pkg.isFramework,
41+
pkg.isOptional
4042
);
4143
}
4244
}

src/razor/src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export async function activate(
104104
await setupDevKitEnvironment(dotnetInfo.env, csharpDevkitExtension, logger);
105105

106106
if (vscode.env.isTelemetryEnabled) {
107-
const razorComponentPaths = getComponentPaths('razorDevKit', undefined);
107+
const razorComponentPaths = getComponentPaths('razorDevKit', undefined, logger.outputChannel);
108108
if (razorComponentPaths.length !== 1) {
109109
logger.logError('Failed to find Razor DevKit telemetry extension path.', undefined);
110110
} else {

0 commit comments

Comments
 (0)