6
6
using System ;
7
7
using System . Collections . Generic ;
8
8
using System . Diagnostics ;
9
- using System . IO ;
10
9
using System . Linq ;
11
10
using System . Management . Automation ;
12
11
using System . Management . Automation . Host ;
13
- using System . Management . Automation . Runspaces ;
14
12
using System . Reflection ;
15
13
using System . Runtime . InteropServices ;
16
14
using System . Threading ;
17
15
using System . Threading . Tasks ;
18
- using Microsoft . Extensions . DependencyInjection ;
19
16
using Microsoft . Extensions . Logging ;
20
- using Microsoft . PowerShell . EditorServices . Extensions ;
21
- using Microsoft . PowerShell . EditorServices . Host ;
22
- using Microsoft . PowerShell . EditorServices . Templates ;
17
+ using Microsoft . PowerShell . EditorServices . Engine . Server ;
23
18
using Serilog ;
24
19
25
20
namespace Microsoft . PowerShell . EditorServices . Engine
@@ -62,8 +57,6 @@ public class EditorServicesHost
62
57
{
63
58
#region Private Fields
64
59
65
- private readonly IServiceCollection _serviceCollection ;
66
-
67
60
private readonly HostDetails _hostDetails ;
68
61
69
62
private readonly PSHost _internalHost ;
@@ -74,7 +67,7 @@ public class EditorServicesHost
74
67
75
68
private readonly string [ ] _additionalModules ;
76
69
77
- private ILanguageServer _languageServer ;
70
+ private PsesLanguageServer _languageServer ;
78
71
79
72
private Microsoft . Extensions . Logging . ILogger _logger ;
80
73
@@ -139,16 +132,15 @@ public EditorServicesHost(
139
132
Validate . IsNotNull ( nameof ( hostDetails ) , hostDetails ) ;
140
133
Validate . IsNotNull ( nameof ( internalHost ) , internalHost ) ;
141
134
142
- _serviceCollection = new ServiceCollection ( ) ;
143
135
_hostDetails = hostDetails ;
144
136
145
137
//this._hostDetails = hostDetails;
146
- this . _enableConsoleRepl = enableConsoleRepl ;
138
+ _enableConsoleRepl = enableConsoleRepl ;
147
139
//this.bundledModulesPath = bundledModulesPath;
148
- this . _additionalModules = additionalModules ?? Array . Empty < string > ( ) ;
149
- this . _featureFlags = new HashSet < string > ( featureFlags ?? Array . Empty < string > ( ) ) ;
140
+ _additionalModules = additionalModules ?? Array . Empty < string > ( ) ;
141
+ _featureFlags = new HashSet < string > ( featureFlags ?? Array . Empty < string > ( ) ) ;
150
142
//this.serverCompletedTask = new TaskCompletionSource<bool>();
151
- this . _internalHost = internalHost ;
143
+ _internalHost = internalHost ;
152
144
153
145
#if DEBUG
154
146
if ( waitForDebugger )
@@ -236,59 +228,33 @@ public void StartLanguageService(
236
228
237
229
_logger . LogInformation ( $ "LSP NamedPipe: { config . InOutPipeName } \n LSP OutPipe: { config . OutPipeName } ") ;
238
230
239
- _serviceCollection
240
- . AddSingleton < WorkspaceService > ( )
241
- . AddSingleton < SymbolsService > ( )
242
- . AddSingleton < ConfigurationService > ( )
243
- . AddSingleton < PowerShellContextService > (
244
- ( provider ) =>
245
- GetFullyInitializedPowerShellContext (
246
- provider . GetService < OmniSharp . Extensions . LanguageServer . Protocol . Server . ILanguageServer > ( ) ,
247
- profilePaths ) )
248
- . AddSingleton < TemplateService > ( )
249
- . AddSingleton < EditorOperationsService > ( )
250
- . AddSingleton < ExtensionService > (
251
- ( provider ) =>
252
- {
253
- var extensionService = new ExtensionService (
254
- provider . GetService < PowerShellContextService > ( ) ,
255
- provider . GetService < OmniSharp . Extensions . LanguageServer . Protocol . Server . ILanguageServer > ( ) ) ;
256
- extensionService . InitializeAsync (
257
- serviceProvider : provider ,
258
- editorOperations : provider . GetService < EditorOperationsService > ( ) )
259
- . Wait ( ) ;
260
- return extensionService ;
261
- } )
262
- . AddSingleton < AnalysisService > (
263
- ( provider ) =>
264
- {
265
- return AnalysisService . Create (
266
- provider . GetService < ConfigurationService > ( ) ,
267
- provider . GetService < OmniSharp . Extensions . LanguageServer . Protocol . Server . ILanguageServer > ( ) ,
268
- _factory . CreateLogger < AnalysisService > ( ) ) ;
269
- } ) ;
231
+
270
232
271
233
switch ( config . TransportType )
272
234
{
273
235
case EditorServiceTransportType . NamedPipe :
274
- _languageServer = new OmnisharpLanguageServerBuilder ( _serviceCollection )
275
- {
276
- NamedPipeName = config . InOutPipeName ?? config . InPipeName ,
277
- OutNamedPipeName = config . OutPipeName ,
278
- LoggerFactory = _factory ,
279
- MinimumLogLevel = LogLevel . Trace ,
280
- }
281
- . BuildLanguageServer ( ) ;
236
+ _languageServer = new NamedPipePsesLanguageServer (
237
+ _factory ,
238
+ LogLevel . Trace ,
239
+ _enableConsoleRepl ,
240
+ _featureFlags ,
241
+ _hostDetails ,
242
+ _additionalModules ,
243
+ _internalHost ,
244
+ profilePaths ,
245
+ config . InOutPipeName ?? config . InPipeName ,
246
+ config . OutPipeName ) ;
282
247
break ;
283
248
284
249
case EditorServiceTransportType . Stdio :
285
- _languageServer = new OmnisharpLanguageServerBuilder ( _serviceCollection )
286
- {
287
- Stdio = true ,
288
- LoggerFactory = _factory ,
289
- MinimumLogLevel = LogLevel . Trace ,
290
- }
291
- . BuildLanguageServer ( ) ;
250
+ _languageServer = new StdioPsesLanguageServer (
251
+ _factory ,
252
+ LogLevel . Trace ,
253
+ _featureFlags ,
254
+ _hostDetails ,
255
+ _additionalModules ,
256
+ _internalHost ,
257
+ profilePaths ) ;
292
258
break ;
293
259
}
294
260
@@ -302,57 +268,6 @@ public void StartLanguageService(
302
268
config . TransportType , config . Endpoint ) ) ;
303
269
}
304
270
305
- private PowerShellContextService GetFullyInitializedPowerShellContext (
306
- OmniSharp . Extensions . LanguageServer . Protocol . Server . ILanguageServer languageServer ,
307
- ProfilePaths profilePaths )
308
- {
309
- var logger = _factory . CreateLogger < PowerShellContextService > ( ) ;
310
-
311
- // PSReadLine can only be used when -EnableConsoleRepl is specified otherwise
312
- // issues arise when redirecting stdio.
313
- var powerShellContext = new PowerShellContextService (
314
- logger ,
315
- languageServer ,
316
- _featureFlags . Contains ( "PSReadLine" ) && _enableConsoleRepl ) ;
317
-
318
- EditorServicesPSHostUserInterface hostUserInterface =
319
- _enableConsoleRepl
320
- ? ( EditorServicesPSHostUserInterface ) new TerminalPSHostUserInterface ( powerShellContext , logger , _internalHost )
321
- : new ProtocolPSHostUserInterface ( languageServer , powerShellContext , logger ) ;
322
-
323
- EditorServicesPSHost psHost =
324
- new EditorServicesPSHost (
325
- powerShellContext ,
326
- _hostDetails ,
327
- hostUserInterface ,
328
- logger ) ;
329
-
330
- Runspace initialRunspace = PowerShellContextService . CreateRunspace ( psHost ) ;
331
- powerShellContext . Initialize ( profilePaths , initialRunspace , true , hostUserInterface ) ;
332
-
333
- powerShellContext . ImportCommandsModuleAsync (
334
- Path . Combine (
335
- Path . GetDirectoryName ( this . GetType ( ) . GetTypeInfo ( ) . Assembly . Location ) ,
336
- @"..\Commands" ) ) ;
337
-
338
- // TODO: This can be moved to the point after the $psEditor object
339
- // gets initialized when that is done earlier than LanguageServer.Initialize
340
- foreach ( string module in this . _additionalModules )
341
- {
342
- var command =
343
- new PSCommand ( )
344
- . AddCommand ( "Microsoft.PowerShell.Core\\ Import-Module" )
345
- . AddParameter ( "Name" , module ) ;
346
-
347
- powerShellContext . ExecuteCommandAsync < PSObject > (
348
- command ,
349
- sendOutputToHost : false ,
350
- sendErrorToHost : true ) ;
351
- }
352
-
353
- return powerShellContext ;
354
- }
355
-
356
271
/// <summary>
357
272
/// Starts the debug service with the specified config.
358
273
/// </summary>
0 commit comments