Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@
"Suppress notification": "Suppress notification",
"Restore {0}": "Restore {0}",
"Restore already in progress": "Restore already in progress",
"Sending request": "Sending request",
"C# Project Context Status": "C# Project Context Status",
"Active File Context": "Active File Context",
"Initializing dotnet-trace.../dotnet-trace is a command name and should not be localized": {
Expand Down
91 changes: 17 additions & 74 deletions src/lsptoolshost/projectRestore/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@

import * as vscode from 'vscode';
import { RoslynLanguageServer } from '../server/roslynLanguageServer';
import {
RestorableProjects,
RestoreParams,
RestorePartialResult,
RestoreRequest,
ProjectNeedsRestoreRequest,
} from '../server/roslynProtocol';
import { RestorableProjects, RestoreParams, RestoreRequest } from '../server/roslynProtocol';
import path from 'path';
import { showErrorMessage } from '../../shared/observers/utils/showMessage';
import { getCSharpDevKit } from '../../utils/getCSharpDevKit';
import { CancellationToken } from 'vscode-jsonrpc';

let _restoreInProgress = false;

Expand All @@ -32,33 +27,10 @@ export function registerRestoreCommands(
);
context.subscriptions.push(
vscode.commands.registerCommand('dotnet.restore.all', async (): Promise<void> => {
return restore(languageServer, csharpOutputChannel, [], true);
return restore(languageServer, csharpOutputChannel, []);
})
);
}

languageServer.registerOnRequest(ProjectNeedsRestoreRequest.type, async (params) => {
let projectFilePaths = params.projectFilePaths;
if (getCSharpDevKit()) {
// Only restore '.cs' files (file-based apps) if CDK is loaded.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really nice to delete this also.

const csharpFiles = [];
for (const path of projectFilePaths) {
if (path.endsWith('.cs')) {
csharpFiles.push(path);
} else {
csharpOutputChannel.debug(
`[.NET Restore] Not restoring '${path}' from C# extension, because C# Dev Kit is expected to handle restore for it.`
);
}
}

projectFilePaths = csharpFiles;
}

if (projectFilePaths.length > 0) {
await restore(languageServer, csharpOutputChannel, params.projectFilePaths, false);
}
});
}

async function chooseProjectAndRestore(
Expand Down Expand Up @@ -93,63 +65,34 @@ async function chooseProjectAndRestore(
return;
}

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

export async function restore(
languageServer: RoslynLanguageServer,
outputChannel: vscode.LogOutputChannel,
projectFiles: string[],
showOutput: boolean
projectFiles: string[]
): Promise<void> {
if (_restoreInProgress) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now this tracks only restores initiated by the client. Parallel restores on different things are still permitted on the server side. Perhaps that is what we want? At least there doesn't seem to be a need to make a change to that in this PR.

Copy link
Member Author

@dibarbet dibarbet Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right. don't want really multiple manually initiated restores running at once. But server can run automatic restores for diff projects

showErrorMessage(vscode, vscode.l10n.t('Restore already in progress'));
return;
}
_restoreInProgress = true;
if (showOutput) {
outputChannel.show(true);
}
outputChannel.show(true);

const request: RestoreParams = { projectFilePaths: projectFiles };
await vscode.window
.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: vscode.l10n.t('Restore'),
cancellable: true,
},
async (progress, token) => {
const writeOutput = (output: RestorePartialResult) => {
if (output.message) {
outputChannel.debug(`[.NET Restore] ${output.message}`);
}

progress.report({ message: output.stage });
};

progress.report({ message: vscode.l10n.t('Sending request') });
const responsePromise = languageServer.sendRequestWithProgress(
RestoreRequest.type,
request,
async (p) => writeOutput(p),
token
);

await responsePromise.then(
(result) => result.forEach((r) => writeOutput(r)),
(err) => outputChannel.error(`[.NET Restore] ${err}`)
);
}
)
.then(
() => {
_restoreInProgress = false;
},
() => {
_restoreInProgress = false;
}
);
// server will show a work done progress with cancellation. no need to pass a token to the request.
const resultPromise = languageServer.sendRequest(RestoreRequest.type, request, CancellationToken.None).then(
() => {
_restoreInProgress = false;
},
(err) => {
outputChannel.error(`[.NET Restore] ${err}`);
_restoreInProgress = false;
}
);

await resultPromise;
return;
}
19 changes: 3 additions & 16 deletions src/lsptoolshost/server/roslynProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,8 @@ export interface RestoreParams extends WorkDoneProgressParams, PartialResultPara
projectFilePaths: string[];
}

export interface RestorePartialResult {
stage: string;
message: string;
export interface RestoreResult {
success: boolean;
}

export interface ProjectNeedsRestoreName {
Expand Down Expand Up @@ -336,13 +335,7 @@ export namespace CodeActionFixAllResolveRequest {
export namespace RestoreRequest {
export const method = 'workspace/_roslyn_restore';
export const messageDirection: MessageDirection = MessageDirection.clientToServer;
export const type = new ProtocolRequestType<
RestoreParams,
RestorePartialResult[],
RestorePartialResult,
void,
void
>(method);
export const type = new RequestType<RestoreParams, RestoreResult, void>(method);
}

export namespace RestorableProjects {
Expand All @@ -351,12 +344,6 @@ export namespace RestorableProjects {
export const type = new RequestType0<string[], void>(method);
}

export namespace ProjectNeedsRestoreRequest {
export const method = 'workspace/_roslyn_projectNeedsRestore';
export const messageDirection: MessageDirection = MessageDirection.serverToClient;
export const type = new RequestType<ProjectNeedsRestoreName, void, void>(method);
}

export namespace SourceGeneratorGetTextRequest {
export const method = 'sourceGeneratedDocument/_roslyn_getText';
export const messageDirection: MessageDirection = MessageDirection.clientToServer;
Expand Down
Loading