66using Microsoft . PowerShell . EditorServices . Protocol . LanguageServer ;
77using Microsoft . PowerShell . EditorServices . Protocol . MessageProtocol ;
88using Microsoft . PowerShell . EditorServices . Protocol . MessageProtocol . Channel ;
9+ using Microsoft . PowerShell . EditorServices . Session ;
910using Microsoft . PowerShell . EditorServices . Utility ;
1011using System ;
1112using System . Collections . Generic ;
@@ -23,18 +24,27 @@ public class LanguageServer : LanguageServerBase
2324 {
2425 private static CancellationTokenSource existingRequestCancellation ;
2526
27+ private bool profilesLoaded ;
2628 private EditorSession editorSession ;
2729 private OutputDebouncer outputDebouncer ;
2830 private LanguageServerSettings currentSettings = new LanguageServerSettings ( ) ;
2931
30- 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 ( ) )
3137 {
3238 }
3339
34- 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 )
3545 {
3646 this . editorSession = new EditorSession ( ) ;
37- this . editorSession . StartSession ( ) ;
47+ this . editorSession . StartSession ( hostDetails ) ;
3848 this . editorSession . ConsoleService . OutputWritten += this . powerShellContext_OutputWritten ;
3949
4050 // Always send console prompts through the UI in the language service
@@ -58,7 +68,7 @@ protected override void Initialize()
5868 this . SetEventHandler ( DidOpenTextDocumentNotification . Type , this . HandleDidOpenTextDocumentNotification ) ;
5969 this . SetEventHandler ( DidCloseTextDocumentNotification . Type , this . HandleDidCloseTextDocumentNotification ) ;
6070 this . SetEventHandler ( DidChangeTextDocumentNotification . Type , this . HandleDidChangeTextDocumentNotification ) ;
61- this . SetEventHandler ( DidChangeConfigurationNotification < SettingsWrapper > . Type , this . HandleDidChangeConfigurationNotification ) ;
71+ this . SetEventHandler ( DidChangeConfigurationNotification < LanguageServerSettingsWrapper > . Type , this . HandleDidChangeConfigurationNotification ) ;
6272
6373 this . SetRequestHandler ( DefinitionRequest . Type , this . HandleDefinitionRequest ) ;
6474 this . SetRequestHandler ( ReferencesRequest . Type , this . HandleReferencesRequest ) ;
@@ -286,20 +296,29 @@ protected Task HandleDidChangeTextDocumentNotification(
286296 }
287297
288298 protected async Task HandleDidChangeConfigurationNotification (
289- DidChangeConfigurationParams < SettingsWrapper > configChangeParams ,
299+ DidChangeConfigurationParams < LanguageServerSettingsWrapper > configChangeParams ,
290300 EventContext eventContext )
291301 {
292- bool oldScriptAnalysisEnabled =
302+ bool oldLoadProfiles = this . currentSettings . EnableProfileLoading ;
303+ bool oldScriptAnalysisEnabled =
293304 this . currentSettings . ScriptAnalysis . Enable . HasValue ;
294305 string oldScriptAnalysisSettingsPath =
295306 this . currentSettings . ScriptAnalysis . SettingsPath ;
296307
297308 this . currentSettings . Update (
298- configChangeParams . Settings . Powershell ) ;
309+ configChangeParams . Settings . Powershell ,
310+ this . editorSession . Workspace . WorkspacePath ) ;
311+
312+ if ( ! this . profilesLoaded &&
313+ this . currentSettings . EnableProfileLoading &&
314+ oldLoadProfiles != this . currentSettings . EnableProfileLoading )
315+ {
316+ await this . editorSession . PowerShellContext . LoadHostProfiles ( ) ;
317+ this . profilesLoaded = true ;
318+ }
299319
300- string newSettingsPath = this . currentSettings . ScriptAnalysis . SettingsPath ;
301-
302320 // If there is a new settings file path, restart the analyzer with the new settigs.
321+ string newSettingsPath = this . currentSettings . ScriptAnalysis . SettingsPath ;
303322 if ( ! ( oldScriptAnalysisSettingsPath ? . Equals ( newSettingsPath , StringComparison . OrdinalIgnoreCase ) ?? false ) )
304323 {
305324 this . editorSession . RestartAnalysisService ( newSettingsPath ) ;
@@ -1000,7 +1019,6 @@ private static CompletionItem CreateCompletionItem(
10001019 {
10011020 string detailString = null ;
10021021 string documentationString = null ;
1003- string labelString = completionDetails . ListItemText ;
10041022
10051023 if ( ( completionDetails . CompletionType == CompletionType . Variable ) ||
10061024 ( completionDetails . CompletionType == CompletionType . ParameterName ) )
@@ -1013,11 +1031,6 @@ private static CompletionItem CreateCompletionItem(
10131031 {
10141032 detailString = matches [ 0 ] . Groups [ 1 ] . Value ;
10151033 }
1016-
1017- // PowerShell returns ListItemText for parameters & variables that is not prefixed
1018- // and it needs to be or the completion will not appear for these CompletionTypes.
1019- string prefix = ( completionDetails . CompletionType == CompletionType . Variable ) ? "$" : "-" ;
1020- labelString = prefix + completionDetails . ListItemText ;
10211034 }
10221035 else if ( ( completionDetails . CompletionType == CompletionType . Method ) ||
10231036 ( completionDetails . CompletionType == CompletionType . Property ) )
@@ -1054,13 +1067,13 @@ private static CompletionItem CreateCompletionItem(
10541067 // completion list. Technically we don't need the ListItemText at all but it may come
10551068 // in handy during debug.
10561069 var sortText = ( completionDetails . CompletionType == CompletionType . ParameterName )
1057- ? string . Format ( "{0 :D3}{1}" , sortIndex , completionDetails . ListItemText )
1058- : null ;
1070+ ? $ " { sortIndex : D3} { completionDetails . ListItemText } "
1071+ : null ;
10591072
10601073 return new CompletionItem
10611074 {
10621075 InsertText = completionDetails . CompletionText ,
1063- Label = labelString ,
1076+ Label = completionDetails . ListItemText ,
10641077 Kind = MapCompletionKind ( completionDetails . CompletionType ) ,
10651078 Detail = detailString ,
10661079 Documentation = documentationString ,
0 commit comments