Skip to content

Commit 23d7fb2

Browse files
authored
Merge pull request #6390 from dibarbet/add_devkit_disabled_option
Add option to disable devkit
2 parents 91f7fe4 + 05ef696 commit 23d7fb2

7 files changed

+24
-5
lines changed

package.json

+6
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,12 @@
11691169
"default": null,
11701170
"description": "Sets a path where MSBuild binary logs are written to when loading projects, to help diagnose loading errors."
11711171
},
1172+
"dotnet.preferCSharpExtension": {
1173+
"scope": "resource",
1174+
"type": "boolean",
1175+
"default": false,
1176+
"description": "%configuration.dotnet.preferCSharpExtension%"
1177+
},
11721178
"dotnet.implementType.insertionBehavior": {
11731179
"type": "string",
11741180
"enum": [

package.nls.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"configuration.dotnet.server.waitForDebugger": "Passes the --debug flag when launching the server to allow a debugger to be attached. (Previously `omnisharp.waitForDebugger`)",
66
"configuration.dotnet.server.trace": "Sets the logging level for the language server",
77
"configuration.dotnet.server.extensionPaths": "Override for path to language server --extension arguments",
8+
"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)",
89
"configuration.dotnet.implementType.insertionBehavior": "The insertion location of properties, events, and methods When implement interface or abstract class.",
910
"configuration.dotnet.implementType.insertionBehavior.withOtherMembersOfTheSameKind": "Place them with other members of the same kind.",
1011
"configuration.dotnet.implementType.insertionBehavior.atTheEnd": "Place them at the end.",

src/lsptoolshost/roslynLanguageServer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ export class RoslynLanguageServer {
403403
}
404404

405405
private async sendOrSubscribeForServiceBrokerConnection(): Promise<void> {
406-
const csharpDevKitExtension = vscode.extensions.getExtension<CSharpDevKitExports>(csharpDevkitExtensionId);
406+
const csharpDevKitExtension = getCSharpDevKit();
407407
if (csharpDevKitExtension) {
408408
const exports = await csharpDevKitExtension.activate();
409409

@@ -469,7 +469,7 @@ export class RoslynLanguageServer {
469469
// Get the brokered service pipe name from C# Dev Kit (if installed).
470470
// We explicitly call this in the LSP server start action instead of awaiting it
471471
// in our activation because C# Dev Kit depends on C# activation completing.
472-
const csharpDevkitExtension = vscode.extensions.getExtension<CSharpDevKitExports>(csharpDevkitExtensionId);
472+
const csharpDevkitExtension = getCSharpDevKit();
473473
if (csharpDevkitExtension) {
474474
_wasActivatedWithCSharpDevkit = true;
475475

src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export async function activate(
8989

9090
requiredPackageIds.push('Razor');
9191

92-
const csharpDevkitExtension = vscode.extensions.getExtension(csharpDevkitExtensionId);
92+
const csharpDevkitExtension = getCSharpDevKit();
9393
const useOmnisharpServer = !csharpDevkitExtension && commonOptions.useOmnisharpServer;
9494
if (useOmnisharpServer) {
9595
requiredPackageIds.push('OmniSharp');

src/shared/options.ts

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export interface LanguageServerOptions {
7272
readonly logLevel: string;
7373
readonly documentSelector: DocumentSelector;
7474
readonly extensionsPaths: string[] | null;
75+
readonly preferCSharpExtension: boolean;
7576
}
7677

7778
export interface RazorOptions {
@@ -377,6 +378,9 @@ class LanguageServerOptionsImpl implements LanguageServerOptions {
377378
public get extensionsPaths() {
378379
return readOption<string[] | null>('dotnet.server.extensionPaths', null);
379380
}
381+
public get preferCSharpExtension() {
382+
return readOption<boolean>('dotnet.preferCSharpExtension', false);
383+
}
380384
}
381385

382386
class RazorOptionsImpl implements RazorOptions {
@@ -469,4 +473,5 @@ export const OmnisharpOptionsThatTriggerReload: ReadonlyArray<keyof OmnisharpSer
469473
export const LanguageServerOptionsThatTriggerReload: ReadonlyArray<keyof LanguageServerOptions> = [
470474
'logLevel',
471475
'documentSelector',
476+
'preferCSharpExtension',
472477
];

src/utils/getCSharpDevKit.ts

+6
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55

66
import * as vscode from 'vscode';
77
import { CSharpDevKitExports } from '../csharpDevKitExports';
8+
import { languageServerOptions } from '../shared/options';
89

910
export const csharpDevkitExtensionId = 'ms-dotnettools.csdevkit';
1011
export const csharpDevkitIntelliCodeExtensionId = 'ms-dotnettools.vscodeintellicode-csharp';
1112

1213
export function getCSharpDevKit(): vscode.Extension<CSharpDevKitExports> | undefined {
14+
// Devkit is explicitly disabled via the option - we should ignore it even if it exists.
15+
if (languageServerOptions.preferCSharpExtension) {
16+
return undefined;
17+
}
18+
1319
return vscode.extensions.getExtension<CSharpDevKitExports>(csharpDevkitExtensionId);
1420
}

test/unitTests/languageServerConfigChangeObserver.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ jestLib.describe('Option changes observer', () => {
3636
[
3737
{ config: 'dotnet', section: 'server.documentSelector', value: ['other'] },
3838
{ config: 'dotnet', section: 'server.trace', value: 'trace' },
39+
{ config: 'dotnet', section: 'preferCSharpExtension', value: true },
3940
].forEach((elem) => {
40-
jestLib.describe(`When the ${elem.config} ${elem.section} changes`, () => {
41+
jestLib.describe(`When the ${elem.config}.${elem.section} changes`, () => {
4142
jestLib.beforeEach(() => {
4243
jestLib.expect(infoMessage).toBe(undefined);
4344
jestLib.expect(invokedCommand).toBe(undefined);
@@ -76,7 +77,7 @@ jestLib.describe('Option changes observer', () => {
7677
});
7778

7879
[{ config: 'dotnet', section: 'server.useOmnisharp', value: true }].forEach((elem) => {
79-
jestLib.describe(`When the ${elem.config} ${elem.section} changes`, () => {
80+
jestLib.describe(`When the ${elem.config}.${elem.section} changes`, () => {
8081
jestLib.beforeEach(() => {
8182
jestLib.expect(infoMessage).toBe(undefined);
8283
jestLib.expect(invokedCommand).toBe(undefined);

0 commit comments

Comments
 (0)