Skip to content

Commit 94d8046

Browse files
committed
Handle restore on the server
1 parent 11939a0 commit 94d8046

File tree

3 files changed

+20
-91
lines changed

3 files changed

+20
-91
lines changed

l10n/bundle.l10n.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@
190190
"Suppress notification": "Suppress notification",
191191
"Restore {0}": "Restore {0}",
192192
"Restore already in progress": "Restore already in progress",
193-
"Sending request": "Sending request",
194193
"C# Project Context Status": "C# Project Context Status",
195194
"Active File Context": "Active File Context",
196195
"Initializing dotnet-trace.../dotnet-trace is a command name and should not be localized": {

src/lsptoolshost/projectRestore/restore.ts

Lines changed: 17 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,11 @@
55

66
import * as vscode from 'vscode';
77
import { RoslynLanguageServer } from '../server/roslynLanguageServer';
8-
import {
9-
RestorableProjects,
10-
RestoreParams,
11-
RestorePartialResult,
12-
RestoreRequest,
13-
ProjectNeedsRestoreRequest,
14-
} from '../server/roslynProtocol';
8+
import { RestorableProjects, RestoreParams, RestoreRequest } from '../server/roslynProtocol';
159
import path from 'path';
1610
import { showErrorMessage } from '../../shared/observers/utils/showMessage';
1711
import { getCSharpDevKit } from '../../utils/getCSharpDevKit';
12+
import { CancellationToken } from 'vscode-jsonrpc';
1813

1914
let _restoreInProgress = false;
2015

@@ -32,33 +27,10 @@ export function registerRestoreCommands(
3227
);
3328
context.subscriptions.push(
3429
vscode.commands.registerCommand('dotnet.restore.all', async (): Promise<void> => {
35-
return restore(languageServer, csharpOutputChannel, [], true);
30+
return restore(languageServer, csharpOutputChannel, []);
3631
})
3732
);
3833
}
39-
40-
languageServer.registerOnRequest(ProjectNeedsRestoreRequest.type, async (params) => {
41-
let projectFilePaths = params.projectFilePaths;
42-
if (getCSharpDevKit()) {
43-
// Only restore '.cs' files (file-based apps) if CDK is loaded.
44-
const csharpFiles = [];
45-
for (const path of projectFilePaths) {
46-
if (path.endsWith('.cs')) {
47-
csharpFiles.push(path);
48-
} else {
49-
csharpOutputChannel.debug(
50-
`[.NET Restore] Not restoring '${path}' from C# extension, because C# Dev Kit is expected to handle restore for it.`
51-
);
52-
}
53-
}
54-
55-
projectFilePaths = csharpFiles;
56-
}
57-
58-
if (projectFilePaths.length > 0) {
59-
await restore(languageServer, csharpOutputChannel, params.projectFilePaths, false);
60-
}
61-
});
6234
}
6335

6436
async function chooseProjectAndRestore(
@@ -93,63 +65,34 @@ async function chooseProjectAndRestore(
9365
return;
9466
}
9567

96-
await restore(languageServer, outputChannel, [pickedItem.description!], true);
68+
await restore(languageServer, outputChannel, [pickedItem.description!]);
9769
}
9870

9971
export async function restore(
10072
languageServer: RoslynLanguageServer,
10173
outputChannel: vscode.LogOutputChannel,
102-
projectFiles: string[],
103-
showOutput: boolean
74+
projectFiles: string[]
10475
): Promise<void> {
10576
if (_restoreInProgress) {
10677
showErrorMessage(vscode, vscode.l10n.t('Restore already in progress'));
10778
return;
10879
}
10980
_restoreInProgress = true;
110-
if (showOutput) {
111-
outputChannel.show(true);
112-
}
81+
outputChannel.show(true);
11382

11483
const request: RestoreParams = { projectFilePaths: projectFiles };
115-
await vscode.window
116-
.withProgress(
117-
{
118-
location: vscode.ProgressLocation.Notification,
119-
title: vscode.l10n.t('Restore'),
120-
cancellable: true,
121-
},
122-
async (progress, token) => {
123-
const writeOutput = (output: RestorePartialResult) => {
124-
if (output.message) {
125-
outputChannel.debug(`[.NET Restore] ${output.message}`);
126-
}
127-
128-
progress.report({ message: output.stage });
129-
};
130-
131-
progress.report({ message: vscode.l10n.t('Sending request') });
132-
const responsePromise = languageServer.sendRequestWithProgress(
133-
RestoreRequest.type,
134-
request,
135-
async (p) => writeOutput(p),
136-
token
137-
);
13884

139-
await responsePromise.then(
140-
(result) => result.forEach((r) => writeOutput(r)),
141-
(err) => outputChannel.error(`[.NET Restore] ${err}`)
142-
);
143-
}
144-
)
145-
.then(
146-
() => {
147-
_restoreInProgress = false;
148-
},
149-
() => {
150-
_restoreInProgress = false;
151-
}
152-
);
85+
// server will show a work done progress with cancellation. no need to pass a token to the request.
86+
const resultPromise = languageServer.sendRequest(RestoreRequest.type, request, CancellationToken.None).then(
87+
() => {
88+
_restoreInProgress = false;
89+
},
90+
(err) => {
91+
outputChannel.error(`[.NET Restore] ${err}`);
92+
_restoreInProgress = false;
93+
}
94+
);
15395

96+
await resultPromise;
15497
return;
15598
}

src/lsptoolshost/server/roslynProtocol.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,8 @@ export interface RestoreParams extends WorkDoneProgressParams, PartialResultPara
227227
projectFilePaths: string[];
228228
}
229229

230-
export interface RestorePartialResult {
231-
stage: string;
232-
message: string;
230+
export interface RestoreResult {
231+
success: boolean;
233232
}
234233

235234
export interface ProjectNeedsRestoreName {
@@ -345,13 +344,7 @@ export namespace CodeActionFixAllResolveRequest {
345344
export namespace RestoreRequest {
346345
export const method = 'workspace/_roslyn_restore';
347346
export const messageDirection: MessageDirection = MessageDirection.clientToServer;
348-
export const type = new ProtocolRequestType<
349-
RestoreParams,
350-
RestorePartialResult[],
351-
RestorePartialResult,
352-
void,
353-
void
354-
>(method);
347+
export const type = new RequestType<RestoreParams, RestoreResult, void>(method);
355348
}
356349

357350
export namespace RestorableProjects {
@@ -360,12 +353,6 @@ export namespace RestorableProjects {
360353
export const type = new RequestType0<string[], void>(method);
361354
}
362355

363-
export namespace ProjectNeedsRestoreRequest {
364-
export const method = 'workspace/_roslyn_projectNeedsRestore';
365-
export const messageDirection: MessageDirection = MessageDirection.serverToClient;
366-
export const type = new RequestType<ProjectNeedsRestoreName, void, void>(method);
367-
}
368-
369356
export namespace CopilotRelatedDocumentsRequest {
370357
export const method = 'copilot/_related_documents';
371358
export const messageDirection: MessageDirection = MessageDirection.clientToServer;

0 commit comments

Comments
 (0)