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
15
using OmniSharp . Extensions . JsonRpc ;
16
+ using OmniSharp . Extensions . LanguageServer . Protocol . Models ;
16
17
using OmniSharp . Extensions . LanguageServer . Protocol . Server ;
17
18
using OmniSharp . Extensions . LanguageServer . Server ;
18
19
using Serilog ;
@@ -25,15 +26,12 @@ namespace Microsoft.PowerShell.EditorServices.Server
25
26
internal class PsesLanguageServer
26
27
{
27
28
internal ILoggerFactory LoggerFactory { get ; }
28
-
29
29
internal ILanguageServer LanguageServer { get ; private set ; }
30
-
31
30
private readonly LogLevel _minimumLogLevel ;
32
31
private readonly Stream _inputStream ;
33
32
private readonly Stream _outputStream ;
34
33
private readonly HostStartupInfo _hostDetails ;
35
34
private readonly TaskCompletionSource < bool > _serverStart ;
36
-
37
35
private PsesInternalHost _psesHost ;
38
36
39
37
/// <summary>
@@ -125,33 +123,32 @@ public async Task StartAsync()
125
123
// _Initialize_ request:
126
124
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialize
127
125
. OnInitialize (
128
- ( languageServer , request , _ ) =>
126
+ ( languageServer , initializeParams , cancellationToken ) =>
129
127
{
130
- Log . Logger . Debug ( "Initializing OmniSharp Language Server" ) ;
131
-
132
- IServiceProvider serviceProvider = languageServer . Services ;
133
-
134
- _psesHost = serviceProvider . GetService < PsesInternalHost > ( ) ;
135
-
136
- WorkspaceService workspaceService = serviceProvider . GetService < WorkspaceService > ( ) ;
137
-
138
- // Grab the workspace path from the parameters
139
- if ( request . RootUri != null )
140
- {
141
- workspaceService . WorkspacePath = request . RootUri . GetFileSystemPath ( ) ;
142
- }
143
- else if ( request . WorkspaceFolders != null )
128
+ // Set the workspace path from the parameters.
129
+ WorkspaceService workspaceService = languageServer . Services . GetService < WorkspaceService > ( ) ;
130
+ if ( initializeParams . WorkspaceFolders is not null )
144
131
{
145
- // If RootUri isn't set, try to use the first WorkspaceFolder.
146
132
// TODO: Support multi-workspace.
147
- foreach ( OmniSharp . Extensions . LanguageServer . Protocol . Models . WorkspaceFolder workspaceFolder in request . WorkspaceFolders )
133
+ foreach ( WorkspaceFolder workspaceFolder in initializeParams . WorkspaceFolders )
148
134
{
149
135
workspaceService . WorkspacePath = workspaceFolder . Uri . GetFileSystemPath ( ) ;
150
136
break ;
151
137
}
152
138
}
153
139
154
- return Task . CompletedTask ;
140
+ // Parse initialization options.
141
+ JObject initializationOptions = initializeParams . InitializationOptions as JObject ;
142
+ HostStartOptions hostStartOptions = new ( )
143
+ {
144
+ LoadProfiles = initializationOptions ? . GetValue ( "EnableProfileLoading" ) ? . Value < bool > ( ) ?? false ,
145
+ // TODO: Consider deprecating the setting which sets this and
146
+ // instead use WorkspacePath exclusively.
147
+ InitialWorkingDirectory = initializationOptions ? . GetValue ( "InitialWorkingDirectory" ) ? . Value < string > ( ) ?? workspaceService . WorkspacePath
148
+ } ;
149
+
150
+ _psesHost = languageServer . Services . GetService < PsesInternalHost > ( ) ;
151
+ return _psesHost . TryStartAsync ( hostStartOptions , cancellationToken ) ;
155
152
} ) ;
156
153
} ) . ConfigureAwait ( false ) ;
157
154
@@ -164,7 +161,6 @@ public async Task StartAsync()
164
161
/// <returns>A task that completes when the server is shut down.</returns>
165
162
public async Task WaitForShutdown ( )
166
163
{
167
- Log . Logger . Debug ( "Shutting down OmniSharp Language Server" ) ;
168
164
await _serverStart . Task . ConfigureAwait ( false ) ;
169
165
await LanguageServer . WaitForExit . ConfigureAwait ( false ) ;
170
166
0 commit comments