Skip to content

Commit 28e2485

Browse files
committed
Add option to disable devkit
1 parent a62858c commit 28e2485

File tree

6 files changed

+21
-3
lines changed

6 files changed

+21
-3
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.loadProjectsWithCSharpExtension": {
1173+
"scope": "machine-overridable",
1174+
"type": "boolean",
1175+
"default": false,
1176+
"description": "%configuration.dotnet.loadProjectsWithCSharpExtension%"
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.loadProjectsWithCSharpExtension": "Forces projects to load with the C# extension only. This can be useful when using legacy project types that are not supported by the 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 loadProjectsWithCSharpExtension: 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 loadProjectsWithCSharpExtension() {
382+
return readOption<boolean>('dotnet.loadProjectsWithCSharpExtension', 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+
'loadProjectsWithCSharpExtension',
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.loadProjectsWithCSharpExtension) {
16+
return undefined;
17+
}
18+
1319
return vscode.extensions.getExtension<CSharpDevKitExports>(csharpDevkitExtensionId);
1420
}

0 commit comments

Comments
 (0)