Skip to content

Commit c618d38

Browse files
committed
Merge remote-tracking branch 'upstream/main' into merge_main
2 parents f122463 + e233682 commit c618d38

18 files changed

+384
-73
lines changed

.vscode/launch.json

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848
"--extensionTestsPath=${workspaceRoot}/out/test/featureTests"
4949
],
5050
"env": {
51-
"CODE_WORKSPACE_ROOT": "${workspaceRoot}",
52-
"CODE_TESTS_PATH": "${workspaceRoot}/out/test/featureTests",
5351
"CODE_EXTENSIONS_PATH": "${workspaceRoot}",
5452
"OSVC_SUITE": "featureTests",
5553
},
@@ -73,12 +71,8 @@
7371
"--extensionTestsPath=${workspaceRoot}/out/test/integrationTests"
7472
],
7573
"env": {
76-
"CODE_WORKSPACE_ROOT": "${workspaceRoot}",
77-
"CODE_TESTS_PATH": "${workspaceRoot}/out/test/integrationTests",
78-
"CODE_TESTS_WORKSPACE": "${workspaceRoot}/test/integrationTests/testAssets/singleCsproj",
7974
"CODE_EXTENSIONS_PATH": "${workspaceRoot}",
8075
"OSVC_SUITE": "singleCsproj",
81-
"OMNISHARP_ENGINE": "stdio",
8276
},
8377
"sourceMaps": true,
8478
"outFiles": [
@@ -101,12 +95,8 @@
10195
"--extensionTestsPath=${workspaceRoot}/out/test/integrationTests"
10296
],
10397
"env": {
104-
"CODE_WORKSPACE_ROOT": "${workspaceRoot}",
105-
"CODE_TESTS_PATH": "${workspaceRoot}/out/test/integrationTests",
106-
"CODE_TESTS_WORKSPACE": "${workspaceRoot}/test/integrationTests/testAssets/BasicRazorApp2_1",
10798
"CODE_EXTENSIONS_PATH": "${workspaceRoot}",
10899
"OSVC_SUITE": "BasicRazorApp2_1",
109-
"OMNISHARP_ENGINE": "stdio",
110100
},
111101
},
112102
{
@@ -118,26 +108,45 @@
118108
// Create a temp profile that has no extensions / user settings.
119109
// This allows us to only have the C# extension + the dotnet runtime installer extension dependency.
120110
"--profile-temp",
121-
"${workspaceRoot}/test/integrationTests/testAssets/slnWithCsproj",
111+
"${workspaceRoot}/test/integrationTests/testAssets/slnWithCsproj/.vscode/omnisharp_slnWithCsproj.code-workspace",
122112
"--extensionDevelopmentPath=${workspaceRoot}",
123113
"--extensionTestsPath=${workspaceRoot}/out/test/integrationTests"
124114
],
125115
"env": {
126-
"CODE_WORKSPACE_ROOT": "${workspaceRoot}",
127-
"CODE_TESTS_PATH": "${workspaceRoot}/out/test/integrationTests",
128-
"CODE_TESTS_WORKSPACE": "${workspaceRoot}/test/integrationTests/testAssets/slnWithCsproj",
129116
"CODE_EXTENSIONS_PATH": "${workspaceRoot}",
130117
"OSVC_SUITE": "slnWithCsproj",
131-
"OMNISHARP_ENGINE": "stdio",
132118
},
133-
"stopOnEntry": false,
134119
"sourceMaps": true,
135120
"outFiles": [
136121
"${workspaceRoot}/dist/*.js",
137122
"${workspaceRoot}/out/test/**/*.js"
138123
],
139124
"preLaunchTask": "buildDev"
140125
},
126+
{
127+
"name": "LSP Tools Host: Launch slnWithCsproj Workspace Tests",
128+
"type": "extensionHost",
129+
"request": "launch",
130+
"runtimeExecutable": "${execPath}",
131+
"args": [
132+
// Create a temp profile that has no extensions / user settings.
133+
// This allows us to only have the C# extension + the dotnet runtime installer extension dependency.
134+
"--profile-temp",
135+
"${workspaceRoot}/test/integrationTests/testAssets/slnWithCsproj/.vscode/lsp_tools_host_slnWithCsproj.code-workspace",
136+
"--extensionDevelopmentPath=${workspaceRoot}",
137+
"--extensionTestsPath=${workspaceRoot}/out/lsptoolshosttest/lspToolsHostIntegrationTests",
138+
],
139+
"env": {
140+
"CODE_EXTENSIONS_PATH": "${workspaceRoot}",
141+
"OSVC_SUITE": "slnWithCsproj",
142+
},
143+
"sourceMaps": true,
144+
"outFiles": [
145+
"${workspaceRoot}/dist/*.js",
146+
"${workspaceRoot}/out/bluetest/**/*.js"
147+
],
148+
"preLaunchTask": "buildDev"
149+
},
141150
{
142151
"name": "Launch singleCsproj Workspace Tests [LSP]",
143152
"type": "extensionHost",
@@ -147,19 +156,14 @@
147156
// Create a temp profile that has no extensions / user settings.
148157
// This allows us to only have the C# extension + the dotnet runtime installer extension dependency.
149158
"--profile-temp",
150-
"${workspaceRoot}/test/integrationTests/testAssets/singleCsproj",
159+
"${workspaceRoot}/test/integrationTests/testAssets/slnWithCsproj/.vscode/omnisharp_lsp_slnWithCsproj.code-workspace",
151160
"--extensionDevelopmentPath=${workspaceRoot}",
152161
"--extensionTestsPath=${workspaceRoot}/out/test/integrationTests"
153162
],
154163
"env": {
155-
"CODE_WORKSPACE_ROOT": "${workspaceRoot}",
156-
"CODE_TESTS_PATH": "${workspaceRoot}/out/test/integrationTests",
157-
"CODE_TESTS_WORKSPACE": "${workspaceRoot}/test/integrationTests/testAssets/singleCsproj",
158164
"CODE_EXTENSIONS_PATH": "${workspaceRoot}",
159165
"OSVC_SUITE": "singleCsproj",
160-
"OMNISHARP_ENGINE": "lsp",
161166
},
162-
"stopOnEntry": false,
163167
"sourceMaps": true,
164168
"outFiles": [
165169
"${workspaceRoot}/dist/*.js",
@@ -181,12 +185,8 @@
181185
"--extensionTestsPath=${workspaceRoot}/out/test/integrationTests"
182186
],
183187
"env": {
184-
"CODE_WORKSPACE_ROOT": "${workspaceRoot}",
185-
"CODE_TESTS_PATH": "${workspaceRoot}/out/test/integrationTests",
186-
"CODE_TESTS_WORKSPACE": "${workspaceRoot}/test/integrationTests/testAssets/BasicRazorApp2_1",
187188
"CODE_EXTENSIONS_PATH": "${workspaceRoot}",
188189
"OSVC_SUITE": "BasicRazorApp2_1",
189-
"OMNISHARP_ENGINE": "lsp",
190190
},
191191
},
192192
{
@@ -198,17 +198,13 @@
198198
// Create a temp profile that has no extensions / user settings.
199199
// This allows us to only have the C# extension + the dotnet runtime installer extension dependency.
200200
"--profile-temp",
201-
"${workspaceRoot}/test/integrationTests/testAssets/slnWithCsproj",
201+
"${workspaceRoot}/test/integrationTests/testAssets/slnWithCsproj/.vscode/omnisharp_lsp_slnWithCsproj.code-workspace",
202202
"--extensionDevelopmentPath=${workspaceRoot}",
203203
"--extensionTestsPath=${workspaceRoot}/out/test/integrationTests"
204204
],
205205
"env": {
206-
"CODE_WORKSPACE_ROOT": "${workspaceRoot}",
207-
"CODE_TESTS_PATH": "${workspaceRoot}/out/test/integrationTests",
208-
"CODE_TESTS_WORKSPACE": "${workspaceRoot}/test/integrationTests/testAssets/slnWithCsproj",
209206
"CODE_EXTENSIONS_PATH": "${workspaceRoot}",
210207
"OSVC_SUITE": "slnWithCsproj",
211-
"OMNISHARP_ENGINE": "lsp",
212208
},
213209
"sourceMaps": true,
214210
"outFiles": [
@@ -231,9 +227,6 @@
231227
"--extensionTestsPath=${workspaceRoot}/out/test/integrationTests"
232228
],
233229
"env": {
234-
"CODE_WORKSPACE_ROOT": "${workspaceRoot}",
235-
"CODE_TESTS_PATH": "${workspaceRoot}/out/test/integrationTests",
236-
"CODE_TESTS_WORKSPACE": "${workspaceRoot}/test/integrationTests/testAssets/slnFilterWithCsproj",
237230
"CODE_EXTENSIONS_PATH": "${workspaceRoot}",
238231
"OSVC_SUITE": "slnFilterWithCsproj",
239232
},
@@ -258,9 +251,6 @@
258251
"--extensionTestsPath=${workspaceRoot}/out/test/integrationTests"
259252
],
260253
"env": {
261-
"CODE_WORKSPACE_ROOT": "${workspaceRoot}",
262-
"CODE_TESTS_PATH": "${workspaceRoot}/out/test/integrationTests",
263-
"CODE_TESTS_WORKSPACE": "${workspaceRoot}/test/integrationTests/testAssets/slnWithGenerator",
264254
"CODE_EXTENSIONS_PATH": "${workspaceRoot}",
265255
"OSVC_SUITE": "slnWithGenerator",
266256
},

README.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
## C# for Visual Studio Code
2-
A [Visual Studio Code](https://code.visualstudio.com/) [extension](https://marketplace.visualstudio.com/VSCode) that provides rich language support for C# and is shipped as part of [C# Dev Kit][csdevkitextension].
3-
4-
This pre-release version of the extension is available for use today, and offers performant and reliable support for coding in C#. Powered by a Language Server Protocol (LSP) Tools Host, this extension integrates with open source components like [Roslyn](https://github.com/dotnet/roslyn) and [Razor](https://github.com/dotnet/razor) to provide rich type information and a faster, more reliable C# experience.
2+
A [Visual Studio Code](https://code.visualstudio.com/) [extension](https://marketplace.visualstudio.com/VSCode) that provides rich language support for C# and is shipped along with [C# Dev Kit][csdevkitextension]. Powered by a Language Server Protocol (LSP) server, this extension integrates with open source components like [Roslyn](https://github.com/dotnet/roslyn) and [Razor](https://github.com/dotnet/razor) to provide rich type information and a faster, more reliable C# experience.
53

64
## Recommended Install
75
While it is possible to use the C# extension as a standalone extension, we highly recommend using [C# Dev Kit][csdevkitextension].
86

9-
1. Installing [C# Dev Kit][csdevkitextension] will automatically install this extension as a required dependency
7+
1. Installing [C# Dev Kit][csdevkitextension] will automatically install this extension as a required dependency.
108
2. Open a folder/workspace that contains a C# project (.csproj) and a C# solution (.sln) and the extension will activate.
119
3. Whether you install C# Dev Kit or just the C# extension, the [.NET Runtime Installer Tool extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.vscode-dotnet-runtime) will be installed as a dependency.
1210

13-
Note: If working on a solution that requires versions prior to .NET 6, install a Full Framework runtime and MSBuild tooling.
14-
* Set omnisharp.useModernNet to false and if you are on the pre-release verion, set dotnet.server.useOmnisharp to true
15-
* Windows: .NET Framework along with MSBuild Tools
16-
* MacOS/Linux: Mono with MSBuild
11+
Note: If working on a solution that requires versions prior to .NET 6 or non-solution based projects, install a Full Framework runtime and [MSBuild tooling](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022).
12+
* Set omnisharp.useModernNet to false and set dotnet.server.useOmnisharp to true
13+
* Uninstall or disable C# Dev Kit
14+
* Windows: .NET Framework along with [MSBuild Tools](https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022)
15+
* MacOS/Linux: [Mono with MSBuild](https://www.mono-project.com/download/preview/)
1716

1817
## Features
19-
* Refactoring
20-
* Code Navigation (GTD, FAR)
21-
* Code Completions
22-
* Roslyn powered semantic awareness
18+
Learn more about the rich features of the C# extension:
19+
* [Refactoring](https://code.visualstudio.com/docs/csharp/refactoring): Edit your code with code fixes and refactorings
20+
* [Navigation](https://code.visualstudio.com/docs/csharp/navigate-edit): Explore and navigate your code with features like Go To Definition and Find All References
21+
* [IntelliSense](https://code.visualstudio.com/docs/csharp/navigate-edit): Write code with auto-completion
22+
* [Formatting and Linting](https://code.visualstudio.com/docs/csharp/formatting-linting): Format and lint your code
23+
24+
For more information you can:
25+
26+
- [Follow our C# tutorial](https://code.visualstudio.com/docs/csharp/get-started) with step-by-step instructions for building a simple app.
27+
- Check out the [C# documentation](https://code.visualstudio.com/docs/languages/csharp) on the VS Code site for general information about using the extension.
2328

2429
## How to use OmniSharp?
25-
If you don’t want to take advantage of the great Language Server features, you can revert back to using OmniSharp in the pre-release extension by going to the Extension settings and setting `dotnet.server.useOmnisharp` to true. This will require that you restart VS Code to take effect. You can also switch back to the Switch to Release Version to revert back to the C# extension powered by OmniSharp.
30+
If you don’t want to take advantage of the great Language Server features, you can revert back to using OmniSharp by going to the Extension settings and setting `dotnet.server.useOmnisharp` to true. Next, uninstall or disable C# Dev Kit. Finally, restart VS Code for this to take effect.
2631

2732

2833
## Found a Bug?
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as path from 'path';
7+
import * as testRunner from '../testRunner';
8+
9+
export async function run() {
10+
process.env.RUNNING_INTEGRATION_TESTS = 'true';
11+
12+
return testRunner.run(path.resolve(__dirname, '.'), {
13+
timeout: 120000, // this seems to timing out often in our pipeline
14+
ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.)
15+
useColors: true, // colored output from test results
16+
});
17+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as vscode from 'vscode';
7+
8+
import { should, assert } from 'chai';
9+
import testAssetWorkspace from '../../test/integrationTests/testAssets/testAssetWorkspace';
10+
import * as path from 'path';
11+
import { activateCSharpExtension, isRazorWorkspace, isSlnWithGenerator } from './lspToolsHostIntegrationHelpers';
12+
import { InlayHint, InlayHintKind, Position } from 'vscode-languageserver-protocol';
13+
14+
suite(`LSP Inlay Hints ${testAssetWorkspace.description}`, function () {
15+
let fileUri: vscode.Uri;
16+
17+
suiteSetup(async function () {
18+
should();
19+
20+
if (isRazorWorkspace(vscode.workspace) || isSlnWithGenerator(vscode.workspace)) {
21+
this.skip();
22+
}
23+
24+
const editorConfig = vscode.workspace.getConfiguration('editor');
25+
await editorConfig.update('inlayHints.enabled', true);
26+
const dotnetConfig = vscode.workspace.getConfiguration('dotnet');
27+
await dotnetConfig.update('inlayHints.enableInlayHintsForParameters', true);
28+
await dotnetConfig.update('inlayHints.enableInlayHintsForLiteralParameters', true);
29+
await dotnetConfig.update('inlayHints.enableInlayHintsForObjectCreationParameters', true);
30+
await dotnetConfig.update('inlayHints.enableInlayHintsForIndexerParameters', true);
31+
await dotnetConfig.update('inlayHints.enableInlayHintsForOtherParameters', true);
32+
await dotnetConfig.update('inlayHints.suppressInlayHintsForParametersThatDifferOnlyBySuffix', true);
33+
await dotnetConfig.update('inlayHints.suppressInlayHintsForParametersThatMatchMethodIntent', true);
34+
await dotnetConfig.update('inlayHints.suppressInlayHintsForParametersThatMatchArgumentName', true);
35+
36+
const csharpConfig = vscode.workspace.getConfiguration('csharp');
37+
await csharpConfig.update('inlayHints.enableInlayHintsForTypes', true);
38+
await csharpConfig.update('inlayHints.enableInlayHintsForImplicitVariableTypes', true);
39+
await csharpConfig.update('inlayHints.enableInlayHintsForLambdaParameterTypes', true);
40+
await csharpConfig.update('inlayHints.enableInlayHintsForImplicitObjectCreation', true);
41+
42+
const fileName = 'inlayHints.cs';
43+
const projectDirectory = testAssetWorkspace.projects[0].projectDirectoryPath;
44+
const filePath = path.join(projectDirectory, fileName);
45+
fileUri = vscode.Uri.file(filePath);
46+
47+
await vscode.commands.executeCommand('vscode.open', fileUri);
48+
await activateCSharpExtension();
49+
});
50+
51+
suiteTeardown(async () => {
52+
await testAssetWorkspace.cleanupWorkspace();
53+
});
54+
55+
test('Hints retrieved for region', async () => {
56+
const range = new vscode.Range(new vscode.Position(4, 8), new vscode.Position(15, 85));
57+
const hints: vscode.InlayHint[] = await vscode.commands.executeCommand(
58+
'vscode.executeInlayHintProvider',
59+
fileUri,
60+
range
61+
);
62+
63+
assert.lengthOf(hints, 5);
64+
65+
assertInlayHintEqual(hints[0], InlayHint.create(Position.create(6, 12), 'InlayHints', InlayHintKind.Type));
66+
assertInlayHintEqual(hints[1], InlayHint.create(Position.create(7, 27), 'InlayHints', InlayHintKind.Type));
67+
assertInlayHintEqual(hints[2], InlayHint.create(Position.create(9, 17), 'i:', InlayHintKind.Parameter));
68+
assertInlayHintEqual(hints[3], InlayHint.create(Position.create(10, 15), 'param1:', InlayHintKind.Parameter));
69+
assertInlayHintEqual(hints[4], InlayHint.create(Position.create(11, 27), 'param1:', InlayHintKind.Parameter));
70+
71+
function assertInlayHintEqual(actual: vscode.InlayHint, expected: InlayHint) {
72+
const actualLabel = actual.label as string;
73+
assert.equal(actualLabel, expected.label);
74+
assert.equal(actual.position.line, expected.position.line);
75+
assert.equal(actual.position.character, expected.position.character);
76+
assert.equal(actual.kind, expected.kind);
77+
}
78+
});
79+
});
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as vscode from 'vscode';
7+
import * as path from 'path';
8+
import { CSharpExtensionExports } from '../../src/csharpExtensionExports';
9+
10+
export async function activateCSharpExtension(): Promise<void> {
11+
// Ensure the dependent extension exists - when launching via F5 launch.json we can't install the extension prior to opening vscode.
12+
const vscodeDotnetRuntimeExtensionId = 'ms-dotnettools.vscode-dotnet-runtime';
13+
const dotnetRuntimeExtension =
14+
vscode.extensions.getExtension<CSharpExtensionExports>(vscodeDotnetRuntimeExtensionId);
15+
if (!dotnetRuntimeExtension) {
16+
await vscode.commands.executeCommand('workbench.extensions.installExtension', vscodeDotnetRuntimeExtensionId);
17+
await vscode.commands.executeCommand('workbench.action.reloadWindow');
18+
}
19+
20+
const csharpExtension = vscode.extensions.getExtension<CSharpExtensionExports>('ms-dotnettools.csharp');
21+
if (!csharpExtension) {
22+
throw new Error('Failed to find installation of ms-dotnettools.csharp');
23+
}
24+
25+
// Explicitly await the extension activation even if completed so that we capture any errors it threw during activation.
26+
await csharpExtension.activate();
27+
28+
await csharpExtension.exports.initializationFinished();
29+
console.log('ms-dotnettools.csharp activated');
30+
}
31+
32+
export function isRazorWorkspace(workspace: typeof vscode.workspace) {
33+
return isGivenSln(workspace, 'BasicRazorApp2_1');
34+
}
35+
36+
export function isSlnWithGenerator(workspace: typeof vscode.workspace) {
37+
return isGivenSln(workspace, 'slnWithGenerator');
38+
}
39+
40+
function isGivenSln(workspace: typeof vscode.workspace, expectedProjectFileName: string) {
41+
const primeWorkspace = workspace.workspaceFolders![0];
42+
const projectFileName = primeWorkspace.uri.fsPath.split(path.sep).pop();
43+
44+
return projectFileName === expectedProjectFileName;
45+
}

0 commit comments

Comments
 (0)