Skip to content

Commit 8dc2b9c

Browse files
authored
Merge pull request #6060 from dibarbet/show_project_load_error
Show toast when project loading fails
2 parents cb5f4d3 + 0631bb6 commit 8dc2b9c

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
}
3737
},
3838
"defaults": {
39-
"roslyn": "4.8.0-1.23406.1",
39+
"roslyn": "4.8.0-1.23407.6",
4040
"omniSharp": "1.39.7",
4141
"razor": "7.0.0-preview.23405.1",
4242
"razorOmnisharp": "7.0.0-preview.23363.1"

src/lsptoolshost/commands.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export function registerCommands(
1717
context: vscode.ExtensionContext,
1818
languageServer: RoslynLanguageServer,
1919
optionProvider: OptionProvider,
20-
hostExecutableResolver: IHostExecutableResolver
20+
hostExecutableResolver: IHostExecutableResolver,
21+
outputChannel: vscode.OutputChannel
2122
) {
2223
// It is very important to be careful about the types used as parameters for these command callbacks.
2324
// If the arguments are coming from the server as json, it is NOT appropriate to use type definitions
@@ -50,6 +51,9 @@ export function registerCommands(
5051
)
5152
)
5253
);
54+
context.subscriptions.push(
55+
vscode.commands.registerCommand('csharp.showOutputWindow', async () => outputChannel.show())
56+
);
5357
}
5458

5559
/**

src/lsptoolshost/roslynLanguageServer.ts

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
CompletionItem,
4040
PartialResultParams,
4141
ProtocolRequestType,
42+
MessageType,
4243
} from 'vscode-languageclient/node';
4344
import { PlatformInformation } from '../shared/platform';
4445
import { readConfigurations } from './configurationMiddleware';
@@ -198,6 +199,57 @@ export class RoslynLanguageServer {
198199
);
199200
});
200201

202+
this._languageClient.onNotification(RoslynProtocol.ShowToastNotification.type, async (notification) => {
203+
const messageOptions: vscode.MessageOptions = {
204+
modal: false,
205+
};
206+
const commands = notification.commands.map((command) => command.title);
207+
const executeCommandByName = async (result: string | undefined) => {
208+
if (result) {
209+
const command = notification.commands.find((command) => command.title === result);
210+
if (!command) {
211+
throw new Error(`Unknown command ${result}`);
212+
}
213+
214+
if (command.arguments) {
215+
await vscode.commands.executeCommand(command.command, ...command.arguments);
216+
} else {
217+
await vscode.commands.executeCommand(command.command);
218+
}
219+
}
220+
};
221+
222+
switch (notification.messageType) {
223+
case MessageType.Error: {
224+
const result = await vscode.window.showErrorMessage(
225+
notification.message,
226+
messageOptions,
227+
...commands
228+
);
229+
executeCommandByName(result);
230+
break;
231+
}
232+
case MessageType.Warning: {
233+
const result = await vscode.window.showWarningMessage(
234+
notification.message,
235+
messageOptions,
236+
...commands
237+
);
238+
executeCommandByName(result);
239+
break;
240+
}
241+
default: {
242+
const result = await vscode.window.showInformationMessage(
243+
notification.message,
244+
messageOptions,
245+
...commands
246+
);
247+
executeCommandByName(result);
248+
break;
249+
}
250+
}
251+
});
252+
201253
this.registerExtensionsChanged(this._languageClient);
202254
this.registerTelemetryChanged(this._languageClient);
203255

@@ -664,7 +716,7 @@ export async function activateRoslynLanguageServer(
664716
);
665717

666718
// Register any commands that need to be handled by the extension.
667-
registerCommands(context, _languageServer, optionProvider, hostExecutableResolver);
719+
registerCommands(context, _languageServer, optionProvider, hostExecutableResolver, _channel);
668720

669721
registerRazorCommands(context, _languageServer);
670722

src/lsptoolshost/roslynProtocol.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { Command } from 'vscode';
67
import * as lsp from 'vscode-languageserver-protocol';
78

89
export interface WorkspaceDebugConfigurationParams {
@@ -116,6 +117,12 @@ export interface DebugAttachResult {
116117
didAttach: boolean;
117118
}
118119

120+
export interface ShowToastNotificationParams {
121+
messageType: lsp.MessageType;
122+
message: string;
123+
commands: Command[];
124+
}
125+
119126
export namespace WorkspaceDebugConfigurationRequest {
120127
export const method = 'workspace/debugConfiguration';
121128
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.clientToServer;
@@ -142,6 +149,12 @@ export namespace ProjectInitializationCompleteNotification {
142149
export const type = new lsp.NotificationType(method);
143150
}
144151

152+
export namespace ShowToastNotification {
153+
export const method = 'window/_roslyn_showToast';
154+
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.serverToClient;
155+
export const type = new lsp.NotificationType<ShowToastNotificationParams>(method);
156+
}
157+
145158
export namespace RunTestsRequest {
146159
export const method = 'textDocument/runTests';
147160
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.clientToServer;

0 commit comments

Comments
 (0)