Skip to content

Commit

Permalink
Merge pull request #7039 from dibarbet/package_xaml_content
Browse files Browse the repository at this point in the history
Package xaml content
  • Loading branch information
dibarbet authored Apr 16, 2024
2 parents 3d33d80 + 7cbc4fc commit 1f84e72
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 104 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules
out
.roslyn/
.roslynDevKit/
.xamlTools/
.omnisharp/
.omnisharp-*/
.vs/
Expand Down
24 changes: 23 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"omniSharp": "1.39.11",
"razor": "7.0.0-preview.24178.4",
"razorOmnisharp": "7.0.0-preview.23363.1",
"razorTelemetry": "7.0.0-preview.24178.4"
"razorTelemetry": "7.0.0-preview.24178.4",
"xamlTools": "17.11.34816.20"
},
"main": "./dist/extension",
"l10n": "./l10n",
Expand Down Expand Up @@ -1621,6 +1622,21 @@
"scope": "machine-overridable",
"description": "%configuration.dotnet.server.path%"
},
"dotnet.server.componentPaths": {
"type": "object",
"description": "%configuration.dotnet.server.componentPaths%",
"properties": {
"roslynDevKit": {
"description": "%configuration.dotnet.server.componentPaths.roslynDevKit%",
"type": "string"
},
"xamlTools": {
"description": "%configuration.dotnet.server.componentPaths.xamlTools%",
"type": "string"
}
},
"default": {}
},
"dotnet.server.startTimeout": {
"type": "number",
"scope": "machine-overridable",
Expand Down Expand Up @@ -1666,6 +1682,12 @@
"default": null,
"description": "%configuration.dotnet.server.crashDumpPath%"
},
"dotnet.enableXamlToolsPreview": {
"scope": "machine-overridable",
"type": "boolean",
"default": false,
"description": "%configuration.dotnet.enableXamlToolsPreview%"
},
"dotnet.projects.binaryLogPath": {
"scope": "machine-overridable",
"type": "string",
Expand Down
4 changes: 4 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@
"configuration.dotnet.defaultSolution.description": "The path of the default solution to be opened in the workspace, or set to 'disable' to skip it. (Previously `omnisharp.defaultLaunchSolution`)",
"configuration.dotnet.dotnetPath": "Specifies the path to a dotnet installation directory to use instead of the default system one. This only influences the dotnet installation to use for hosting the language server itself. Example: \"/home/username/mycustomdotnetdirectory\".",
"configuration.dotnet.server.path": "Specifies the absolute path to the server (LSP or O#) executable. When left empty the version pinned to the C# Extension is used. (Previously `omnisharp.path`)",
"configuration.dotnet.server.componentPaths": "Allows overriding the folder path for built in components of the language server (for example, override the .roslynDevKit path in the extension directory to use locally built components)",
"configuration.dotnet.server.componentPaths.roslynDevKit": "Overrides the folder path for the .roslynDevKit component of the language server",
"configuration.dotnet.server.componentPaths.xamlTools": "Overrides the folder path for the .xamlTools component of the language server",
"configuration.dotnet.server.startTimeout": "Specifies a timeout (in ms) for the client to successfully start and connect to the language server.",
"configuration.dotnet.server.waitForDebugger": "Passes the --debug flag when launching the server to allow a debugger to be attached. (Previously `omnisharp.waitForDebugger`)",
"configuration.dotnet.server.trace": "Sets the logging level for the language server",
"configuration.dotnet.server.extensionPaths": "Override for path to language server --extension arguments",
"configuration.dotnet.server.crashDumpPath": "Sets a folder path where crash dumps are written to if the language server crashes. Must be writeable by the user.",
"configuration.dotnet.enableXamlToolsPreview": "[Experimental] Enables XAML tools when using C# Dev Kit",
"configuration.dotnet.projects.enableAutomaticRestore": "Enables automatic NuGet restore if the extension detects assets are missing.",
"configuration.dotnet.preferCSharpExtension": "Forces projects to load with the C# extension only. This can be useful when using legacy project types that are not supported by C# Dev Kit. (Requires window reload)",
"configuration.dotnet.implementType.insertionBehavior": "The insertion location of properties, events, and methods When implement interface or abstract class.",
Expand Down
1 change: 1 addition & 0 deletions src/csharpExtensionExports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface CSharpExtensionExports {
profferBrokeredServices: (container: GlobalBrokeredServiceContainer) => void;
determineBrowserType: () => Promise<string | undefined>;
experimental: CSharpExtensionExperimentalExports;
getComponentFolder: (componentName: string) => string;
}

export interface CSharpExtensionExperimentalExports {
Expand Down
59 changes: 59 additions & 0 deletions src/lsptoolshost/builtInComponents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as fs from 'fs';
import * as path from 'path';
import { LanguageServerOptions } from '../shared/options';

interface ComponentInfo {
defaultFolderName: string;
optionName: string;
componentDllPaths: string[];
}

export const componentInfo: { [key: string]: ComponentInfo } = {
roslynDevKit: {
defaultFolderName: '.roslynDevKit',
optionName: 'roslynDevKit',
componentDllPaths: ['Microsoft.VisualStudio.LanguageServices.DevKit.dll'],
},
xamlTools: {
defaultFolderName: '.xamlTools',
optionName: 'xamlTools',
componentDllPaths: [
'Microsoft.VisualStudio.DesignTools.CodeAnalysis.dll',
'Microsoft.VisualStudio.DesignTools.CodeAnalysis.Diagnostics.dll',
],
},
};

export function getComponentPaths(componentName: string, options: LanguageServerOptions): string[] {
const component = componentInfo[componentName];
const baseFolder = getComponentFolderPath(component, options);
const paths = component.componentDllPaths.map((dllPath) => path.join(baseFolder, dllPath));
for (const dllPath of paths) {
if (!fs.existsSync(dllPath)) {
throw new Error(`Component DLL not found: ${dllPath}`);
}
}

return paths;
}

export function getComponentFolder(componentName: string, options: LanguageServerOptions): string {
const component = componentInfo[componentName];
return getComponentFolderPath(component, options);
}

function getComponentFolderPath(component: ComponentInfo, options: LanguageServerOptions): string {
if (options.componentPaths) {
const optionValue = options.componentPaths[component.optionName];
if (optionValue) {
return optionValue;
}
}

return path.join(__dirname, '..', component.defaultFolderName);
}
34 changes: 20 additions & 14 deletions src/lsptoolshost/roslynLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import { IDisposable } from '../disposable';
import { registerNestedCodeActionCommands } from './nestedCodeAction';
import { registerRestoreCommands } from './restore';
import { BuildDiagnosticsService } from './buildDiagnosticsService';
import { getComponentPaths } from './builtInComponents';

let _channel: vscode.OutputChannel;
let _traceChannel: vscode.OutputChannel;
Expand Down Expand Up @@ -506,10 +507,6 @@ export class RoslynLanguageServer {
args.push('--logLevel', logLevel);
}

for (const extensionPath of additionalExtensionPaths) {
args.push('--extension', extensionPath);
}

args.push(
'--razorSourceGenerator',
path.join(context.extension.extensionPath, '.razor', 'Microsoft.CodeAnalysis.Razor.Compiler.dll')
Expand Down Expand Up @@ -540,7 +537,7 @@ export class RoslynLanguageServer {
// Set command enablement as soon as we know devkit is available.
vscode.commands.executeCommand('setContext', 'dotnet.server.activationContext', 'RoslynDevKit');

const csharpDevKitArgs = this.getCSharpDevKitExportArgs();
const csharpDevKitArgs = this.getCSharpDevKitExportArgs(additionalExtensionPaths);
args = args.concat(csharpDevKitArgs);

await this.setupDevKitEnvironment(dotnetInfo.env, csharpDevkitExtension);
Expand All @@ -553,6 +550,10 @@ export class RoslynLanguageServer {
_wasActivatedWithCSharpDevkit = false;
}

for (const extensionPath of additionalExtensionPaths) {
args.push('--extension', extensionPath);
}

if (logLevel && [Trace.Messages, Trace.Verbose].includes(this.GetTraceLevel(logLevel))) {
_channel.appendLine(`Starting server at ${serverPath}`);
}
Expand Down Expand Up @@ -806,19 +807,24 @@ export class RoslynLanguageServer {
);
}

private static getCSharpDevKitExportArgs(): string[] {
private static getCSharpDevKitExportArgs(additionalExtensionPaths: string[]): string[] {
const args: string[] = [];

const clientRoot = __dirname;
const devKitDepsPath = path.join(
clientRoot,
'..',
'.roslynDevKit',
'Microsoft.VisualStudio.LanguageServices.DevKit.dll'
);
args.push('--devKitDependencyPath', devKitDepsPath);
const devKitDepsPath = getComponentPaths('roslynDevKit', languageServerOptions);
if (devKitDepsPath.length > 1) {
throw new Error('Expected only one devkit deps path');
}

args.push('--devKitDependencyPath', devKitDepsPath[0]);

args.push('--sessionId', getSessionId());

// Also include the Xaml Dev Kit extensions, if enabled.
if (languageServerOptions.enableXamlToolsPreview) {
getComponentPaths('xamlTools', languageServerOptions).forEach((path) =>
additionalExtensionPaths.push(path)
);
}
return args;
}

Expand Down
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ import { RoslynLanguageServerEvents } from './lsptoolshost/languageServerEvents'
import { ServerStateChange } from './lsptoolshost/serverStateChange';
import { SolutionSnapshotProvider } from './lsptoolshost/services/solutionSnapshotProvider';
import { RazorTelemetryDownloader } from './razor/razorTelemetryDownloader';
import { commonOptions, omnisharpOptions, razorOptions } from './shared/options';
import { commonOptions, languageServerOptions, omnisharpOptions, razorOptions } from './shared/options';
import { BuildResultDiagnostics } from './lsptoolshost/services/buildResultReporterService';
import { debugSessionTracker } from './coreclrDebug/provisionalDebugSessionTracker';
import { getComponentFolder } from './lsptoolshost/builtInComponents';

export async function activate(
context: vscode.ExtensionContext
Expand Down Expand Up @@ -367,6 +368,9 @@ export async function activate(
sendServerRequest: async (t, p, ct) => await languageServerExport.sendRequest(t, p, ct),
languageServerEvents: roslynLanguageServerEvents,
},
getComponentFolder: (componentName) => {
return getComponentFolder(componentName, languageServerOptions);
},
};
} else {
return {
Expand Down
10 changes: 10 additions & 0 deletions src/shared/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export interface LanguageServerOptions {
readonly crashDumpPath: string | undefined;
readonly analyzerDiagnosticScope: string;
readonly compilerDiagnosticScope: string;
readonly componentPaths: { [key: string]: string } | null;
readonly enableXamlToolsPreview: boolean;
}

export interface RazorOptions {
Expand Down Expand Up @@ -397,6 +399,12 @@ class LanguageServerOptionsImpl implements LanguageServerOptions {
public get compilerDiagnosticScope() {
return readOption<string>('dotnet.backgroundAnalysis.compilerDiagnosticsScope', 'openFiles');
}
public get componentPaths() {
return readOption<{ [key: string]: string }>('dotnet.server.componentPaths', {});
}
public get enableXamlToolsPreview() {
return readOption<boolean>('dotnet.enableXamlToolsPreview', false);
}
}

class RazorOptionsImpl implements RazorOptions {
Expand Down Expand Up @@ -490,4 +498,6 @@ export const LanguageServerOptionsThatTriggerReload: ReadonlyArray<keyof Languag
'logLevel',
'documentSelector',
'preferCSharpExtension',
'componentPaths',
'enableXamlToolsPreview',
];
Loading

0 comments on commit 1f84e72

Please sign in to comment.