Skip to content

Commit ab97842

Browse files
committed
Updates to bring in the Copilot lanaguage server from a storage account instead of relying on its presence in C# Dev Kit.
1 parent 4cd8363 commit ab97842

File tree

4 files changed

+45
-61
lines changed

4 files changed

+45
-61
lines changed

package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,24 @@
422422
"isFramework": false,
423423
"integrity": "9944EBD6EE06BD595BCADD3057CD9BEF4105C3A3952DAE03E54F3114E2E6661F"
424424
},
425+
{
426+
"id": "RoslynCopilotLanguageServer",
427+
"description": "Language server for Roslyn Copilot integration (Windows)",
428+
"url": "https://roslynomnisharp.blob.core.windows.net/releases/1.39.12/omnisharp-linux-musl-arm64-net6.0-1.39.12.zip",
429+
"installPath": ".roslyncopilotlanguageserver",
430+
"platforms": [
431+
"win32",
432+
"linux",
433+
"linux-musl",
434+
"darwin"
435+
],
436+
"architectures": [
437+
"x86_64",
438+
"arm64"
439+
],
440+
"installTestPath": "./.roslyncopilotlanguageserver/Microsoft.VisualStudio.Copilot.Roslyn.LanguageServer.dll",
441+
"integrity": "9944EBD6EE06BD595BCADD3057CD9BEF4105C3A3952DAE03E54F3114E2E6661F"
442+
},
425443
{
426444
"id": "Debugger",
427445
"description": ".NET Core Debugger (Windows / x64)",

src/lsptoolshost/copilot/contextProviders.ts

Lines changed: 10 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ import * as vscode from 'vscode';
77
import * as lsp from 'vscode-languageserver-protocol';
88
import { RoslynLanguageServer } from '../server/roslynLanguageServer';
99
import { CSharpExtensionId } from '../../constants/csharpExtensionId';
10-
import { csharpDevkitExtensionId, getCSharpDevKit } from '../../utils/getCSharpDevKit';
11-
import path from 'path';
12-
import { readJsonSync } from 'fs-extra';
13-
14-
export const copilotLanguageServerExtensionComponentName = '@microsoft/visualstudio.copilot.roslyn.languageserver';
15-
export const copilotLanguageServerExtensionAssemblyName = 'Microsoft.VisualStudio.Copilot.Roslyn.LanguageServer.dll';
16-
const copilotLanguageServerExtensionCapabilitiesFileName = 'capabilities.json';
10+
import { getCSharpDevKit } from '../../utils/getCSharpDevKit';
1711

1812
type ActiveExperiments = { [name: string]: string | number | boolean | string[] };
1913

@@ -29,17 +23,9 @@ export interface ContextResolveParam {
2923
data?: any;
3024
activeExperiments: ActiveExperiments;
3125
}
32-
33-
const oldResolveContextMethodName = 'roslyn/resolveContext';
34-
const oldresolveContextMethodSupportedVersion = '1';
35-
const newResolveContextMethodName = 'roslyn/resolveContext@2';
36-
const newResolveContextMethodSupportedVersion = '1';
37-
const oldResolveContextRequest = new lsp.RequestType<ContextResolveParam, SupportedContextItem[], void>(
38-
oldResolveContextMethodName,
39-
lsp.ParameterStructures.auto
40-
);
41-
const newResolveContextRequest = new lsp.RequestType<ContextResolveParam, SupportedContextItem[], void>(
42-
newResolveContextMethodName,
26+
const resolveContextMethodName = 'roslyn/resolveContext@2';
27+
const resolveContextRequest = new lsp.RequestType<ContextResolveParam, SupportedContextItem[], void>(
28+
resolveContextMethodName,
4329
lsp.ParameterStructures.auto
4430
);
4531

@@ -85,43 +71,8 @@ export function registerCopilotContextProviders(
8571
return;
8672
}
8773

88-
devkit.activate().then(async (devKitExports) => {
74+
devkit.activate().then(async () => {
8975
try {
90-
let resolveMethod: lsp.RequestType<ContextResolveParam, SupportedContextItem[], void> | undefined =
91-
undefined;
92-
const copilotServerExtensionfolder = devKitExports.components[copilotLanguageServerExtensionComponentName];
93-
if (copilotServerExtensionfolder) {
94-
const capabilitiesFilePath = path.join(
95-
copilotServerExtensionfolder,
96-
copilotLanguageServerExtensionCapabilitiesFileName
97-
);
98-
const capabilitiesContent = await readJsonSync(capabilitiesFilePath);
99-
for (const capability of capabilitiesContent?.capabilities ?? []) {
100-
if (
101-
capability.method === oldResolveContextMethodName &&
102-
capability.version === oldresolveContextMethodSupportedVersion
103-
) {
104-
resolveMethod = oldResolveContextRequest;
105-
channel.debug(`supported 'roslyn/resolveContext' method found in capabilities.json`);
106-
break;
107-
} else if (
108-
capability.method === newResolveContextMethodName &&
109-
capability.version === newResolveContextMethodSupportedVersion
110-
) {
111-
resolveMethod = newResolveContextRequest;
112-
channel.debug(`supported 'roslyn/resolveContext@2' method found in capabilities.json`);
113-
break;
114-
}
115-
}
116-
}
117-
118-
if (!resolveMethod) {
119-
channel.debug(
120-
`Failed to find compatible version of context provider from installed version of ${csharpDevkitExtensionId}.`
121-
);
122-
return;
123-
}
124-
12576
const copilotApi = vscode.extensions.getExtension<CopilotApi>('github.copilot');
12677
if (!copilotApi) {
12778
channel.debug(
@@ -150,7 +101,11 @@ export function registerCopilotContextProviders(
150101
if (!contextResolveParam) {
151102
return [];
152103
}
153-
const items = await languageServer.sendRequest(resolveMethod, contextResolveParam, token);
104+
const items = await languageServer.sendRequest(
105+
resolveContextRequest,
106+
contextResolveParam,
107+
token
108+
);
154109
channel.trace(`Copilot context provider resolved ${items.length} items`);
155110
return items;
156111
},

src/lsptoolshost/server/roslynLanguageServer.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as path from 'path';
88
import * as cp from 'child_process';
99
import * as uuid from 'uuid';
1010
import * as net from 'net';
11+
import * as util from '../../common';
1112
import {
1213
LanguageClientOptions,
1314
MessageTransports,
@@ -74,10 +75,6 @@ import { getProfilingEnvVars } from '../profiling/profiling';
7475
import { isString } from '../utils/isString';
7576
import { getServerPath } from '../activate';
7677
import { UriConverter } from '../utils/uriConverter';
77-
import {
78-
copilotLanguageServerExtensionAssemblyName,
79-
copilotLanguageServerExtensionComponentName,
80-
} from '../copilot/contextProviders';
8178

8279
// Flag indicating if C# Devkit was installed the last time we activated.
8380
// Used to determine if we need to restart the server on extension changes.
@@ -108,6 +105,13 @@ export class RoslynLanguageServer {
108105
*/
109106
private static _processId: number | undefined;
110107

108+
/**
109+
* The folder name for the Roslyn Copilot language server extension.
110+
*/
111+
private static readonly _copilotLanguageServerExtensionDirName = '.roslyncopilotlanguageserver';
112+
private static readonly _copilotLanguageServerExtensionAssemblyName =
113+
'Microsoft.VisualStudio.Copilot.Roslyn.LanguageServer.dll';
114+
111115
/**
112116
* The solution file previously opened; we hold onto this so we can send this back over if the server were to be relaunched for any reason, like some other configuration
113117
* change that required the server to restart, or some other catastrophic failure that completely took down the process. In the case that the process is crashing because
@@ -1079,11 +1083,15 @@ export class RoslynLanguageServer {
10791083
await exports.setupTelemetryEnvironmentAsync(env);
10801084
}
10811085

1082-
const copilotServerExtensionfolder = exports.components[copilotLanguageServerExtensionComponentName];
1086+
const copilotServerExtensionfolder = path.join(
1087+
util.getExtensionPath(),
1088+
RoslynLanguageServer._copilotLanguageServerExtensionDirName
1089+
);
1090+
10831091
if (copilotServerExtensionfolder) {
10841092
const copilotServerExtensionFullPath = path.join(
10851093
copilotServerExtensionfolder,
1086-
copilotLanguageServerExtensionAssemblyName
1094+
RoslynLanguageServer._copilotLanguageServerExtensionAssemblyName
10871095
);
10881096
additionalExtensionPaths.push(copilotServerExtensionFullPath);
10891097
channel.trace(

src/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ export async function activate(
7777
if (useOmnisharpServer) {
7878
requiredPackageIds.push('OmniSharp');
7979
}
80+
if (csharpDevkitExtension) {
81+
requiredPackageIds.push('RoslynCopilotLanguageServer');
82+
}
8083

8184
const networkSettingsProvider = vscodeNetworkSettingsProvider(vscode);
8285
const useFramework = useOmnisharpServer && omnisharpOptions.useModernNet !== true;

0 commit comments

Comments
 (0)