Skip to content

Commit 512df9e

Browse files
Address breaking changes in Omnisharp lib and depend on DocumentUri more (#1300)
* Take 2 * remove dispose * test fixes and ScriptFile uses DocumentUri * delete commented out code * flip IsInMemory check * Codacy and a Windows test failure * Codacy and Rob feedback * use our platform check
1 parent 9e3fbcf commit 512df9e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+796
-425
lines changed

src/PowerShellEditorServices/Extensions/Api/WorkspaceService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ internal EditorScriptFile(
9393
ScriptFile scriptFile)
9494
{
9595
_scriptFile = scriptFile;
96-
Uri = new Uri(scriptFile.DocumentUri);
96+
Uri = scriptFile.DocumentUri.ToUri();
9797
Lines = _scriptFile.FileLines.AsReadOnly();
9898
}
9999

src/PowerShellEditorServices/Extensions/FileContext.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public sealed class FileContext
5050
/// <summary>
5151
/// Gets the URI of the file.
5252
/// </summary>
53-
public Uri Uri { get; }
53+
public Uri Uri { get; }
5454

5555
/// <summary>
5656
/// Gets the parsed token list for the file.
@@ -96,7 +96,7 @@ internal FileContext(
9696
this.editorContext = editorContext;
9797
this.editorOperations = editorOperations;
9898
this.Language = language;
99-
this.Uri = new Uri(scriptFile.DocumentUri);
99+
this.Uri = scriptFile.DocumentUri.ToUri();
100100
}
101101

102102
#endregion
@@ -230,7 +230,7 @@ public void InsertText(
230230
public void InsertText(string textToInsert, IFileRange insertRange)
231231
{
232232
this.editorOperations
233-
.InsertTextAsync(this.scriptFile.ClientFilePath, textToInsert, insertRange.ToBufferRange())
233+
.InsertTextAsync(this.scriptFile.DocumentUri.ToString(), textToInsert, insertRange.ToBufferRange())
234234
.Wait();
235235
}
236236

src/PowerShellEditorServices/Hosting/EditorServicesServerFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
using Microsoft.PowerShell.EditorServices.Services;
1414
using Serilog;
1515
using Serilog.Events;
16-
using OmniSharp.Extensions.LanguageServer.Server;
16+
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
1717

1818
#if DEBUG
1919
using Serilog.Debugging;
@@ -126,7 +126,7 @@ public PsesDebugServer CreateDebugServerForTempSession(Stream inputStream, Strea
126126
.AddPsesLanguageServices(hostStartupInfo)
127127
// For a Temp session, there is no LanguageServer so just set it to null
128128
.AddSingleton(
129-
typeof(OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer),
129+
typeof(ILanguageServer),
130130
_ => null)
131131
.BuildServiceProvider();
132132

src/PowerShellEditorServices/PowerShellEditorServices.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="3.1.4" />
4141
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.4" />
4242
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.17.0-*" />
43+
<PackageReference Include="OmniSharp.Extensions.DebugAdapter.Server" Version="0.17.0-*" />
4344
<PackageReference Include="PowerShellStandard.Library" Version="5.1.1" />
4445
<PackageReference Include="Serilog" Version="2.9.0" />
4546
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
@@ -49,7 +50,6 @@
4950
<PackageReference Include="System.Security.Principal" Version="4.3.0" />
5051
<PackageReference Include="System.Security.Principal.Windows" Version="4.7.0" />
5152
<PackageReference Include="UnixConsoleEcho" Version="0.1.0" />
52-
<PackageReference Include="OmniSharp.Extensions.DebugAdapter.Server" Version="0.17.0-*" />
5353
</ItemGroup>
5454

5555
<ItemGroup>

src/PowerShellEditorServices/Server/PsesLanguageServer.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Microsoft.PowerShell.EditorServices.Handlers;
1111
using Microsoft.PowerShell.EditorServices.Hosting;
1212
using Microsoft.PowerShell.EditorServices.Services;
13+
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
1314
using OmniSharp.Extensions.LanguageServer.Server;
1415
using Serilog;
1516

@@ -68,23 +69,23 @@ public async Task StartAsync()
6869
.AddSerilog(Log.Logger)
6970
.AddLanguageServer(_minimumLogLevel)
7071
.SetMinimumLevel(_minimumLogLevel))
71-
.WithHandler<WorkspaceSymbolsHandler>()
72-
.WithHandler<TextDocumentHandler>()
72+
.WithHandler<PsesWorkspaceSymbolsHandler>()
73+
.WithHandler<PsesTextDocumentHandler>()
7374
.WithHandler<GetVersionHandler>()
74-
.WithHandler<ConfigurationHandler>()
75-
.WithHandler<FoldingRangeHandler>()
76-
.WithHandler<DocumentFormattingHandlers>()
77-
.WithHandler<ReferencesHandler>()
78-
.WithHandler<DocumentSymbolHandler>()
79-
.WithHandler<DocumentHighlightHandler>()
75+
.WithHandler<PsesConfigurationHandler>()
76+
.WithHandler<PsesFoldingRangeHandler>()
77+
.WithHandler<PsesDocumentFormattingHandlers>()
78+
.WithHandler<PsesReferencesHandler>()
79+
.WithHandler<PsesDocumentSymbolHandler>()
80+
.WithHandler<PsesDocumentHighlightHandler>()
8081
.WithHandler<PSHostProcessAndRunspaceHandlers>()
81-
.WithHandler<CodeLensHandlers>()
82-
.WithHandler<CodeActionHandler>()
82+
.WithHandler<PsesCodeLensHandlers>()
83+
.WithHandler<PsesCodeActionHandler>()
8384
.WithHandler<InvokeExtensionCommandHandler>()
84-
.WithHandler<CompletionHandler>()
85-
.WithHandler<HoverHandler>()
86-
.WithHandler<SignatureHelpHandler>()
87-
.WithHandler<DefinitionHandler>()
85+
.WithHandler<PsesCompletionHandler>()
86+
.WithHandler<PsesHoverHandler>()
87+
.WithHandler<PsesSignatureHelpHandler>()
88+
.WithHandler<PsesDefinitionHandler>()
8889
.WithHandler<TemplateHandlers>()
8990
.WithHandler<GetCommentHelpHandler>()
9091
.WithHandler<EvaluateHandler>()

src/PowerShellEditorServices/Services/Analysis/AnalysisService.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using System.Collections.Generic;
1010
using System.IO;
1111
using System.Linq;
12-
using System.Runtime.InteropServices;
1312
using System.Text;
1413
using System.Threading;
1514
using System.Threading.Tasks;
@@ -18,6 +17,7 @@
1817
using Microsoft.PowerShell.EditorServices.Services.Configuration;
1918
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
2019
using OmniSharp.Extensions.LanguageServer.Protocol;
20+
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
2121
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
2222
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
2323

@@ -136,8 +136,7 @@ public AnalysisService(
136136
/// <param name="cancellationToken">A cancellation token to cancel this call with.</param>
137137
/// <returns>A task that finishes when script diagnostics have been published.</returns>
138138
public void RunScriptDiagnostics(
139-
ScriptFile[] filesToAnalyze,
140-
CancellationToken cancellationToken)
139+
ScriptFile[] filesToAnalyze)
141140
{
142141
if (_configurationService.CurrentSettings.ScriptAnalysis.Enable == false)
143142
{
@@ -146,10 +145,8 @@ public void RunScriptDiagnostics(
146145

147146
EnsureEngineSettingsCurrent();
148147

149-
// Create a cancellation token source that will cancel if we do or if the caller does
150-
var cancellationSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
151-
152148
// If there's an existing task, we want to cancel it here;
149+
var cancellationSource = new CancellationTokenSource();
153150
CancellationTokenSource oldTaskCancellation = Interlocked.Exchange(ref _diagnosticsCancellationTokenSource, cancellationSource);
154151
if (oldTaskCancellation != null)
155152
{
@@ -420,9 +417,9 @@ private void PublishScriptDiagnostics(ScriptFile scriptFile, IReadOnlyList<Scrip
420417
diagnostics[i] = diagnostic;
421418
}
422419

423-
_languageServer.Document.PublishDiagnostics(new PublishDiagnosticsParams
420+
_languageServer.TextDocument.PublishDiagnostics(new PublishDiagnosticsParams
424421
{
425-
Uri = DocumentUri.From(scriptFile.DocumentUri),
422+
Uri = scriptFile.DocumentUri,
426423
Diagnostics = new Container<Diagnostic>(diagnostics)
427424
});
428425
}

src/PowerShellEditorServices/Services/CodeLens/PesterCodeLensProvider.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private CodeLens[] GetPesterLens(PesterSymbolReference pesterSymbol, ScriptFile
5555
Data = JToken.FromObject(new {
5656
Uri = scriptFile.DocumentUri,
5757
ProviderId = nameof(PesterCodeLensProvider)
58-
}),
58+
}, Serializer.Instance.JsonSerializer),
5959
Command = new Command()
6060
{
6161
Name = "PowerShell.RunPesterTests",
@@ -66,8 +66,7 @@ private CodeLens[] GetPesterLens(PesterSymbolReference pesterSymbol, ScriptFile
6666
false /* No debug */,
6767
pesterSymbol.TestName,
6868
pesterSymbol.ScriptRegion?.StartLineNumber
69-
},
70-
Serializer.Instance.JsonSerializer)
69+
}, Serializer.Instance.JsonSerializer)
7170
}
7271
},
7372

@@ -77,7 +76,7 @@ private CodeLens[] GetPesterLens(PesterSymbolReference pesterSymbol, ScriptFile
7776
Data = JToken.FromObject(new {
7877
Uri = scriptFile.DocumentUri,
7978
ProviderId = nameof(PesterCodeLensProvider)
80-
}),
79+
}, Serializer.Instance.JsonSerializer),
8180
Command = new Command()
8281
{
8382
Name = "PowerShell.RunPesterTests",

src/PowerShellEditorServices/Services/CodeLens/ReferencesCodeLensProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public CodeLens[] ProvideCodeLenses(ScriptFile scriptFile)
6868
{
6969
Uri = scriptFile.DocumentUri,
7070
ProviderId = nameof(ReferencesCodeLensProvider)
71-
}),
71+
}, Serializer.Instance.JsonSerializer),
7272
Range = sym.ScriptRegion.ToRange()
7373
});
7474
}

src/PowerShellEditorServices/Services/DebugAdapter/Handlers/BreakpointHandlers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public SetExceptionBreakpointsHandler(
8787
DebugService debugService,
8888
DebugStateService debugStateService)
8989
{
90-
_logger = loggerFactory.CreateLogger<SetFunctionBreakpointsHandler>();
90+
_logger = loggerFactory.CreateLogger<SetExceptionBreakpointsHandler>();
9191
_debugService = debugService;
9292
_debugStateService = debugStateService;
9393
}
@@ -133,7 +133,7 @@ public SetBreakpointsHandler(
133133
DebugStateService debugStateService,
134134
WorkspaceService workspaceService)
135135
{
136-
_logger = loggerFactory.CreateLogger<SetFunctionBreakpointsHandler>();
136+
_logger = loggerFactory.CreateLogger<SetBreakpointsHandler>();
137137
_debugService = debugService;
138138
_debugStateService = debugStateService;
139139
_workspaceService = workspaceService;

src/PowerShellEditorServices/Services/DebugAdapter/Handlers/ConfigurationDoneHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public ConfigurationDoneHandler(
3737
PowerShellContextService powerShellContextService,
3838
WorkspaceService workspaceService)
3939
{
40-
_logger = loggerFactory.CreateLogger<SetFunctionBreakpointsHandler>();
40+
_logger = loggerFactory.CreateLogger<ConfigurationDoneHandler>();
4141
_jsonRpcServer = jsonRpcServer;
4242
_debugService = debugService;
4343
_debugStateService = debugStateService;
@@ -106,7 +106,7 @@ private async Task LaunchScriptAsync(string scriptToLaunch)
106106
// By doing this, we light up the ability to debug Untitled files with breakpoints.
107107
// This is only possible via the direct usage of the breakpoint APIs in PowerShell because
108108
// Set-PSBreakpoint validates that paths are actually on the filesystem.
109-
ScriptBlockAst ast = Parser.ParseInput(untitledScript.Contents, untitledScript.DocumentUri, out Token[] tokens, out ParseError[] errors);
109+
ScriptBlockAst ast = Parser.ParseInput(untitledScript.Contents, untitledScript.DocumentUri.ToString(), out Token[] tokens, out ParseError[] errors);
110110

111111
// This seems to be the simplest way to invoke a script block (which contains breakpoint information) via the PowerShell API.
112112
var cmd = new PSCommand().AddScript(". $args[0]").AddArgument(ast.GetScriptBlock());

0 commit comments

Comments
 (0)