Skip to content

Commit 9c0d446

Browse files
CopilotJoeRobich
andcommitted
Handle optional components gracefully when files don't exist
Co-authored-by: JoeRobich <611219+JoeRobich@users.noreply.github.com>
1 parent e0152c9 commit 9c0d446

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/lsptoolshost/extensions/builtInComponents.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,20 @@ export const componentInfo: { [key: string]: ComponentInfo } = {
4444
},
4545
};
4646

47-
export function getComponentPaths(componentName: string, options: LanguageServerOptions | undefined): string[] {
47+
export function getComponentPaths(
48+
componentName: string,
49+
options: LanguageServerOptions | undefined,
50+
isOptional = false
51+
): string[] {
4852
const component = componentInfo[componentName];
4953
const baseFolder = getComponentFolderPath(component, options);
5054
const paths = component.componentDllPaths.map((dllPath) => path.join(baseFolder, dllPath));
5155
for (const dllPath of paths) {
5256
if (!fs.existsSync(dllPath)) {
57+
if (isOptional) {
58+
// Component is optional and doesn't exist - return empty array
59+
return [];
60+
}
5361
throw new Error(`Component DLL not found: ${dllPath}`);
5462
}
5563
}

src/lsptoolshost/server/roslynLanguageServer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ export class RoslynLanguageServer {
10261026

10271027
// Also include the Xaml Dev Kit extensions, if enabled.
10281028
if (languageServerOptions.enableXamlTools) {
1029-
getComponentPaths('xamlTools', languageServerOptions).forEach((path) =>
1029+
getComponentPaths('xamlTools', languageServerOptions, true).forEach((path) =>
10301030
additionalExtensionPaths.push(path)
10311031
);
10321032
}
@@ -1096,7 +1096,7 @@ export class RoslynLanguageServer {
10961096
await exports.setupTelemetryEnvironmentAsync(env);
10971097
}
10981098

1099-
getComponentPaths('roslynCopilot', languageServerOptions).forEach((extPath) => {
1099+
getComponentPaths('roslynCopilot', languageServerOptions, true).forEach((extPath) => {
11001100
additionalExtensionPaths.push(extPath);
11011101
});
11021102
}

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, true);
108108
if (razorComponentPaths.length !== 1) {
109109
logger.logError('Failed to find Razor DevKit telemetry extension path.', undefined);
110110
} else {

0 commit comments

Comments
 (0)