Skip to content

Commit b8a3c26

Browse files
committed
Enable automatic nuget restore on the client
1 parent b8bc637 commit b8a3c26

File tree

5 files changed

+51
-11
lines changed

5 files changed

+51
-11
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,6 +1742,11 @@
17421742
"default": null,
17431743
"description": "Sets a path where MSBuild binary logs are written to when loading projects, to help diagnose loading errors."
17441744
},
1745+
"dotnet.projects.enableAutomaticRestore": {
1746+
"type": "boolean",
1747+
"default": true,
1748+
"description": "Sets whether or not automatic nuget restore is enabled if the project system detects assets are missing."
1749+
},
17451750
"razor.languageServer.directory": {
17461751
"type": "string",
17471752
"scope": "machine-overridable",

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+
UnresolvedProjectDependenciesNotification,
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(UnresolvedProjectDependenciesNotification.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 UnresolvedProjectDependenciesNotification {
272+
export const method = 'workspace/_roslyn_unresolvedProjectDependencies';
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)