From cee0dbb60fc06ce5b57760d9cf44fb8e759742a1 Mon Sep 17 00:00:00 2001 From: David Barbet Date: Mon, 7 Aug 2023 11:46:44 -0700 Subject: [PATCH 1/3] Implement support for server side notification to show a toast with command --- src/lsptoolshost/commands.ts | 6 ++- src/lsptoolshost/roslynLanguageServer.ts | 54 +++++++++++++++++++++++- src/lsptoolshost/roslynProtocol.ts | 13 ++++++ 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/lsptoolshost/commands.ts b/src/lsptoolshost/commands.ts index 7578321a4..8b3e8d25b 100644 --- a/src/lsptoolshost/commands.ts +++ b/src/lsptoolshost/commands.ts @@ -17,7 +17,8 @@ export function registerCommands( context: vscode.ExtensionContext, languageServer: RoslynLanguageServer, optionProvider: OptionProvider, - hostExecutableResolver: IHostExecutableResolver + hostExecutableResolver: IHostExecutableResolver, + outputChannel: vscode.OutputChannel ) { // It is very important to be careful about the types used as parameters for these command callbacks. // 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( ) ) ); + context.subscriptions.push( + vscode.commands.registerCommand('csharp.showOutputWindow', async () => outputChannel.show()) + ); } /** diff --git a/src/lsptoolshost/roslynLanguageServer.ts b/src/lsptoolshost/roslynLanguageServer.ts index 08a0b11e2..5403dd342 100644 --- a/src/lsptoolshost/roslynLanguageServer.ts +++ b/src/lsptoolshost/roslynLanguageServer.ts @@ -39,6 +39,7 @@ import { CompletionItem, PartialResultParams, ProtocolRequestType, + MessageType, } from 'vscode-languageclient/node'; import { PlatformInformation } from '../shared/platform'; import { readConfigurations } from './configurationMiddleware'; @@ -198,6 +199,57 @@ export class RoslynLanguageServer { ); }); + this._languageClient.onNotification(RoslynProtocol.ShowToastNotification.type, async (notification) => { + const messageOptions: vscode.MessageOptions = { + modal: false, + }; + const commands = notification.commands.map((command) => command.title); + const executeCommandByName = async (result: string | undefined) => { + if (result) { + const command = notification.commands.find((command) => command.title === result); + if (!command) { + throw new Error(`Unknown command ${result}`); + } + + if (command.arguments) { + await vscode.commands.executeCommand(command.command, ...command.arguments); + } else { + await vscode.commands.executeCommand(command.command); + } + } + }; + + switch (notification.messageType) { + case MessageType.Error: { + const result = await vscode.window.showErrorMessage( + notification.message, + messageOptions, + ...commands + ); + executeCommandByName(result); + break; + } + case MessageType.Warning: { + const result = await vscode.window.showWarningMessage( + notification.message, + messageOptions, + ...commands + ); + executeCommandByName(result); + break; + } + default: { + const result = await vscode.window.showInformationMessage( + notification.message, + messageOptions, + ...commands + ); + executeCommandByName(result); + break; + } + } + }); + this.registerExtensionsChanged(this._languageClient); this.registerTelemetryChanged(this._languageClient); @@ -664,7 +716,7 @@ export async function activateRoslynLanguageServer( ); // Register any commands that need to be handled by the extension. - registerCommands(context, _languageServer, optionProvider, hostExecutableResolver); + registerCommands(context, _languageServer, optionProvider, hostExecutableResolver, _channel); registerRazorCommands(context, _languageServer); diff --git a/src/lsptoolshost/roslynProtocol.ts b/src/lsptoolshost/roslynProtocol.ts index e01b5d732..786026631 100644 --- a/src/lsptoolshost/roslynProtocol.ts +++ b/src/lsptoolshost/roslynProtocol.ts @@ -3,6 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import { Command } from 'vscode'; import * as lsp from 'vscode-languageserver-protocol'; export interface WorkspaceDebugConfigurationParams { @@ -116,6 +117,12 @@ export interface DebugAttachResult { didAttach: boolean; } +export interface ShowToastNotificationParams { + messageType: lsp.MessageType; + message: string; + commands: Command[]; +} + export namespace WorkspaceDebugConfigurationRequest { export const method = 'workspace/debugConfiguration'; export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.clientToServer; @@ -142,6 +149,12 @@ export namespace ProjectInitializationCompleteNotification { export const type = new lsp.NotificationType(method); } +export namespace ShowToastNotification { + export const method = 'window/showToast'; + export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.serverToClient; + export const type = new lsp.NotificationType(method); +} + export namespace RunTestsRequest { export const method = 'textDocument/runTests'; export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.clientToServer; From ec7922dbc47fcf794453cfc5240f78b37ee1ae47 Mon Sep 17 00:00:00 2001 From: David Barbet Date: Mon, 7 Aug 2023 15:28:53 -0700 Subject: [PATCH 2/3] Rename to _roslyn_ --- src/lsptoolshost/roslynProtocol.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lsptoolshost/roslynProtocol.ts b/src/lsptoolshost/roslynProtocol.ts index 786026631..b7f4d02e0 100644 --- a/src/lsptoolshost/roslynProtocol.ts +++ b/src/lsptoolshost/roslynProtocol.ts @@ -150,7 +150,7 @@ export namespace ProjectInitializationCompleteNotification { } export namespace ShowToastNotification { - export const method = 'window/showToast'; + export const method = 'window/_roslyn_showToast'; export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.serverToClient; export const type = new lsp.NotificationType(method); } From 2ba98ae120deae5cefa7b76986c717a133536530 Mon Sep 17 00:00:00 2001 From: David Barbet Date: Mon, 7 Aug 2023 18:38:21 -0700 Subject: [PATCH 3/3] Update roslyn version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f630962a7..2a8bba070 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ } }, "defaults": { - "roslyn": "4.8.0-1.23404.8", + "roslyn": "4.8.0-1.23407.6", "omniSharp": "1.39.7", "razor": "7.0.0-preview.23328.2", "razorOmnisharp": "7.0.0-preview.23363.1"