Skip to content

Commit 0e8e815

Browse files
working launch but not attach
1 parent 8b8a445 commit 0e8e815

23 files changed

+3489
-253
lines changed

src/PowerShellEditorServices.Engine/Hosting/EditorServicesHost.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public void StartDebugService(
318318
Task.WhenAll(tasks)
319319
.ContinueWith(async task => {
320320
_logger.LogInformation("Starting debug server");
321-
await _debugServer.StartAsync();
321+
await _debugServer.StartAsync(_languageServer.LanguageServer.Services);
322322
_logger.LogInformation(
323323
$"Debug service started, type = {config.TransportType}, endpoint = {config.Endpoint}");
324324
});
@@ -327,6 +327,12 @@ public void StartDebugService(
327327
default:
328328
throw new NotSupportedException("not supported");
329329
}
330+
331+
_debugServer.SessionEnded += (sender, eventArgs) =>
332+
{
333+
_debugServer.Dispose();
334+
StartDebugService(config, profilePaths, useExistingSession);
335+
};
330336
}
331337

332338
/// <summary>

src/PowerShellEditorServices.Engine/PowerShellEditorServices.Engine.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@
3232
<PackageReference Include="OmniSharp.Extensions.DebugAdapter.Server" Version="1.0.0" />
3333
</ItemGroup>
3434

35+
<ItemGroup>
36+
<Folder Include="Services\DebugAdapter\Handlers\" />
37+
<Folder Include="Services\DebugAdapter\Debugging\" />
38+
</ItemGroup>
3539
</Project>

src/PowerShellEditorServices.Engine/Server/NamedPipePsesLanguageServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected override (Stream input, Stream output) GetInputOutputStreams()
6161
_outNamedPipeName,
6262
out NamedPipeServerStream outNamedPipe);
6363

64-
var logger = _loggerFactory.CreateLogger("NamedPipeConnection");
64+
var logger = LoggerFactory.CreateLogger("NamedPipeConnection");
6565

6666
logger.LogInformation("Waiting for connection");
6767
namedPipe.WaitForConnection();

src/PowerShellEditorServices.Engine/Server/PsesDebugServer.cs

Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,24 @@
33
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
//
55

6-
using System.Collections.Generic;
6+
using System;
77
using System.IO;
8-
using System.Management.Automation;
9-
using System.Management.Automation.Host;
10-
using System.Management.Automation.Runspaces;
11-
using System.Reflection;
128
using System.Threading.Tasks;
139
using Microsoft.Extensions.DependencyInjection;
1410
using Microsoft.Extensions.Logging;
1511
using Microsoft.PowerShell.EditorServices.Engine.Handlers;
16-
using Microsoft.PowerShell.EditorServices.Engine.Hosting;
1712
using Microsoft.PowerShell.EditorServices.Engine.Services;
18-
using Microsoft.PowerShell.EditorServices.Engine.Services.PowerShellContext;
1913
using OmniSharp.Extensions.DebugAdapter.Protocol.Serialization;
2014
using OmniSharp.Extensions.JsonRpc;
2115
using OmniSharp.Extensions.LanguageServer.Server;
2216

2317
namespace Microsoft.PowerShell.EditorServices.Engine.Server
2418
{
25-
internal class PsesDebugServer
19+
internal class PsesDebugServer : IDisposable
2620
{
2721
protected readonly ILoggerFactory _loggerFactory;
2822
private readonly Stream _inputStream;
2923
private readonly Stream _outputStream;
30-
private readonly TaskCompletionSource<bool> _serverStart;
31-
3224

3325
private IJsonRpcServer _jsonRpcServer;
3426

@@ -40,65 +32,49 @@ internal PsesDebugServer(
4032
_loggerFactory = factory;
4133
_inputStream = inputStream;
4234
_outputStream = outputStream;
43-
_serverStart = new TaskCompletionSource<bool>();
44-
4535
}
4636

47-
public async Task StartAsync()
37+
public async Task StartAsync(IServiceProvider languageServerServiceProvider)
4838
{
4939
_jsonRpcServer = await JsonRpcServer.From(options =>
5040
{
5141
options.Serializer = new DapProtocolSerializer();
5242
options.Reciever = new DapReciever();
5343
options.LoggerFactory = _loggerFactory;
5444
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+
8850
options
8951
.WithInput(_inputStream)
9052
.WithOutput(_outputStream);
9153

9254
logger.LogInformation("Adding handlers");
9355

56+
options
57+
.WithHandler<InitializeHandler>()
58+
.WithHandler<LaunchAndAttachHandler>();
59+
9460
logger.LogInformation("Handlers added");
9561
});
9662
}
9763

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()
9974
{
100-
await _serverStart.Task;
101-
//await _languageServer.;
75+
SessionEnded?.Invoke(this, null);
10276
}
77+
78+
#endregion
10379
}
10480
}

src/PowerShellEditorServices.Engine/Server/PsesLanguageServer.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ namespace Microsoft.PowerShell.EditorServices.Engine.Server
2222
{
2323
internal abstract class PsesLanguageServer
2424
{
25-
protected readonly ILoggerFactory _loggerFactory;
25+
internal ILoggerFactory LoggerFactory { get; private set; }
26+
internal ILanguageServer LanguageServer { get; private set; }
27+
2628
private readonly LogLevel _minimumLogLevel;
2729
private readonly bool _enableConsoleRepl;
2830
private readonly HashSet<string> _featureFlags;
@@ -32,8 +34,6 @@ internal abstract class PsesLanguageServer
3234
private readonly ProfilePaths _profilePaths;
3335
private readonly TaskCompletionSource<bool> _serverStart;
3436

35-
private ILanguageServer _languageServer;
36-
3737
internal PsesLanguageServer(
3838
ILoggerFactory factory,
3939
LogLevel minimumLogLevel,
@@ -44,7 +44,7 @@ internal PsesLanguageServer(
4444
PSHost internalHost,
4545
ProfilePaths profilePaths)
4646
{
47-
_loggerFactory = factory;
47+
LoggerFactory = factory;
4848
_minimumLogLevel = minimumLogLevel;
4949
_enableConsoleRepl = enableConsoleRepl;
5050
_featureFlags = featureFlags;
@@ -57,10 +57,10 @@ internal PsesLanguageServer(
5757

5858
public async Task StartAsync()
5959
{
60-
_languageServer = await LanguageServer.From(options =>
60+
LanguageServer = await OmniSharp.Extensions.LanguageServer.Server.LanguageServer.From(options =>
6161
{
6262
options.AddDefaultLoggingProvider();
63-
options.LoggerFactory = _loggerFactory;
63+
options.LoggerFactory = LoggerFactory;
6464
ILogger logger = options.LoggerFactory.CreateLogger("OptionsStartup");
6565
options.Services = new ServiceCollection()
6666
.AddSingleton<WorkspaceService>()
@@ -155,14 +155,14 @@ await serviceProvider.GetService<PowerShellContextService>().SetWorkingDirectory
155155
public async Task WaitForShutdown()
156156
{
157157
await _serverStart.Task;
158-
await _languageServer.WaitForExit;
158+
await LanguageServer.WaitForExit;
159159
}
160160

161161
private PowerShellContextService GetFullyInitializedPowerShellContext(
162162
OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer languageServer,
163163
ProfilePaths profilePaths)
164164
{
165-
var logger = _loggerFactory.CreateLogger<PowerShellContextService>();
165+
var logger = LoggerFactory.CreateLogger<PowerShellContextService>();
166166

167167
// PSReadLine can only be used when -EnableConsoleRepl is specified otherwise
168168
// issues arise when redirecting stdio.

0 commit comments

Comments
 (0)