Skip to content

Commit cc6cd0e

Browse files
authored
Merge pull request #6450 from dibarbet/cherry_pick_devkit
Cherry pick devkit option
2 parents 52562b8 + a9e6ac0 commit cc6cd0e

File tree

9 files changed

+28
-6
lines changed

9 files changed

+28
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
- Debug from .csproj and .sln [#5876](https://github.com/dotnet/vscode-csharp/issues/5876)
99

1010
## Latest
11+
* Respect `dotnet.preferCSharpExtension` option (PR: [#6390](https://github.com/dotnet/vscode-csharp/pull/6390))
12+
13+
## 2.3.27
1114
* Update Roslyn version to 4.8.0-3.23470.7 (PR: [#6408](https://github.com/dotnet/vscode-csharp/pull/6408))
1215
* Update NuGet version to fix issues loading projects with .NET 8 RC2 (PR: [#70023](https://github.com/dotnet/roslyn/pull/70023))
1316
* Update MSBuildLocator version to fix issues loading projects when only .NET 6 is installed (PR: [#70038](https://github.com/dotnet/roslyn/pull/70038))

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,12 @@
11751175
"default": null,
11761176
"description": "Sets a path where MSBuild binary logs are written to when loading projects, to help diagnose loading errors."
11771177
},
1178+
"dotnet.preferCSharpExtension": {
1179+
"scope": "resource",
1180+
"type": "boolean",
1181+
"default": false,
1182+
"description": "%configuration.dotnet.preferCSharpExtension%"
1183+
},
11781184
"dotnet.implementType.insertionBehavior": {
11791185
"type": "string",
11801186
"enum": [

package.nls.json

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

src/lsptoolshost/roslynLanguageServer.ts

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export interface LanguageServerOptions {
7373
readonly documentSelector: DocumentSelector;
7474
readonly extensionsPaths: string[] | null;
7575
readonly startTimeout: number;
76+
readonly preferCSharpExtension: boolean;
7677
}
7778

7879
export interface RazorOptions {
@@ -381,6 +382,9 @@ class LanguageServerOptionsImpl implements LanguageServerOptions {
381382
public get startTimeout() {
382383
return readOption<number>('dotnet.server.startTimeout', 30000);
383384
}
385+
public get preferCSharpExtension() {
386+
return readOption<boolean>('dotnet.preferCSharpExtension', false);
387+
}
384388
}
385389

386390
class RazorOptionsImpl implements RazorOptions {
@@ -473,4 +477,5 @@ export const OmnisharpOptionsThatTriggerReload: ReadonlyArray<keyof OmnisharpSer
473477
export const LanguageServerOptionsThatTriggerReload: ReadonlyArray<keyof LanguageServerOptions> = [
474478
'logLevel',
475479
'documentSelector',
480+
'preferCSharpExtension',
476481
];

src/utils/getCSharpDevKit.ts

Lines changed: 6 additions & 0 deletions
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

Lines changed: 3 additions & 2 deletions
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);

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
3-
"version": "2.3",
3+
"version": "2.4",
44
"publicReleaseRefSpec": [
55
"^refs/heads/release$",
66
"^refs/heads/main$"

0 commit comments

Comments
 (0)