Skip to content

Commit e7161d0

Browse files
committed
Use the source generator from the Razor extension if cohosting is on
1 parent f156cc9 commit e7161d0

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/lsptoolshost/server/roslynLanguageServer.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -617,15 +617,23 @@ export class RoslynLanguageServer {
617617
? path.join(context.extension.extensionPath, '.razor')
618618
: razorOptions.razorServerPath;
619619

620-
args.push('--razorSourceGenerator', path.join(razorPath, 'Microsoft.CodeAnalysis.Razor.Compiler.dll'));
620+
let razorComponentPath = '';
621+
getComponentPaths('razorExtension', languageServerOptions).forEach((extPath) => {
622+
additionalExtensionPaths.push(extPath);
623+
razorComponentPath = path.dirname(extPath);
624+
});
625+
626+
// If cohosting is enabled we get the source generator from the razor component path
627+
const razorSourceGeneratorPath = razorOptions.cohostingEnabled ? razorComponentPath : razorPath;
621628

622629
args.push(
623-
'--razorDesignTimePath',
624-
path.join(razorPath, 'Targets', 'Microsoft.NET.Sdk.Razor.DesignTime.targets')
630+
'--razorSourceGenerator',
631+
path.join(razorSourceGeneratorPath, 'Microsoft.CodeAnalysis.Razor.Compiler.dll')
625632
);
626633

627-
getComponentPaths('razorExtension', languageServerOptions).forEach((path) =>
628-
additionalExtensionPaths.push(path)
634+
args.push(
635+
'--razorDesignTimePath',
636+
path.join(razorPath, 'Targets', 'Microsoft.NET.Sdk.Razor.DesignTime.targets')
629637
);
630638

631639
// Get the brokered service pipe name from C# Dev Kit (if installed).

src/shared/options.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export interface RazorOptions {
8888
readonly razorDevMode: boolean;
8989
readonly razorPluginPath: string;
9090
readonly razorServerPath: string;
91+
readonly cohostingEnabled: boolean;
9192
}
9293

9394
class CommonOptionsImpl implements CommonOptions {
@@ -430,6 +431,9 @@ class RazorOptionsImpl implements RazorOptions {
430431
public get razorServerPath() {
431432
return readOption<string>('razor.languageServer.directory', '');
432433
}
434+
public get cohostingEnabled() {
435+
return readOption<boolean>('razor.languageServer.cohostingEnabled', false);
436+
}
433437
}
434438

435439
export const commonOptions: CommonOptions = new CommonOptionsImpl();

0 commit comments

Comments
 (0)