@@ -61,7 +61,7 @@ let _languageServer: RoslynLanguageServer;
61
61
let _channel : vscode . OutputChannel ;
62
62
let _traceChannel : vscode . OutputChannel ;
63
63
64
- const csharpDevkitIntelliCodeExtensionId = "ms-dotnettools.vscodeintellicode-csharp" ;
64
+ export const CSharpDevkitIntelliCodeExtensionId = "ms-dotnettools.vscodeintellicode-csharp" ;
65
65
66
66
export class RoslynLanguageServer {
67
67
@@ -117,38 +117,7 @@ export class RoslynLanguageServer {
117
117
private optionProvider : OptionProvider ,
118
118
private context : vscode . ExtensionContext ,
119
119
private telemetryReporter : TelemetryReporter
120
- ) {
121
- // subscribe to extension change events so that we can get notified if C# Dev Kit is added/removed later.
122
- this . context . subscriptions . push ( vscode . extensions . onDidChange ( async ( ) => {
123
- let csharpDevkitExtension = getCSharpDevKit ( ) ;
124
-
125
- if ( this . _wasActivatedWithCSharpDevkit === undefined ) {
126
- // Haven't activated yet.
127
- return ;
128
- }
129
-
130
- const title = 'Restart Language Server' ;
131
- const command = 'dotnet.restartServer' ;
132
- if ( csharpDevkitExtension && ! this . _wasActivatedWithCSharpDevkit ) {
133
- // We previously started without C# Dev Kit and its now installed.
134
- // Offer a prompt to restart the server to use C# Dev Kit.
135
- _channel . appendLine ( `Detected new installation of ${ csharpDevkitExtensionId } ` ) ;
136
- let message = `Detected installation of ${ csharpDevkitExtensionId } . Would you like to relaunch the language server for added features?` ;
137
- ShowInformationMessage ( vscode , message , { title, command } ) ;
138
- } else {
139
- // Any other change to extensions is irrelevant - an uninstall requires a reload of the window
140
- // which will automatically restart this extension too.
141
- }
142
- } ) ) ;
143
-
144
- // Subscribe to telemetry events so we can enable/disable as needed
145
- this . context . subscriptions . push ( vscode . env . onDidChangeTelemetryEnabled ( ( isEnabled : boolean ) => {
146
- const title = 'Restart Language Server' ;
147
- const command = 'dotnet.restartServer' ;
148
- const message = 'Detected change in telemetry settings. These will not take effect until the language server is restarted, would you like to restart?' ;
149
- ShowInformationMessage ( vscode , message , { title, command } ) ;
150
- } ) ) ;
151
- }
120
+ ) { }
152
121
153
122
/**
154
123
* Resolves server options and starts the dotnet language server process. The process is started asynchronously and this method will not wait until
@@ -223,6 +192,9 @@ export class RoslynLanguageServer {
223
192
this . _eventBus . emit ( RoslynLanguageServer . serverStateChangeEvent , ServerStateChange . ProjectInitializationComplete ) ;
224
193
} ) ;
225
194
195
+ this . registerExtensionsChanged ( this . _languageClient ) ;
196
+ this . registerTelemtryChanged ( this . _languageClient ) ;
197
+
226
198
// Start the client. This will also launch the server
227
199
this . _languageClient . start ( ) ;
228
200
@@ -416,7 +388,7 @@ export class RoslynLanguageServer {
416
388
this . _wasActivatedWithCSharpDevkit = true ;
417
389
418
390
// Get the starred suggestion dll location from C# Dev Kit IntelliCode (if both C# Dev Kit and C# Dev Kit IntelliCode are installed).
419
- const csharpDevkitIntelliCodeExtension = vscode . extensions . getExtension < CSharpIntelliCodeExports > ( csharpDevkitIntelliCodeExtensionId ) ;
391
+ const csharpDevkitIntelliCodeExtension = vscode . extensions . getExtension < CSharpIntelliCodeExports > ( CSharpDevkitIntelliCodeExtensionId ) ;
420
392
if ( csharpDevkitIntelliCodeExtension ) {
421
393
_channel . appendLine ( "Activating C# + C# Dev Kit + C# IntelliCode..." ) ;
422
394
const csharpDevkitIntelliCodeArgs = await this . getCSharpDevkitIntelliCodeExportArgs ( csharpDevkitIntelliCodeExtension ) ;
@@ -508,6 +480,41 @@ export class RoslynLanguageServer {
508
480
} ) ) ;
509
481
}
510
482
483
+ private registerExtensionsChanged ( languageClient : RoslynLanguageClientInstance ) {
484
+ // subscribe to extension change events so that we can get notified if C# Dev Kit is added/removed later.
485
+ languageClient . addDisposable ( vscode . extensions . onDidChange ( async ( ) => {
486
+ let csharpDevkitExtension = getCSharpDevKit ( ) ;
487
+
488
+ if ( this . _wasActivatedWithCSharpDevkit === undefined ) {
489
+ // Haven't activated yet.
490
+ return ;
491
+ }
492
+
493
+ const title = 'Restart Language Server' ;
494
+ const command = 'dotnet.restartServer' ;
495
+ if ( csharpDevkitExtension && ! this . _wasActivatedWithCSharpDevkit ) {
496
+ // We previously started without C# Dev Kit and its now installed.
497
+ // Offer a prompt to restart the server to use C# Dev Kit.
498
+ _channel . appendLine ( `Detected new installation of ${ csharpDevkitExtensionId } ` ) ;
499
+ let message = `Detected installation of ${ csharpDevkitExtensionId } . Would you like to relaunch the language server for added features?` ;
500
+ ShowInformationMessage ( vscode , message , { title, command } ) ;
501
+ } else {
502
+ // Any other change to extensions is irrelevant - an uninstall requires a reload of the window
503
+ // which will automatically restart this extension too.
504
+ }
505
+ } ) ) ;
506
+ }
507
+
508
+ private registerTelemtryChanged ( languageClient : RoslynLanguageClientInstance ) {
509
+ // Subscribe to telemetry events so we can enable/disable as needed
510
+ languageClient . addDisposable ( vscode . env . onDidChangeTelemetryEnabled ( ( isEnabled : boolean ) => {
511
+ const title = 'Restart Language Server' ;
512
+ const command = 'dotnet.restartServer' ;
513
+ const message = 'Detected change in telemetry settings. These will not take effect until the language server is restarted, would you like to restart?' ;
514
+ ShowInformationMessage ( vscode , message , { title, command } ) ;
515
+ } ) ) ;
516
+ }
517
+
511
518
private getServerFileName ( ) {
512
519
const serverFileName = 'Microsoft.CodeAnalysis.LanguageServer' ;
513
520
let extension = '' ;
0 commit comments