Skip to content

Commit b243fe3

Browse files
Move to Omnisharp lib 0.18.x (#1376)
* raname * move to 0.18.1 * almost working * merge launch and attach and handle onstarted * merge handler classes into classes that make sense * debugging works the first time now! * dispose of streams * remove initializeHandler since it's covered by OnInitialize* * add DAP E2E tests! * use taskcompletionsource * new up TCS * move to 0.18.2 * misc comments and feedback
1 parent 407fcee commit b243fe3

28 files changed

+397
-376
lines changed

src/PowerShellEditorServices/Extensions/Api/EditorContextService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ public interface IEditorContextService
8484

8585
internal class EditorContextService : IEditorContextService
8686
{
87-
private readonly ILanguageServer _languageServer;
87+
private readonly ILanguageServerFacade _languageServer;
8888

8989
internal EditorContextService(
90-
ILanguageServer languageServer)
90+
ILanguageServerFacade languageServer)
9191
{
9292
_languageServer = languageServer;
9393
}

src/PowerShellEditorServices/Extensions/Api/EditorExtensionServiceProvider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public class EditorExtensionServiceProvider
4343
internal EditorExtensionServiceProvider(IServiceProvider serviceProvider)
4444
{
4545
_serviceProvider = serviceProvider;
46-
LanguageServer = new LanguageServerService(_serviceProvider.GetService<ILanguageServer>());
46+
LanguageServer = new LanguageServerService(_serviceProvider.GetService<ILanguageServerFacade>());
4747
//DocumentSymbols = new DocumentSymbolService(_serviceProvider.GetService<SymbolsService>());
4848
ExtensionCommands = new ExtensionCommandService(_serviceProvider.GetService<ExtensionService>());
4949
Workspace = new WorkspaceService(_serviceProvider.GetService<Internal.WorkspaceService>());
50-
EditorContext = new EditorContextService(_serviceProvider.GetService<ILanguageServer>());
51-
EditorUI = new EditorUIService(_serviceProvider.GetService<ILanguageServer>());
50+
EditorContext = new EditorContextService(_serviceProvider.GetService<ILanguageServerFacade>());
51+
EditorUI = new EditorUIService(_serviceProvider.GetService<ILanguageServerFacade>());
5252
}
5353

5454
/// <summary>
@@ -143,7 +143,7 @@ public object GetServiceByAssemblyQualifiedName(string asmQualifiedTypeName)
143143
/// <remarks>
144144
/// This method is intended as a trapdoor and should not be used in the first instance.
145145
/// Consider using the public extension services if possible.
146-
///
146+
///
147147
/// Also note that services in PSES may live in a separate assembly load context,
148148
/// meaning that a type of the seemingly correct name may fail to fetch to a service
149149
/// that is known under a type of the same name but loaded in a different context.

src/PowerShellEditorServices/Extensions/Api/EditorUIService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ internal class EditorUIService : IEditorUIService
103103
{
104104
private static string[] s_choiceResponseLabelSeparators = new[] { ", " };
105105

106-
private readonly ILanguageServer _languageServer;
106+
private readonly ILanguageServerFacade _languageServer;
107107

108-
public EditorUIService(ILanguageServer languageServer)
108+
public EditorUIService(ILanguageServerFacade languageServer)
109109
{
110110
_languageServer = languageServer;
111111
}

src/PowerShellEditorServices/Extensions/Api/LanguageServerService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public interface ILanguageServerService
6666

6767
internal class LanguageServerService : ILanguageServerService
6868
{
69-
private readonly ILanguageServer _languageServer;
69+
private readonly ILanguageServerFacade _languageServer;
7070

71-
internal LanguageServerService(ILanguageServer languageServer)
71+
internal LanguageServerService(ILanguageServerFacade languageServer)
7272
{
7373
_languageServer = languageServer;
7474
}

src/PowerShellEditorServices/Hosting/EditorServicesServerFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ public PsesDebugServer CreateDebugServerForTempSession(Stream inputStream, Strea
122122
.ClearProviders()
123123
.AddSerilog()
124124
.SetMinimumLevel(LogLevel.Trace))
125-
.AddSingleton<ILanguageServer>(provider => null)
125+
.AddSingleton<ILanguageServerFacade>(provider => null)
126126
.AddPsesLanguageServices(hostStartupInfo)
127127
// For a Temp session, there is no LanguageServer so just set it to null
128128
.AddSingleton(
129-
typeof(ILanguageServer),
129+
typeof(ILanguageServerFacade),
130130
_ => null)
131131
.BuildServiceProvider();
132132

src/PowerShellEditorServices/PowerShellEditorServices.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
4040
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="3.1.9" />
4141
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.9" />
42-
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.17.4" />
43-
<PackageReference Include="OmniSharp.Extensions.DebugAdapter.Server" Version="0.17.4" />
42+
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.18.2" />
43+
<PackageReference Include="OmniSharp.Extensions.DebugAdapter.Server" Version="0.18.2" />
4444
<PackageReference Include="PowerShellStandard.Library" Version="5.1.1" />
4545
<PackageReference Include="Serilog" Version="2.10.0" />
4646
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />

src/PowerShellEditorServices/Server/PsesDebugServer.cs

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
using Microsoft.PowerShell.EditorServices.Handlers;
1414
using Microsoft.PowerShell.EditorServices.Services;
1515
using Microsoft.PowerShell.EditorServices.Utility;
16+
using OmniSharp.Extensions.DebugAdapter.Protocol;
1617
using OmniSharp.Extensions.DebugAdapter.Protocol.Serialization;
18+
using OmniSharp.Extensions.DebugAdapter.Server;
1719
using OmniSharp.Extensions.JsonRpc;
1820
using OmniSharp.Extensions.LanguageServer.Server;
1921

@@ -41,7 +43,7 @@ internal class PsesDebugServer : IDisposable
4143
private readonly bool _usePSReadLine;
4244
private readonly TaskCompletionSource<bool> _serverStopped;
4345

44-
private IJsonRpcServer _jsonRpcServer;
46+
private DebugAdapterServer _debugAdapterServer;
4547
private PowerShellContextService _powerShellContextService;
4648

4749
protected readonly ILoggerFactory _loggerFactory;
@@ -71,13 +73,8 @@ public PsesDebugServer(
7173
/// <returns>A task that completes when the server is ready.</returns>
7274
public async Task StartAsync()
7375
{
74-
_jsonRpcServer = await JsonRpcServer.From(options =>
76+
_debugAdapterServer = await DebugAdapterServer.From(options =>
7577
{
76-
options.Serializer = new DapProtocolSerializer();
77-
options.Receiver = new DapReceiver();
78-
options.LoggerFactory = _loggerFactory;
79-
ILogger logger = options.LoggerFactory.CreateLogger("DebugOptionsStartup");
80-
8178
// We need to let the PowerShell Context Service know that we are in a debug session
8279
// so that it doesn't send the powerShell/startDebugger message.
8380
_powerShellContextService = ServiceProvider.GetService<PowerShellContextService>();
@@ -97,45 +94,53 @@ public async Task StartAsync()
9794
.GetResult();
9895
}
9996

100-
options.Services = new ServiceCollection()
101-
.AddPsesDebugServices(ServiceProvider, this, _useTempSession);
102-
10397
options
10498
.WithInput(_inputStream)
105-
.WithOutput(_outputStream);
106-
107-
logger.LogInformation("Adding handlers");
108-
109-
options
110-
.WithHandler<InitializeHandler>()
111-
.WithHandler<LaunchHandler>()
112-
.WithHandler<AttachHandler>()
99+
.WithOutput(_outputStream)
100+
.WithServices(serviceCollection => serviceCollection
101+
.AddLogging()
102+
.AddOptions()
103+
.AddPsesDebugServices(ServiceProvider, this, _useTempSession))
104+
.WithHandler<LaunchAndAttachHandler>()
113105
.WithHandler<DisconnectHandler>()
114-
.WithHandler<SetFunctionBreakpointsHandler>()
115-
.WithHandler<SetExceptionBreakpointsHandler>()
106+
.WithHandler<BreakpointHandlers>()
116107
.WithHandler<ConfigurationDoneHandler>()
117108
.WithHandler<ThreadsHandler>()
118-
.WithHandler<SetBreakpointsHandler>()
119109
.WithHandler<StackTraceHandler>()
120110
.WithHandler<ScopesHandler>()
121111
.WithHandler<VariablesHandler>()
122-
.WithHandler<ContinueHandler>()
123-
.WithHandler<NextHandler>()
124-
.WithHandler<PauseHandler>()
125-
.WithHandler<StepInHandler>()
126-
.WithHandler<StepOutHandler>()
112+
.WithHandler<DebuggerActionHandlers>()
127113
.WithHandler<SourceHandler>()
128114
.WithHandler<SetVariableHandler>()
129-
.WithHandler<DebugEvaluateHandler>();
130-
131-
logger.LogInformation("Handlers added");
115+
.WithHandler<DebugEvaluateHandler>()
116+
// The OnInitialize delegate gets run when we first receive the _Initialize_ request:
117+
// https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Initialize
118+
.OnInitialize(async (server, request, cancellationToken) => {
119+
var breakpointService = server.GetService<BreakpointService>();
120+
// Clear any existing breakpoints before proceeding
121+
await breakpointService.RemoveAllBreakpointsAsync().ConfigureAwait(false);
122+
})
123+
// The OnInitialized delegate gets run right before the server responds to the _Initialize_ request:
124+
// https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Initialize
125+
.OnInitialized((server, request, response, cancellationToken) => {
126+
response.SupportsConditionalBreakpoints = true;
127+
response.SupportsConfigurationDoneRequest = true;
128+
response.SupportsFunctionBreakpoints = true;
129+
response.SupportsHitConditionalBreakpoints = true;
130+
response.SupportsLogPoints = true;
131+
response.SupportsSetVariable = true;
132+
133+
return Task.CompletedTask;
134+
});
132135
}).ConfigureAwait(false);
133136
}
134137

135138
public void Dispose()
136139
{
137140
_powerShellContextService.IsDebugServerActive = false;
138-
_jsonRpcServer.Dispose();
141+
_debugAdapterServer.Dispose();
142+
_inputStream.Dispose();
143+
_outputStream.Dispose();
139144
_serverStopped.SetResult(true);
140145
}
141146

src/PowerShellEditorServices/Server/PsesServiceCollectionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static IServiceCollection AddPsesLanguageServices(
2626
(provider) =>
2727
PowerShellContextService.Create(
2828
provider.GetService<ILoggerFactory>(),
29-
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>(),
29+
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServerFacade>(),
3030
hostStartupInfo))
3131
.AddSingleton<TemplateService>()
3232
.AddSingleton<EditorOperationsService>()
@@ -36,7 +36,7 @@ public static IServiceCollection AddPsesLanguageServices(
3636
{
3737
var extensionService = new ExtensionService(
3838
provider.GetService<PowerShellContextService>(),
39-
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>());
39+
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServerFacade>());
4040
extensionService.InitializeAsync(
4141
serviceProvider: provider,
4242
editorOperations: provider.GetService<EditorOperationsService>())

src/PowerShellEditorServices/Services/Analysis/AnalysisService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ internal static string GetUniqueIdFromDiagnostic(Diagnostic diagnostic)
8484

8585
private readonly ILogger _logger;
8686

87-
private readonly ILanguageServer _languageServer;
87+
private readonly ILanguageServerFacade _languageServer;
8888

8989
private readonly ConfigurationService _configurationService;
9090

@@ -109,7 +109,7 @@ internal static string GetUniqueIdFromDiagnostic(Diagnostic diagnostic)
109109
/// <param name="workspaceService">The workspace service for file handling within a workspace.</param>
110110
public AnalysisService(
111111
ILoggerFactory loggerFactory,
112-
ILanguageServer languageServer,
112+
ILanguageServerFacade languageServer,
113113
ConfigurationService configurationService,
114114
WorkspaceService workspaceService)
115115
{

src/PowerShellEditorServices/Services/DebugAdapter/DebugEventHandlerService.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
1010
using Microsoft.PowerShell.EditorServices.Utility;
1111
using OmniSharp.Extensions.DebugAdapter.Protocol.Events;
12-
using OmniSharp.Extensions.JsonRpc;
12+
using OmniSharp.Extensions.DebugAdapter.Protocol.Server;
1313

1414
namespace Microsoft.PowerShell.EditorServices.Services
1515
{
@@ -19,20 +19,20 @@ internal class DebugEventHandlerService
1919
private readonly PowerShellContextService _powerShellContextService;
2020
private readonly DebugService _debugService;
2121
private readonly DebugStateService _debugStateService;
22-
private readonly IJsonRpcServer _jsonRpcServer;
22+
private readonly IDebugAdapterServerFacade _debugAdapterServer;
2323

2424
public DebugEventHandlerService(
2525
ILoggerFactory factory,
2626
PowerShellContextService powerShellContextService,
2727
DebugService debugService,
2828
DebugStateService debugStateService,
29-
IJsonRpcServer jsonRpcServer)
29+
IDebugAdapterServerFacade debugAdapterServer)
3030
{
3131
_logger = factory.CreateLogger<DebugEventHandlerService>();
3232
_powerShellContextService = powerShellContextService;
3333
_debugService = debugService;
3434
_debugStateService = debugStateService;
35-
_jsonRpcServer = jsonRpcServer;
35+
_debugAdapterServer = debugAdapterServer;
3636
}
3737

3838
internal void RegisterEventHandlers()
@@ -79,7 +79,7 @@ e.OriginalEvent.Breakpoints[0] is CommandBreakpoint
7979
: "breakpoint";
8080
}
8181

82-
_jsonRpcServer.SendNotification(EventNames.Stopped,
82+
_debugAdapterServer.SendNotification(EventNames.Stopped,
8383
new StoppedEvent
8484
{
8585
ThreadId = 1,
@@ -93,10 +93,10 @@ private void PowerShellContext_RunspaceChanged(object sender, RunspaceChangedEve
9393
e.ChangeAction == RunspaceChangeAction.Enter &&
9494
e.NewRunspace.Context == RunspaceContext.DebuggedRunspace)
9595
{
96-
// Send the InitializedEvent so that the debugger will continue
96+
// Sends the InitializedEvent so that the debugger will continue
9797
// sending configuration requests
9898
_debugStateService.WaitingForAttach = false;
99-
_jsonRpcServer.SendNotification(EventNames.Initialized);
99+
_debugStateService.ServerStarted.SetResult(true);
100100
}
101101
else if (
102102
e.ChangeAction == RunspaceChangeAction.Exit &&
@@ -105,7 +105,7 @@ private void PowerShellContext_RunspaceChanged(object sender, RunspaceChangedEve
105105
// Exited the session while the debugger is stopped,
106106
// send a ContinuedEvent so that the client changes the
107107
// UI to appear to be running again
108-
_jsonRpcServer.SendNotification(EventNames.Continued,
108+
_debugAdapterServer.SendNotification(EventNames.Continued,
109109
new ContinuedEvent
110110
{
111111
ThreadId = 1,
@@ -116,7 +116,7 @@ private void PowerShellContext_RunspaceChanged(object sender, RunspaceChangedEve
116116

117117
private void PowerShellContext_DebuggerResumed(object sender, DebuggerResumeAction e)
118118
{
119-
_jsonRpcServer.SendNotification(EventNames.Continued,
119+
_debugAdapterServer.SendNotification(EventNames.Continued,
120120
new ContinuedEvent
121121
{
122122
AllThreadsContinued = true,
@@ -164,7 +164,7 @@ private void DebugService_BreakpointUpdated(object sender, BreakpointUpdatedEven
164164

165165
breakpoint.Verified = e.UpdateType != BreakpointUpdateType.Disabled;
166166

167-
_jsonRpcServer.SendNotification(EventNames.Breakpoint,
167+
_debugAdapterServer.SendNotification(EventNames.Breakpoint,
168168
new BreakpointEvent
169169
{
170170
Reason = reason,

src/PowerShellEditorServices/Services/DebugAdapter/DebugStateService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ internal class DebugStateService
3838

3939
internal bool IsUsingTempIntegratedConsole { get; set; }
4040

41+
// This gets set at the end of the Launch/Attach handler which set debug state.
42+
internal TaskCompletionSource<bool> ServerStarted { get; set; }
43+
4144
internal void ReleaseSetBreakpointHandle()
4245
{
4346
_setBreakpointInProgressHandle.Release();

0 commit comments

Comments
 (0)