Skip to content

Commit

Permalink
Merge pull request #6712 from dibarbet/merge_main
Browse files Browse the repository at this point in the history
Snap main to release
  • Loading branch information
dibarbet authored Dec 5, 2023
2 parents f94bbb3 + 7976f10 commit ee6980f
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 422 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
- Debug from .csproj and .sln [#5876](https://github.com/dotnet/vscode-csharp/issues/5876)

## Latest
* Update Roslyn to 4.9.0-3.23604.10 (PR: [#6676](https://github.com/dotnet/vscode-csharp/pull/6676))
* Pass through folders for additional files (PR: [#71061](https://github.com/dotnet/roslyn/pull/71061))
* Automatically detect missing NuGet packages and restore (PR: [#70851](https://github.com/dotnet/roslyn/pull/70851))
* Enable route embedded language features in vscode (PR: [#70927](https://github.com/dotnet/roslyn/pull/70927))
* Add automatic nuget restore support to C# standalone (PR: [#6676](https://github.com/dotnet/vscode-csharp/pull/6676))
* Update required VSCode version to 1.75.0 (PR: [#6711](https://github.com/dotnet/vscode-csharp/pull/6711))
* Update debugger docs to point to official documentation (PR: [#6674](https://github.com/dotnet/vscode-csharp/pull/6674))

## 2.12.19
* Update Roslyn to 4.9.0-2.23571.2 (PR: [#6681](https://github.com/dotnet/vscode-csharp/pull/6681))
* Workaround vscode bug with returning defaultBehavior from prepareRename (PR: [#70840](https://github.com/dotnet/roslyn/pull/70840))
* Implement textDocument/prepareRename to show error in invalid rename locations (PR: [#70724](https://github.com/dotnet/roslyn/pull/70724))
Expand Down
364 changes: 2 additions & 362 deletions debugger-launchjson.md

Large diffs are not rendered by default.

44 changes: 9 additions & 35 deletions debugger.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
# Instructions for setting up the .NET Core debugger
This page gives you detailed instructions on how to debug code running under .NET Core in VS Code.
## .NET Debugging in Visual Studio Code

#### Your Feedback​
File bugs and feature requests [here](https://github.com/dotnet/vscode-csharp/issues) to help us build great tooling for .NET Core.
While it is possible to use the C# extension as a standalone extension, we highly recommend using [C# Dev Kit](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp). When using C# Dev Kit, the [official C# debugger documentation](https://code.visualstudio.com/docs/csharp/debugging) and the [official getting started guide](https://code.visualstudio.com/docs/csharp/getting-started) should be used instead of this page.

## Getting started debugging without C# Dev Kit

This guide provides information on getting started with .NET debugging when using the C# extension without C# Dev Kit.

### First Time setup
##### 1: Get Visual Studio Code
Install Visual Studio Code (VS Code). Pick the latest VS Code version from here: https://code.visualstudio.com

##### 2: Install .NET command line tools
Install the .NET Core command line tools (CLI) by following the installation part of the instructions here: https://dotnet.microsoft.com/download
Install the .NET command line tools (CLI) by following the installation part of the instructions here: https://dotnet.microsoft.com/download

##### 3: Install C# Extension for VS Code
Open the command palette in VS Code (press <kbd>F1</kbd>) and run `Extensions: Install Extensions`. Enter `C#` in the search box and press `Enter`. Select the extension and click on `Install`.

If you have previously installed the C# extension, make sure that you have a recent version. You can check this by opening the command palette (press <kbd>F1</kbd>) and running `Extensions: Show Installed Extensions`.

##### 4: Wait for download of platform-specific files
The first time that C# code is opened in VS Code, the extension will download the platform-specific files needed for debugging and editing. Debugging and editor features will not work until these steps finish.


### Once for each project
The following steps have to be executed for every project.
##### 1: Get a project
Expand Down Expand Up @@ -73,37 +71,13 @@ If your code was built on a different computer from where you would like to run
#### [Configurating launch.json for C# Debugging](debugger-launchjson.md)

#### Attach Support
The C# debugger supports attaching to processes. To do this, switch to the Debug tab, and open the configuration drop down.

![Debug launch configuration drop down](https://raw.githubusercontent.com/wiki/dotnet/vscode-csharp/images/debug-launch-configurations.png)

Select the '.NET Core Attach' configuration. Clicking the play button (or pressing <kbd>F5</kbd>) will then try to attach. In launch.json, if `processId` is set to `""` this will provide UI to select which process to attach to.
See the [official documentation](https://code.visualstudio.com/docs/csharp/debugging#_attaching-to-a-process).

#### Remote Debugging

The debugger supports remotely launching or attaching to processes. See [Attaching to remote processes](https://github.com/dotnet/vscode-csharp/wiki/Attaching-to-remote-processes) in the wiki for more information.

#### Exception Settings

The VS Code .NET debugger supports configuration options for if the debugger stops when exceptions are thrown or caught. This is done through two different entries in the BREAKPOINTS section of the Run view:

![Exceptions settings in BREAKPOINTS Run View](https://raw.githubusercontent.com/wiki/dotnet/vscode-csharp/images/Exception-Settings.png)

Note that the BREAKPOINTS section will be missing these entries until the first time that the folder has been debugged with the .NET debugger.

Checking 'All Exceptions' will configure the debugger to stop when an exception is thrown. If Just My Code is enabled (which it is by default) the debugger will not break if an exception is internally thrown and caught in library code. Though if the exception is thrown in library code and returned to user code the debugger will break then.

Checking 'User-Unhandled Exceptions' will configure the debugger to stop when an exception is caught in non-user code after having been thrown in user code or traveled through user code. Exceptions that become user-unhandled aren't always a problem, it could be that user code is implementing an API and is expected to raise an exception in this scenario, but it is often a problem. So, by default, the debugger will stop when an exception becomes user-unhandled.

##### Exception Conditions
Both checkboxes support conditions to break on only selected exception types. To edit the condition, click on the pencil icon (see image above) or right click on the entry and invoke 'Edit Condition'. The condition is a comma-separated list of exception types to break on, or if the list starts with '!', a list of exception types to ignore.

Examples conditions:

| Example condition value | Result |
|-------------------------|--------|
| System.NullReferenceException | This will break on just null reference exceptions. |
| System.NullReferenceException, System.InvalidOperationException | This will break on both null reference exceptions and invalid operation exceptions. |
| !System.Threading.Tasks.TaskCanceledException | This will break on all exceptions except for task canceled. |
| !System.Threading.Tasks.TaskCanceledException, System.NotImplementedException | This will break on all exceptions except for task cancelled and not implemented. |

See the [official documentation](https://code.visualstudio.com/docs/csharp/debugging#_stopping-on-exceptions).
20 changes: 7 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
}
},
"defaults": {
"roslyn": "4.9.0-2.23571.2",
"roslyn": "4.9.0-3.23604.10",
"omniSharp": "1.39.10",
"razor": "7.0.0-preview.23528.1",
"razorOmnisharp": "7.0.0-preview.23363.1",
Expand Down Expand Up @@ -1014,7 +1014,7 @@
}
],
"engines": {
"vscode": "^1.73.0"
"vscode": "^1.75.0"
},
"activationEvents": [
"onDebugInitialConfigurations",
Expand All @@ -1023,18 +1023,7 @@
"onDebugResolve:clr",
"onDebugResolve:dotnet",
"onLanguage:csharp",
"onLanguage:aspnetcorerazor",
"onCommand:o.restart",
"onCommand:o.pickProjectAndStart",
"onCommand:o.showOutput",
"onCommand:dotnet.restore.project",
"onCommand:dotnet.restore.all",
"onCommand:dotnet.generateAssets",
"onCommand:dotnet.openSolution",
"onCommand:csharp.downloadDebugger",
"onCommand:csharp.listProcess",
"onCommand:csharp.listRemoteProcess",
"onCommand:csharp.listRemoteDockerProcess",
"onCommand:omnisharp.registerLanguageMiddleware",
"workspaceContains:project.json",
"workspaceContains:**/*.{csproj,sln,slnf,csx,cake}"
Expand Down Expand Up @@ -1742,6 +1731,11 @@
"default": null,
"description": "Sets a path where MSBuild binary logs are written to when loading projects, to help diagnose loading errors."
},
"dotnet.projects.enableAutomaticRestore": {
"type": "boolean",
"default": true,
"description": "%configuration.dotnet.projects.enableAutomaticRestore%"
},
"razor.languageServer.directory": {
"type": "string",
"scope": "machine-overridable",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"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.server.crashDumpPath": "Sets a folder path where crash dumps are written to if the language server crashes. Must be writeable by the user.",
"configuration.dotnet.projects.enableAutomaticRestore": "Enables automatic NuGet restore if the extension detects assets are missing.",
"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)",
"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.",
Expand Down
28 changes: 21 additions & 7 deletions src/lsptoolshost/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@

import * as vscode from 'vscode';
import { RoslynLanguageServer } from './roslynLanguageServer';
import { RestorableProjects, RestoreParams, RestorePartialResult, RestoreRequest } from './roslynProtocol';
import {
RestorableProjects,
RestoreParams,
RestorePartialResult,
RestoreRequest,
ProjectHasUnresolvedDependenciesRequest,
} from './roslynProtocol';
import path = require('path');

let _restoreInProgress = false;
Expand All @@ -22,10 +28,15 @@ export function registerRestoreCommands(
);
context.subscriptions.push(
vscode.commands.registerCommand('dotnet.restore.all', async (): Promise<void> => {
return restore(languageServer, restoreChannel);
return restore(languageServer, restoreChannel, [], true);
})
);

languageServer.registerOnRequest(ProjectHasUnresolvedDependenciesRequest.type, async (params) => {
await restore(languageServer, restoreChannel, params.projectFilePaths, false);
});
}

async function chooseProjectAndRestore(
languageServer: RoslynLanguageServer,
restoreChannel: vscode.OutputChannel
Expand All @@ -49,22 +60,25 @@ async function chooseProjectAndRestore(
return;
}

await restore(languageServer, restoreChannel, pickedItem.description);
await restore(languageServer, restoreChannel, [pickedItem.description!], true);
}

async function restore(
export async function restore(
languageServer: RoslynLanguageServer,
restoreChannel: vscode.OutputChannel,
projectFile?: string
projectFiles: string[],
showOutput: boolean
): Promise<void> {
if (_restoreInProgress) {
vscode.window.showErrorMessage(vscode.l10n.t('Restore already in progress'));
return;
}
_restoreInProgress = true;
restoreChannel.show(true);
if (showOutput) {
restoreChannel.show(true);
}

const request: RestoreParams = { projectFilePath: projectFile };
const request: RestoreParams = { projectFilePaths: projectFiles };
await vscode.window
.withProgress(
{
Expand Down
8 changes: 8 additions & 0 deletions src/lsptoolshost/roslynLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
MessageTransports,
RAL,
CancellationToken,
RequestHandler,
} from 'vscode-languageclient/node';
import { PlatformInformation } from '../shared/platform';
import { readConfigurations } from './configurationMiddleware';
Expand Down Expand Up @@ -319,6 +320,13 @@ export class RoslynLanguageServer {
return response;
}

public registerOnRequest<Params, Result, Error>(
type: RequestType<Params, Result, Error>,
handler: RequestHandler<Params, Result, Error>
) {
this._languageClient.addDisposable(this._languageClient.onRequest(type, handler));
}

public async registerSolutionSnapshot(token: vscode.CancellationToken): Promise<SolutionSnapshotId> {
const response = await this.sendRequest0(RoslynProtocol.RegisterSolutionSnapshotRequest.type, token);
if (response) {
Expand Down
19 changes: 16 additions & 3 deletions src/lsptoolshost/roslynProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,24 @@ export interface NamedPipeInformation {

export interface RestoreParams extends lsp.WorkDoneProgressParams, lsp.PartialResultParams {
/**
* An optional file path to restore.
* If none is specified, the solution (or all loaded projects) are restored.
* The set of projects to restore.
* If none are specified, the solution (or all loaded projects) are restored.
*/
projectFilePath?: string;
projectFilePaths: string[];
}

export interface RestorePartialResult {
stage: string;
message: string;
}

export interface UnresolvedProjectDependenciesParams {
/**
* The set of projects that have unresolved dependencies and require a restore.
*/
projectFilePaths: string[];
}

export namespace WorkspaceDebugConfigurationRequest {
export const method = 'workspace/debugConfiguration';
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.clientToServer;
Expand Down Expand Up @@ -260,3 +267,9 @@ export namespace RestorableProjects {
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.clientToServer;
export const type = new lsp.RequestType0<string[], void>(method);
}

export namespace ProjectHasUnresolvedDependenciesRequest {
export const method = 'workspace/_roslyn_projectHasUnresolvedDependencies';
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.serverToClient;
export const type = new lsp.RequestType<UnresolvedProjectDependenciesParams, void, void>(method);
}
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ export async function activate(
// ensure it gets properly disposed. Upon disposal the events will be flushed.
context.subscriptions.push(reporter);

const csharpChannel = vscode.window.createOutputChannel('C#');
const dotnetTestChannel = vscode.window.createOutputChannel('.NET Test Log');
const dotnetChannel = vscode.window.createOutputChannel('.NET NuGet Restore');
const csharpChannel = vscode.window.createOutputChannel('C#');
const csharpchannelObserver = new CsharpChannelObserver(csharpChannel);
const csharpLogObserver = new CsharpLoggerObserver(csharpChannel);
eventStream.subscribe(csharpchannelObserver.post);
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "2.12",
"version": "2.13",
"publicReleaseRefSpec": [
"^refs/heads/release$",
"^refs/heads/main$",
Expand Down

0 comments on commit ee6980f

Please sign in to comment.