6
6
using Microsoft . PowerShell . EditorServices . Protocol . LanguageServer ;
7
7
using Microsoft . PowerShell . EditorServices . Protocol . MessageProtocol ;
8
8
using Microsoft . PowerShell . EditorServices . Protocol . MessageProtocol . Channel ;
9
- using Microsoft . PowerShell . EditorServices . Protocol . Messages ;
9
+ using Microsoft . PowerShell . EditorServices . Session ;
10
10
using Microsoft . PowerShell . EditorServices . Utility ;
11
11
using System ;
12
12
using System . Collections . Generic ;
@@ -24,18 +24,27 @@ public class LanguageServer : LanguageServerBase
24
24
{
25
25
private static CancellationTokenSource existingRequestCancellation ;
26
26
27
+ private bool profilesLoaded ;
27
28
private EditorSession editorSession ;
28
29
private OutputDebouncer outputDebouncer ;
29
30
private LanguageServerSettings currentSettings = new LanguageServerSettings ( ) ;
30
31
31
- public LanguageServer ( ) : this ( new StdioServerChannel ( ) )
32
+ /// <param name="hostDetails">
33
+ /// Provides details about the host application.
34
+ /// </param>
35
+ public LanguageServer ( HostDetails hostDetails )
36
+ : this ( hostDetails , new StdioServerChannel ( ) )
32
37
{
33
38
}
34
39
35
- public LanguageServer ( ChannelBase serverChannel ) : base ( serverChannel )
40
+ /// <param name="hostDetails">
41
+ /// Provides details about the host application.
42
+ /// </param>
43
+ public LanguageServer ( HostDetails hostDetails , ChannelBase serverChannel )
44
+ : base ( serverChannel )
36
45
{
37
46
this . editorSession = new EditorSession ( ) ;
38
- this . editorSession . StartSession ( ) ;
47
+ this . editorSession . StartSession ( hostDetails ) ;
39
48
this . editorSession . ConsoleService . OutputWritten += this . powerShellContext_OutputWritten ;
40
49
41
50
// Always send console prompts through the UI in the language service
@@ -59,7 +68,7 @@ protected override void Initialize()
59
68
this . SetEventHandler ( DidOpenTextDocumentNotification . Type , this . HandleDidOpenTextDocumentNotification ) ;
60
69
this . SetEventHandler ( DidCloseTextDocumentNotification . Type , this . HandleDidCloseTextDocumentNotification ) ;
61
70
this . SetEventHandler ( DidChangeTextDocumentNotification . Type , this . HandleDidChangeTextDocumentNotification ) ;
62
- this . SetEventHandler ( DidChangeConfigurationNotification < SettingsWrapper > . Type , this . HandleDidChangeConfigurationNotification ) ;
71
+ this . SetEventHandler ( DidChangeConfigurationNotification < LanguageServerSettingsWrapper > . Type , this . HandleDidChangeConfigurationNotification ) ;
63
72
64
73
this . SetRequestHandler ( DefinitionRequest . Type , this . HandleDefinitionRequest ) ;
65
74
this . SetRequestHandler ( ReferencesRequest . Type , this . HandleReferencesRequest ) ;
@@ -287,15 +296,24 @@ protected Task HandleDidChangeTextDocumentNotification(
287
296
}
288
297
289
298
protected async Task HandleDidChangeConfigurationNotification (
290
- DidChangeConfigurationParams < SettingsWrapper > configChangeParams ,
299
+ DidChangeConfigurationParams < LanguageServerSettingsWrapper > configChangeParams ,
291
300
EventContext eventContext )
292
301
{
302
+ bool oldLoadProfiles = this . currentSettings . EnableProfileLoading ;
293
303
bool oldScriptAnalysisEnabled =
294
304
this . currentSettings . ScriptAnalysis . Enable . HasValue ;
295
305
296
306
this . currentSettings . Update (
297
307
configChangeParams . Settings . Powershell ) ;
298
308
309
+ if ( ! this . profilesLoaded &&
310
+ this . currentSettings . EnableProfileLoading &&
311
+ oldLoadProfiles != this . currentSettings . EnableProfileLoading )
312
+ {
313
+ await this . editorSession . PowerShellContext . LoadHostProfiles ( ) ;
314
+ this . profilesLoaded = true ;
315
+ }
316
+
299
317
if ( oldScriptAnalysisEnabled != this . currentSettings . ScriptAnalysis . Enable )
300
318
{
301
319
// If the user just turned off script analysis, send a diagnostics
0 commit comments