3
3
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4
4
//
5
5
6
- using System . Collections . Generic ;
6
+ using System ;
7
7
using System . IO ;
8
- using System . Management . Automation ;
9
- using System . Management . Automation . Host ;
10
- using System . Management . Automation . Runspaces ;
11
- using System . Reflection ;
12
8
using System . Threading . Tasks ;
13
9
using Microsoft . Extensions . DependencyInjection ;
14
10
using Microsoft . Extensions . Logging ;
15
11
using Microsoft . PowerShell . EditorServices . Engine . Handlers ;
16
- using Microsoft . PowerShell . EditorServices . Engine . Hosting ;
17
12
using Microsoft . PowerShell . EditorServices . Engine . Services ;
18
- using Microsoft . PowerShell . EditorServices . Engine . Services . PowerShellContext ;
19
13
using OmniSharp . Extensions . DebugAdapter . Protocol . Serialization ;
20
14
using OmniSharp . Extensions . JsonRpc ;
21
15
using OmniSharp . Extensions . LanguageServer . Server ;
22
16
23
17
namespace Microsoft . PowerShell . EditorServices . Engine . Server
24
18
{
25
- internal class PsesDebugServer
19
+ internal class PsesDebugServer : IDisposable
26
20
{
27
21
protected readonly ILoggerFactory _loggerFactory ;
28
22
private readonly Stream _inputStream ;
29
23
private readonly Stream _outputStream ;
30
- private readonly TaskCompletionSource < bool > _serverStart ;
31
-
32
24
33
25
private IJsonRpcServer _jsonRpcServer ;
34
26
@@ -40,65 +32,49 @@ internal PsesDebugServer(
40
32
_loggerFactory = factory ;
41
33
_inputStream = inputStream ;
42
34
_outputStream = outputStream ;
43
- _serverStart = new TaskCompletionSource < bool > ( ) ;
44
-
45
35
}
46
36
47
- public async Task StartAsync ( )
37
+ public async Task StartAsync ( IServiceProvider languageServerServiceProvider )
48
38
{
49
39
_jsonRpcServer = await JsonRpcServer . From ( options =>
50
40
{
51
41
options . Serializer = new DapProtocolSerializer ( ) ;
52
42
options . Reciever = new DapReciever ( ) ;
53
43
options . LoggerFactory = _loggerFactory ;
54
44
ILogger logger = options . LoggerFactory . CreateLogger ( "DebugOptionsStartup" ) ;
55
- options . AddHandler < PowershellInitializeHandler > ( ) ;
56
- // options.Services = new ServiceCollection()
57
- // .AddSingleton<WorkspaceService>()
58
- // .AddSingleton<SymbolsService>()
59
- // .AddSingleton<ConfigurationService>()
60
- // .AddSingleton<PowerShellContextService>(
61
- // (provider) =>
62
- // GetFullyInitializedPowerShellContext(
63
- // provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>(),
64
- // _profilePaths))
65
- // .AddSingleton<TemplateService>()
66
- // .AddSingleton<EditorOperationsService>()
67
- // .AddSingleton<ExtensionService>(
68
- // (provider) =>
69
- // {
70
- // var extensionService = new ExtensionService(
71
- // provider.GetService<PowerShellContextService>(),
72
- // provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>());
73
- // extensionService.InitializeAsync(
74
- // serviceProvider: provider,
75
- // editorOperations: provider.GetService<EditorOperationsService>())
76
- // .Wait();
77
- // return extensionService;
78
- // })
79
- // .AddSingleton<AnalysisService>(
80
- // (provider) =>
81
- // {
82
- // return AnalysisService.Create(
83
- // provider.GetService<ConfigurationService>(),
84
- // provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>(),
85
- // options.LoggerFactory.CreateLogger<AnalysisService>());
86
- // });
87
-
45
+ options . Services = new ServiceCollection ( )
46
+ . AddSingleton ( languageServerServiceProvider . GetService < PowerShellContextService > ( ) )
47
+ . AddSingleton < DebugService > ( )
48
+ . AddSingleton < DebugStateService > ( ) ;
49
+
88
50
options
89
51
. WithInput ( _inputStream )
90
52
. WithOutput ( _outputStream ) ;
91
53
92
54
logger . LogInformation ( "Adding handlers" ) ;
93
55
56
+ options
57
+ . WithHandler < InitializeHandler > ( )
58
+ . WithHandler < LaunchAndAttachHandler > ( ) ;
59
+
94
60
logger . LogInformation ( "Handlers added" ) ;
95
61
} ) ;
96
62
}
97
63
98
- public async Task WaitForShutdown ( )
64
+ public void Dispose ( )
65
+ {
66
+ _jsonRpcServer . Dispose ( ) ;
67
+ }
68
+
69
+ #region Events
70
+
71
+ public event EventHandler SessionEnded ;
72
+
73
+ internal void OnSessionEnded ( )
99
74
{
100
- await _serverStart . Task ;
101
- //await _languageServer.;
75
+ SessionEnded ? . Invoke ( this , null ) ;
102
76
}
77
+
78
+ #endregion
103
79
}
104
80
}
0 commit comments