Skip to content

Commit 7976f10

Browse files
authored
Merge pull request #6676 from dibarbet/automatic_nuget_restore
Enable automatic nuget restore on the client
2 parents f43e588 + 407106e commit 7976f10

File tree

7 files changed

+62
-12
lines changed

7 files changed

+62
-12
lines changed

CHANGELOG.md

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

88
## Latest
9+
* Update Roslyn to 4.9.0-3.23604.10 (PR: [#6676](https://github.com/dotnet/vscode-csharp/pull/6676))
10+
* Pass through folders for additional files (PR: [#71061](https://github.com/dotnet/roslyn/pull/71061))
11+
* Automatically detect missing NuGet packages and restore (PR: [#70851](https://github.com/dotnet/roslyn/pull/70851))
12+
* Enable route embedded language features in vscode (PR: [#70927](https://github.com/dotnet/roslyn/pull/70927))
13+
* Add automatic nuget restore support to C# standalone (PR: [#6676](https://github.com/dotnet/vscode-csharp/pull/6676))
14+
* Update required VSCode version to 1.75.0 (PR: [#6711](https://github.com/dotnet/vscode-csharp/pull/6711))
15+
* Update debugger docs to point to official documentation (PR: [#6674](https://github.com/dotnet/vscode-csharp/pull/6674))
16+
17+
## 2.12.19
918
* Update Roslyn to 4.9.0-2.23571.2 (PR: [#6681](https://github.com/dotnet/vscode-csharp/pull/6681))
1019
* Workaround vscode bug with returning defaultBehavior from prepareRename (PR: [#70840](https://github.com/dotnet/roslyn/pull/70840))
1120
* Implement textDocument/prepareRename to show error in invalid rename locations (PR: [#70724](https://github.com/dotnet/roslyn/pull/70724))

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
}
3838
},
3939
"defaults": {
40-
"roslyn": "4.9.0-2.23571.2",
40+
"roslyn": "4.9.0-3.23604.10",
4141
"omniSharp": "1.39.10",
4242
"razor": "7.0.0-preview.23528.1",
4343
"razorOmnisharp": "7.0.0-preview.23363.1",
@@ -1731,6 +1731,11 @@
17311731
"default": null,
17321732
"description": "Sets a path where MSBuild binary logs are written to when loading projects, to help diagnose loading errors."
17331733
},
1734+
"dotnet.projects.enableAutomaticRestore": {
1735+
"type": "boolean",
1736+
"default": true,
1737+
"description": "%configuration.dotnet.projects.enableAutomaticRestore%"
1738+
},
17341739
"razor.languageServer.directory": {
17351740
"type": "string",
17361741
"scope": "machine-overridable",

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"configuration.dotnet.server.trace": "Sets the logging level for the language server",
3232
"configuration.dotnet.server.extensionPaths": "Override for path to language server --extension arguments",
3333
"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.",
34+
"configuration.dotnet.projects.enableAutomaticRestore": "Enables automatic NuGet restore if the extension detects assets are missing.",
3435
"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)",
3536
"configuration.dotnet.implementType.insertionBehavior": "The insertion location of properties, events, and methods When implement interface or abstract class.",
3637
"configuration.dotnet.implementType.insertionBehavior.withOtherMembersOfTheSameKind": "Place them with other members of the same kind.",

src/lsptoolshost/restore.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55

66
import * as vscode from 'vscode';
77
import { RoslynLanguageServer } from './roslynLanguageServer';
8-
import { RestorableProjects, RestoreParams, RestorePartialResult, RestoreRequest } from './roslynProtocol';
8+
import {
9+
RestorableProjects,
10+
RestoreParams,
11+
RestorePartialResult,
12+
RestoreRequest,
13+
ProjectHasUnresolvedDependenciesRequest,
14+
} from './roslynProtocol';
915
import path = require('path');
1016

1117
let _restoreInProgress = false;
@@ -22,10 +28,15 @@ export function registerRestoreCommands(
2228
);
2329
context.subscriptions.push(
2430
vscode.commands.registerCommand('dotnet.restore.all', async (): Promise<void> => {
25-
return restore(languageServer, restoreChannel);
31+
return restore(languageServer, restoreChannel, [], true);
2632
})
2733
);
34+
35+
languageServer.registerOnRequest(ProjectHasUnresolvedDependenciesRequest.type, async (params) => {
36+
await restore(languageServer, restoreChannel, params.projectFilePaths, false);
37+
});
2838
}
39+
2940
async function chooseProjectAndRestore(
3041
languageServer: RoslynLanguageServer,
3142
restoreChannel: vscode.OutputChannel
@@ -49,22 +60,25 @@ async function chooseProjectAndRestore(
4960
return;
5061
}
5162

52-
await restore(languageServer, restoreChannel, pickedItem.description);
63+
await restore(languageServer, restoreChannel, [pickedItem.description!], true);
5364
}
5465

55-
async function restore(
66+
export async function restore(
5667
languageServer: RoslynLanguageServer,
5768
restoreChannel: vscode.OutputChannel,
58-
projectFile?: string
69+
projectFiles: string[],
70+
showOutput: boolean
5971
): Promise<void> {
6072
if (_restoreInProgress) {
6173
vscode.window.showErrorMessage(vscode.l10n.t('Restore already in progress'));
6274
return;
6375
}
6476
_restoreInProgress = true;
65-
restoreChannel.show(true);
77+
if (showOutput) {
78+
restoreChannel.show(true);
79+
}
6680

67-
const request: RestoreParams = { projectFilePath: projectFile };
81+
const request: RestoreParams = { projectFilePaths: projectFiles };
6882
await vscode.window
6983
.withProgress(
7084
{

src/lsptoolshost/roslynLanguageServer.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
MessageTransports,
2828
RAL,
2929
CancellationToken,
30+
RequestHandler,
3031
} from 'vscode-languageclient/node';
3132
import { PlatformInformation } from '../shared/platform';
3233
import { readConfigurations } from './configurationMiddleware';
@@ -319,6 +320,13 @@ export class RoslynLanguageServer {
319320
return response;
320321
}
321322

323+
public registerOnRequest<Params, Result, Error>(
324+
type: RequestType<Params, Result, Error>,
325+
handler: RequestHandler<Params, Result, Error>
326+
) {
327+
this._languageClient.addDisposable(this._languageClient.onRequest(type, handler));
328+
}
329+
322330
public async registerSolutionSnapshot(token: vscode.CancellationToken): Promise<SolutionSnapshotId> {
323331
const response = await this.sendRequest0(RoslynProtocol.RegisterSolutionSnapshotRequest.type, token);
324332
if (response) {

src/lsptoolshost/roslynProtocol.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,24 @@ export interface NamedPipeInformation {
152152

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

161161
export interface RestorePartialResult {
162162
stage: string;
163163
message: string;
164164
}
165165

166+
export interface UnresolvedProjectDependenciesParams {
167+
/**
168+
* The set of projects that have unresolved dependencies and require a restore.
169+
*/
170+
projectFilePaths: string[];
171+
}
172+
166173
export namespace WorkspaceDebugConfigurationRequest {
167174
export const method = 'workspace/debugConfiguration';
168175
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.clientToServer;
@@ -260,3 +267,9 @@ export namespace RestorableProjects {
260267
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.clientToServer;
261268
export const type = new lsp.RequestType0<string[], void>(method);
262269
}
270+
271+
export namespace ProjectHasUnresolvedDependenciesRequest {
272+
export const method = 'workspace/_roslyn_projectHasUnresolvedDependencies';
273+
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.serverToClient;
274+
export const type = new lsp.RequestType<UnresolvedProjectDependenciesParams, void, void>(method);
275+
}

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ export async function activate(
8383
// ensure it gets properly disposed. Upon disposal the events will be flushed.
8484
context.subscriptions.push(reporter);
8585

86-
const csharpChannel = vscode.window.createOutputChannel('C#');
8786
const dotnetTestChannel = vscode.window.createOutputChannel('.NET Test Log');
8887
const dotnetChannel = vscode.window.createOutputChannel('.NET NuGet Restore');
88+
const csharpChannel = vscode.window.createOutputChannel('C#');
8989
const csharpchannelObserver = new CsharpChannelObserver(csharpChannel);
9090
const csharpLogObserver = new CsharpLoggerObserver(csharpChannel);
9191
eventStream.subscribe(csharpchannelObserver.post);

0 commit comments

Comments
 (0)