Skip to content

Commit

Permalink
Add option to disable devkit
Browse files Browse the repository at this point in the history
  • Loading branch information
dibarbet committed Sep 18, 2023
1 parent a62858c commit bf8b811
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 5 deletions.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,12 @@
"default": null,
"description": "Sets a path where MSBuild binary logs are written to when loading projects, to help diagnose loading errors."
},
"dotnet.preferCSharpExtension": {
"scope": "resource",
"type": "boolean",
"default": false,
"description": "%configuration.dotnet.preferCSharpExtension%"
},
"dotnet.implementType.insertionBehavior": {
"type": "string",
"enum": [
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"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.preferCSharpExtension": "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)",
"configuration.dotnet.implementType.insertionBehavior": "The insertion location of properties, events, and methods When implement interface or abstract class.",
"configuration.dotnet.implementType.insertionBehavior.withOtherMembersOfTheSameKind": "Place them with other members of the same kind.",
"configuration.dotnet.implementType.insertionBehavior.atTheEnd": "Place them at the end.",
Expand Down
4 changes: 2 additions & 2 deletions src/lsptoolshost/roslynLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ export class RoslynLanguageServer {
}

private async sendOrSubscribeForServiceBrokerConnection(): Promise<void> {
const csharpDevKitExtension = vscode.extensions.getExtension<CSharpDevKitExports>(csharpDevkitExtensionId);
const csharpDevKitExtension = getCSharpDevKit();
if (csharpDevKitExtension) {
const exports = await csharpDevKitExtension.activate();

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

Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export async function activate(

requiredPackageIds.push('Razor');

const csharpDevkitExtension = vscode.extensions.getExtension(csharpDevkitExtensionId);
const csharpDevkitExtension = getCSharpDevKit();
const useOmnisharpServer = !csharpDevkitExtension && commonOptions.useOmnisharpServer;
if (useOmnisharpServer) {
requiredPackageIds.push('OmniSharp');
Expand Down
5 changes: 5 additions & 0 deletions src/shared/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export interface LanguageServerOptions {
readonly logLevel: string;
readonly documentSelector: DocumentSelector;
readonly extensionsPaths: string[] | null;
readonly preferCSharpExtension: boolean;
}

export interface RazorOptions {
Expand Down Expand Up @@ -377,6 +378,9 @@ class LanguageServerOptionsImpl implements LanguageServerOptions {
public get extensionsPaths() {
return readOption<string[] | null>('dotnet.server.extensionPaths', null);
}
public get preferCSharpExtension() {
return readOption<boolean>('dotnet.preferCSharpExtension', false);
}
}

class RazorOptionsImpl implements RazorOptions {
Expand Down Expand Up @@ -469,4 +473,5 @@ export const OmnisharpOptionsThatTriggerReload: ReadonlyArray<keyof OmnisharpSer
export const LanguageServerOptionsThatTriggerReload: ReadonlyArray<keyof LanguageServerOptions> = [
'logLevel',
'documentSelector',
'preferCSharpExtension',
];
6 changes: 6 additions & 0 deletions src/utils/getCSharpDevKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@

import * as vscode from 'vscode';
import { CSharpDevKitExports } from '../csharpDevKitExports';
import { languageServerOptions } from '../shared/options';

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

export function getCSharpDevKit(): vscode.Extension<CSharpDevKitExports> | undefined {
// Devkit is explicitly disabled via the option - we should ignore it even if it exists.
if (languageServerOptions.preferCSharpExtension) {
return undefined;
}

return vscode.extensions.getExtension<CSharpDevKitExports>(csharpDevkitExtensionId);
}
5 changes: 3 additions & 2 deletions test/unitTests/languageServerConfigChangeObserver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ jestLib.describe('Option changes observer', () => {
[
{ config: 'dotnet', section: 'server.documentSelector', value: ['other'] },
{ config: 'dotnet', section: 'server.trace', value: 'trace' },
{ config: 'dotnet', section: 'preferCSharpExtension', value: true },
].forEach((elem) => {
jestLib.describe(`When the ${elem.config} ${elem.section} changes`, () => {
jestLib.describe(`When the ${elem.config}.${elem.section} changes`, () => {
jestLib.beforeEach(() => {
jestLib.expect(infoMessage).toBe(undefined);
jestLib.expect(invokedCommand).toBe(undefined);
Expand Down Expand Up @@ -76,7 +77,7 @@ jestLib.describe('Option changes observer', () => {
});

[{ config: 'dotnet', section: 'server.useOmnisharp', value: true }].forEach((elem) => {
jestLib.describe(`When the ${elem.config} ${elem.section} changes`, () => {
jestLib.describe(`When the ${elem.config}.${elem.section} changes`, () => {
jestLib.beforeEach(() => {
jestLib.expect(infoMessage).toBe(undefined);
jestLib.expect(invokedCommand).toBe(undefined);
Expand Down

0 comments on commit bf8b811

Please sign in to comment.