@@ -191,13 +191,13 @@ export class RoslynLanguageServer {
191
191
} ) ;
192
192
193
193
this . registerExtensionsChanged ( this . _languageClient ) ;
194
- this . registerTelemtryChanged ( this . _languageClient ) ;
194
+ this . registerTelemetryChanged ( this . _languageClient ) ;
195
195
196
196
// Start the client. This will also launch the server
197
197
this . _languageClient . start ( ) ;
198
198
199
199
// Register Razor dynamic file info handling
200
- this . registerRazor ( this . _languageClient ) ;
200
+ this . registerDynamicFileInfo ( this . _languageClient ) ;
201
201
}
202
202
203
203
public async stop ( ) : Promise < void > {
@@ -256,6 +256,18 @@ export class RoslynLanguageServer {
256
256
return response ;
257
257
}
258
258
259
+ /**
260
+ * Sends an LSP notification to the server with a given method and parameters.
261
+ */
262
+ public async sendNotification < Params > ( method : string , params : Params ) : Promise < any > {
263
+ if ( ! this . isRunning ( ) ) {
264
+ throw new Error ( 'Tried to send request while server is not started.' ) ;
265
+ }
266
+
267
+ let response = await this . _languageClient ! . sendNotification ( method , params ) ;
268
+ return response ;
269
+ }
270
+
259
271
public async registerSolutionSnapshot ( token : vscode . CancellationToken ) : Promise < SolutionSnapshotId > {
260
272
let response = await _languageServer . sendRequest0 ( RegisterSolutionSnapshotRequest . type , token ) ;
261
273
if ( response )
@@ -430,7 +442,7 @@ export class RoslynLanguageServer {
430
442
return childProcess ;
431
443
}
432
444
433
- private registerRazor ( client : RoslynLanguageClient ) {
445
+ private registerDynamicFileInfo ( client : RoslynLanguageClient ) {
434
446
// When the Roslyn language server sends a request for Razor dynamic file info, we forward that request along to Razor via
435
447
// a command.
436
448
client . onRequest (
@@ -439,43 +451,6 @@ export class RoslynLanguageServer {
439
451
client . onNotification (
440
452
RoslynLanguageServer . removeRazorDynamicFileInfoMethodName ,
441
453
async notification => vscode . commands . executeCommand ( DynamicFileInfoHandler . removeDynamicFileInfoCommand , notification ) ) ;
442
-
443
- // Razor will call into us (via command) for generated file didChange/didClose notifications. We'll then forward these
444
- // notifications along to Roslyn. didOpen notifications are handled separately via the vscode.openTextDocument method.
445
- client . addDisposable ( vscode . commands . registerCommand ( RoslynLanguageServer . roslynDidChangeCommand , ( notification : DidChangeTextDocumentParams ) => {
446
- client . sendNotification ( DidChangeTextDocumentNotification . method , notification ) ;
447
- } ) ) ;
448
- client . addDisposable ( vscode . commands . registerCommand ( RoslynLanguageServer . roslynDidCloseCommand , ( notification : DidCloseTextDocumentParams ) => {
449
- client . sendNotification ( DidCloseTextDocumentNotification . method , notification ) ;
450
- } ) ) ;
451
- client . addDisposable ( vscode . commands . registerCommand ( RoslynLanguageServer . roslynPullDiagnosticCommand , async ( request : DocumentDiagnosticParams ) => {
452
- let diagnosticRequestType = new RequestType < DocumentDiagnosticParams , DocumentDiagnosticReport , any > ( DocumentDiagnosticRequest . method ) ;
453
- return await this . sendRequest ( diagnosticRequestType , request , CancellationToken . None ) ;
454
- } ) ) ;
455
-
456
- // The VS Code API for code actions (and the vscode.CodeAction type) doesn't support everything that LSP supports,
457
- // namely the data property, which Razor needs to identify which code actions are on their allow list, so we need
458
- // to expose a command for them to directly invoke our code actions LSP endpoints, rather than use built-in commands.
459
- client . addDisposable ( vscode . commands . registerCommand ( RoslynLanguageServer . provideCodeActionsCommand , async ( request : CodeActionParams ) => {
460
- return await this . sendRequest ( CodeActionRequest . type , request , CancellationToken . None ) ;
461
- } ) ) ;
462
- client . addDisposable ( vscode . commands . registerCommand ( RoslynLanguageServer . resolveCodeActionCommand , async ( request : CodeAction ) => {
463
- return await this . sendRequest ( CodeActionResolveRequest . type , request , CancellationToken . None ) ;
464
- } ) ) ;
465
-
466
- client . addDisposable ( vscode . commands . registerCommand ( RoslynLanguageServer . provideCompletionsCommand , async ( request : CompletionParams ) => {
467
- return await this . sendRequest ( CompletionRequest . type , request , CancellationToken . None ) ;
468
- } ) ) ;
469
- client . addDisposable ( vscode . commands . registerCommand ( RoslynLanguageServer . resolveCompletionsCommand , async ( request : CompletionItem ) => {
470
- return await this . sendRequest ( CompletionResolveRequest . type , request , CancellationToken . None ) ;
471
- } ) ) ;
472
-
473
- // Roslyn is responsible for producing a json file containing information for Razor, that comes from the compilation for
474
- // a project. We want to defer this work until necessary, so this command is called by the Razor document manager to tell
475
- // us when they need us to initialize the Razor things.
476
- client . addDisposable ( vscode . commands . registerCommand ( RoslynLanguageServer . razorInitializeCommand , ( ) => {
477
- client . sendNotification ( "razor/initialize" , { } ) ;
478
- } ) ) ;
479
454
}
480
455
481
456
private registerExtensionsChanged ( languageClient : RoslynLanguageClient ) {
@@ -503,7 +478,7 @@ export class RoslynLanguageServer {
503
478
} ) ) ;
504
479
}
505
480
506
- private registerTelemtryChanged ( languageClient : RoslynLanguageClient ) {
481
+ private registerTelemetryChanged ( languageClient : RoslynLanguageClient ) {
507
482
// Subscribe to telemetry events so we can enable/disable as needed
508
483
languageClient . addDisposable ( vscode . env . onDidChangeTelemetryEnabled ( ( isEnabled : boolean ) => {
509
484
const title = 'Restart Language Server' ;
@@ -608,6 +583,8 @@ export async function activateRoslynLanguageServer(context: vscode.ExtensionCont
608
583
// Register any commands that need to be handled by the extension.
609
584
registerCommands ( context , _languageServer ) ;
610
585
586
+ registerRazorCommands ( context , _languageServer ) ;
587
+
611
588
// Register any needed debugger components that need to communicate with the language server.
612
589
registerDebugger ( context , _languageServer , platformInfo , optionProvider , _channel ) ;
613
590
@@ -646,6 +623,45 @@ export async function activateRoslynLanguageServer(context: vscode.ExtensionCont
646
623
_languageServer . start ( ) ;
647
624
}
648
625
626
+ function registerRazorCommands ( context : vscode . ExtensionContext , languageServer : RoslynLanguageServer ) {
627
+ // Razor will call into us (via command) for generated file didChange/didClose notifications. We'll then forward these
628
+ // notifications along to Roslyn. didOpen notifications are handled separately via the vscode.openTextDocument method.
629
+ context . subscriptions . push ( vscode . commands . registerCommand ( RoslynLanguageServer . roslynDidChangeCommand , async ( notification : DidChangeTextDocumentParams ) => {
630
+ await languageServer . sendNotification ( DidChangeTextDocumentNotification . method , notification ) ;
631
+ } ) ) ;
632
+ context . subscriptions . push ( vscode . commands . registerCommand ( RoslynLanguageServer . roslynDidCloseCommand , async ( notification : DidCloseTextDocumentParams ) => {
633
+ await languageServer . sendNotification ( DidCloseTextDocumentNotification . method , notification ) ;
634
+ } ) ) ;
635
+ context . subscriptions . push ( vscode . commands . registerCommand ( RoslynLanguageServer . roslynPullDiagnosticCommand , async ( request : DocumentDiagnosticParams ) => {
636
+ let diagnosticRequestType = new RequestType < DocumentDiagnosticParams , DocumentDiagnosticReport , any > ( DocumentDiagnosticRequest . method ) ;
637
+ return await languageServer . sendRequest ( diagnosticRequestType , request , CancellationToken . None ) ;
638
+ } ) ) ;
639
+
640
+ // The VS Code API for code actions (and the vscode.CodeAction type) doesn't support everything that LSP supports,
641
+ // namely the data property, which Razor needs to identify which code actions are on their allow list, so we need
642
+ // to expose a command for them to directly invoke our code actions LSP endpoints, rather than use built-in commands.
643
+ context . subscriptions . push ( vscode . commands . registerCommand ( RoslynLanguageServer . provideCodeActionsCommand , async ( request : CodeActionParams ) => {
644
+ return await languageServer . sendRequest ( CodeActionRequest . type , request , CancellationToken . None ) ;
645
+ } ) ) ;
646
+ context . subscriptions . push ( vscode . commands . registerCommand ( RoslynLanguageServer . resolveCodeActionCommand , async ( request : CodeAction ) => {
647
+ return await languageServer . sendRequest ( CodeActionResolveRequest . type , request , CancellationToken . None ) ;
648
+ } ) ) ;
649
+
650
+ context . subscriptions . push ( vscode . commands . registerCommand ( RoslynLanguageServer . provideCompletionsCommand , async ( request : CompletionParams ) => {
651
+ return await languageServer . sendRequest ( CompletionRequest . type , request , CancellationToken . None ) ;
652
+ } ) ) ;
653
+ context . subscriptions . push ( vscode . commands . registerCommand ( RoslynLanguageServer . resolveCompletionsCommand , async ( request : CompletionItem ) => {
654
+ return await languageServer . sendRequest ( CompletionResolveRequest . type , request , CancellationToken . None ) ;
655
+ } ) ) ;
656
+
657
+ // Roslyn is responsible for producing a json file containing information for Razor, that comes from the compilation for
658
+ // a project. We want to defer this work until necessary, so this command is called by the Razor document manager to tell
659
+ // us when they need us to initialize the Razor things.
660
+ context . subscriptions . push ( vscode . commands . registerCommand ( RoslynLanguageServer . razorInitializeCommand , async ( ) => {
661
+ await languageServer . sendNotification ( "razor/initialize" , { } ) ;
662
+ } ) ) ;
663
+ }
664
+
649
665
async function applyAutoInsertEdit ( e : vscode . TextDocumentChangeEvent , token : vscode . CancellationToken ) {
650
666
const change = e . contentChanges [ 0 ] ;
651
667
0 commit comments