1
1
// Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
4
- using System ;
5
4
using System . IO ;
6
5
using System . Threading . Tasks ;
7
6
using Microsoft . Extensions . DependencyInjection ;
12
11
using Microsoft . PowerShell . EditorServices . Services . Extension ;
13
12
using Microsoft . PowerShell . EditorServices . Services . PowerShell . Host ;
14
13
using Microsoft . PowerShell . EditorServices . Services . Template ;
14
+ using Newtonsoft . Json . Linq ;
15
+ using OmniSharp . Extensions . LanguageServer . Protocol . Models ;
15
16
using OmniSharp . Extensions . LanguageServer . Protocol . Server ;
16
17
using OmniSharp . Extensions . LanguageServer . Server ;
17
18
using Serilog ;
@@ -24,15 +25,12 @@ namespace Microsoft.PowerShell.EditorServices.Server
24
25
internal class PsesLanguageServer
25
26
{
26
27
internal ILoggerFactory LoggerFactory { get ; }
27
-
28
28
internal ILanguageServer LanguageServer { get ; private set ; }
29
-
30
29
private readonly LogLevel _minimumLogLevel ;
31
30
private readonly Stream _inputStream ;
32
31
private readonly Stream _outputStream ;
33
32
private readonly HostStartupInfo _hostDetails ;
34
33
private readonly TaskCompletionSource < bool > _serverStart ;
35
-
36
34
private PsesInternalHost _psesHost ;
37
35
38
36
/// <summary>
@@ -117,33 +115,32 @@ public async Task StartAsync()
117
115
// _Initialize_ request:
118
116
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialize
119
117
. OnInitialize (
120
- ( languageServer , request , _ ) =>
118
+ ( languageServer , initializeParams , cancellationToken ) =>
121
119
{
122
- Log . Logger . Debug ( "Initializing OmniSharp Language Server" ) ;
123
-
124
- IServiceProvider serviceProvider = languageServer . Services ;
125
-
126
- _psesHost = serviceProvider . GetService < PsesInternalHost > ( ) ;
127
-
128
- WorkspaceService workspaceService = serviceProvider . GetService < WorkspaceService > ( ) ;
129
-
130
- // Grab the workspace path from the parameters
131
- if ( request . RootUri != null )
132
- {
133
- workspaceService . WorkspacePath = request . RootUri . GetFileSystemPath ( ) ;
134
- }
135
- else if ( request . WorkspaceFolders != null )
120
+ // Set the workspace path from the parameters.
121
+ WorkspaceService workspaceService = languageServer . Services . GetService < WorkspaceService > ( ) ;
122
+ if ( initializeParams . WorkspaceFolders is not null )
136
123
{
137
- // If RootUri isn't set, try to use the first WorkspaceFolder.
138
124
// TODO: Support multi-workspace.
139
- foreach ( OmniSharp . Extensions . LanguageServer . Protocol . Models . WorkspaceFolder workspaceFolder in request . WorkspaceFolders )
125
+ foreach ( WorkspaceFolder workspaceFolder in initializeParams . WorkspaceFolders )
140
126
{
141
127
workspaceService . WorkspacePath = workspaceFolder . Uri . GetFileSystemPath ( ) ;
142
128
break ;
143
129
}
144
130
}
145
131
146
- return Task . CompletedTask ;
132
+ // Parse initialization options.
133
+ JObject initializationOptions = initializeParams . InitializationOptions as JObject ;
134
+ HostStartOptions hostStartOptions = new ( )
135
+ {
136
+ LoadProfiles = initializationOptions ? . GetValue ( "EnableProfileLoading" ) ? . Value < bool > ( ) ?? false ,
137
+ // TODO: Consider deprecating the setting which sets this and
138
+ // instead use WorkspacePath exclusively.
139
+ InitialWorkingDirectory = initializationOptions ? . GetValue ( "InitialWorkingDirectory" ) ? . Value < string > ( ) ?? workspaceService . WorkspacePath
140
+ } ;
141
+
142
+ _psesHost = languageServer . Services . GetService < PsesInternalHost > ( ) ;
143
+ return _psesHost . TryStartAsync ( hostStartOptions , cancellationToken ) ;
147
144
} ) ;
148
145
} ) . ConfigureAwait ( false ) ;
149
146
@@ -156,7 +153,6 @@ public async Task StartAsync()
156
153
/// <returns>A task that completes when the server is shut down.</returns>
157
154
public async Task WaitForShutdown ( )
158
155
{
159
- Log . Logger . Debug ( "Shutting down OmniSharp Language Server" ) ;
160
156
await _serverStart . Task . ConfigureAwait ( false ) ;
161
157
await LanguageServer . WaitForExit . ConfigureAwait ( false ) ;
162
158
0 commit comments