@@ -39,6 +39,7 @@ import {
3939 CompletionItem ,
4040 PartialResultParams ,
4141 ProtocolRequestType ,
42+ MessageType ,
4243} from 'vscode-languageclient/node' ;
4344import { PlatformInformation } from '../shared/platform' ;
4445import { 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
0 commit comments