Skip to content

Address breaking changes in Omnisharp lib and depend on DocumentUri more #1300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ internal EditorScriptFile(
ScriptFile scriptFile)
{
_scriptFile = scriptFile;
Uri = new Uri(scriptFile.DocumentUri);
Uri = scriptFile.DocumentUri.ToUri();
Lines = _scriptFile.FileLines.AsReadOnly();
}

6 changes: 3 additions & 3 deletions src/PowerShellEditorServices/Extensions/FileContext.cs
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ public sealed class FileContext
/// <summary>
/// Gets the URI of the file.
/// </summary>
public Uri Uri { get; }
public Uri Uri { get; }

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

#endregion
@@ -230,7 +230,7 @@ public void InsertText(
public void InsertText(string textToInsert, IFileRange insertRange)
{
this.editorOperations
.InsertTextAsync(this.scriptFile.ClientFilePath, textToInsert, insertRange.ToBufferRange())
.InsertTextAsync(this.scriptFile.DocumentUri.ToString(), textToInsert, insertRange.ToBufferRange())
.Wait();
}

Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
using Microsoft.PowerShell.EditorServices.Services;
using Serilog;
using Serilog.Events;
using OmniSharp.Extensions.LanguageServer.Server;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;

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

Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.4" />
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.17.0-*" />
<PackageReference Include="OmniSharp.Extensions.DebugAdapter.Server" Version="0.17.0-*" />
<PackageReference Include="PowerShellStandard.Library" Version="5.1.1" />
<PackageReference Include="Serilog" Version="2.9.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
@@ -49,7 +50,6 @@
<PackageReference Include="System.Security.Principal" Version="4.3.0" />
<PackageReference Include="System.Security.Principal.Windows" Version="4.7.0" />
<PackageReference Include="UnixConsoleEcho" Version="0.1.0" />
<PackageReference Include="OmniSharp.Extensions.DebugAdapter.Server" Version="0.17.0-*" />
</ItemGroup>

<ItemGroup>
29 changes: 15 additions & 14 deletions src/PowerShellEditorServices/Server/PsesLanguageServer.cs
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
using Microsoft.PowerShell.EditorServices.Handlers;
using Microsoft.PowerShell.EditorServices.Hosting;
using Microsoft.PowerShell.EditorServices.Services;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
using OmniSharp.Extensions.LanguageServer.Server;
using Serilog;

@@ -68,23 +69,23 @@ public async Task StartAsync()
.AddSerilog(Log.Logger)
.AddLanguageServer(_minimumLogLevel)
.SetMinimumLevel(_minimumLogLevel))
.WithHandler<WorkspaceSymbolsHandler>()
.WithHandler<TextDocumentHandler>()
.WithHandler<PsesWorkspaceSymbolsHandler>()
.WithHandler<PsesTextDocumentHandler>()
.WithHandler<GetVersionHandler>()
.WithHandler<ConfigurationHandler>()
.WithHandler<FoldingRangeHandler>()
.WithHandler<DocumentFormattingHandlers>()
.WithHandler<ReferencesHandler>()
.WithHandler<DocumentSymbolHandler>()
.WithHandler<DocumentHighlightHandler>()
.WithHandler<PsesConfigurationHandler>()
.WithHandler<PsesFoldingRangeHandler>()
.WithHandler<PsesDocumentFormattingHandlers>()
.WithHandler<PsesReferencesHandler>()
.WithHandler<PsesDocumentSymbolHandler>()
.WithHandler<PsesDocumentHighlightHandler>()
.WithHandler<PSHostProcessAndRunspaceHandlers>()
.WithHandler<CodeLensHandlers>()
.WithHandler<CodeActionHandler>()
.WithHandler<PsesCodeLensHandlers>()
.WithHandler<PsesCodeActionHandler>()
.WithHandler<InvokeExtensionCommandHandler>()
.WithHandler<CompletionHandler>()
.WithHandler<HoverHandler>()
.WithHandler<SignatureHelpHandler>()
.WithHandler<DefinitionHandler>()
.WithHandler<PsesCompletionHandler>()
.WithHandler<PsesHoverHandler>()
.WithHandler<PsesSignatureHelpHandler>()
.WithHandler<PsesDefinitionHandler>()
.WithHandler<TemplateHandlers>()
.WithHandler<GetCommentHelpHandler>()
.WithHandler<EvaluateHandler>()
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -18,6 +17,7 @@
using Microsoft.PowerShell.EditorServices.Services.Configuration;
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
using OmniSharp.Extensions.LanguageServer.Protocol;
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;

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

EnsureEngineSettingsCurrent();

// Create a cancellation token source that will cancel if we do or if the caller does
var cancellationSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);

// If there's an existing task, we want to cancel it here;
var cancellationSource = new CancellationTokenSource();
CancellationTokenSource oldTaskCancellation = Interlocked.Exchange(ref _diagnosticsCancellationTokenSource, cancellationSource);
if (oldTaskCancellation != null)
{
@@ -420,9 +417,9 @@ private void PublishScriptDiagnostics(ScriptFile scriptFile, IReadOnlyList<Scrip
diagnostics[i] = diagnostic;
}

_languageServer.Document.PublishDiagnostics(new PublishDiagnosticsParams
_languageServer.TextDocument.PublishDiagnostics(new PublishDiagnosticsParams
{
Uri = DocumentUri.From(scriptFile.DocumentUri),
Uri = scriptFile.DocumentUri,
Diagnostics = new Container<Diagnostic>(diagnostics)
});
}
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ private CodeLens[] GetPesterLens(PesterSymbolReference pesterSymbol, ScriptFile
Data = JToken.FromObject(new {
Uri = scriptFile.DocumentUri,
ProviderId = nameof(PesterCodeLensProvider)
}),
}, Serializer.Instance.JsonSerializer),
Command = new Command()
{
Name = "PowerShell.RunPesterTests",
@@ -66,8 +66,7 @@ private CodeLens[] GetPesterLens(PesterSymbolReference pesterSymbol, ScriptFile
false /* No debug */,
pesterSymbol.TestName,
pesterSymbol.ScriptRegion?.StartLineNumber
},
Serializer.Instance.JsonSerializer)
}, Serializer.Instance.JsonSerializer)
}
},

@@ -77,7 +76,7 @@ private CodeLens[] GetPesterLens(PesterSymbolReference pesterSymbol, ScriptFile
Data = JToken.FromObject(new {
Uri = scriptFile.DocumentUri,
ProviderId = nameof(PesterCodeLensProvider)
}),
}, Serializer.Instance.JsonSerializer),
Command = new Command()
{
Name = "PowerShell.RunPesterTests",
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ public CodeLens[] ProvideCodeLenses(ScriptFile scriptFile)
{
Uri = scriptFile.DocumentUri,
ProviderId = nameof(ReferencesCodeLensProvider)
}),
}, Serializer.Instance.JsonSerializer),
Range = sym.ScriptRegion.ToRange()
});
}
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ public SetExceptionBreakpointsHandler(
DebugService debugService,
DebugStateService debugStateService)
{
_logger = loggerFactory.CreateLogger<SetFunctionBreakpointsHandler>();
_logger = loggerFactory.CreateLogger<SetExceptionBreakpointsHandler>();
_debugService = debugService;
_debugStateService = debugStateService;
}
@@ -133,7 +133,7 @@ public SetBreakpointsHandler(
DebugStateService debugStateService,
WorkspaceService workspaceService)
{
_logger = loggerFactory.CreateLogger<SetFunctionBreakpointsHandler>();
_logger = loggerFactory.CreateLogger<SetBreakpointsHandler>();
_debugService = debugService;
_debugStateService = debugStateService;
_workspaceService = workspaceService;
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ public ConfigurationDoneHandler(
PowerShellContextService powerShellContextService,
WorkspaceService workspaceService)
{
_logger = loggerFactory.CreateLogger<SetFunctionBreakpointsHandler>();
_logger = loggerFactory.CreateLogger<ConfigurationDoneHandler>();
_jsonRpcServer = jsonRpcServer;
_debugService = debugService;
_debugStateService = debugStateService;
@@ -106,7 +106,7 @@ private async Task LaunchScriptAsync(string scriptToLaunch)
// By doing this, we light up the ability to debug Untitled files with breakpoints.
// This is only possible via the direct usage of the breakpoint APIs in PowerShell because
// Set-PSBreakpoint validates that paths are actually on the filesystem.
ScriptBlockAst ast = Parser.ParseInput(untitledScript.Contents, untitledScript.DocumentUri, out Token[] tokens, out ParseError[] errors);
ScriptBlockAst ast = Parser.ParseInput(untitledScript.Contents, untitledScript.DocumentUri.ToString(), out Token[] tokens, out ParseError[] errors);

// This seems to be the simplest way to invoke a script block (which contains breakpoint information) via the PowerShell API.
var cmd = new PSCommand().AddScript(". $args[0]").AddArgument(ast.GetScriptBlock());
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ public VariablesHandler(
ILoggerFactory loggerFactory,
DebugService debugService)
{
_logger = loggerFactory.CreateLogger<ScopesHandler>();
_logger = loggerFactory.CreateLogger<VariablesHandler>();
_debugService = debugService;
}

Original file line number Diff line number Diff line change
@@ -10,10 +10,10 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.PowerShell.EditorServices.Services;
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
using Microsoft.PowerShell.EditorServices.Utility;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
using OmniSharp.Extensions.LanguageServer.Protocol.Window;

namespace Microsoft.PowerShell.EditorServices.Handlers
{
@@ -96,7 +96,7 @@ private async Task CheckPackageManagement()
}

var takeActionText = "Yes";
MessageActionItem messageAction = await _languageServer.Window.ShowMessage(new ShowMessageRequestParams
MessageActionItem messageAction = await _languageServer.Window.ShowMessageRequest(new ShowMessageRequestParams
{
Message = "You have an older version of PackageManagement known to cause issues with the PowerShell extension. Would you like to update PackageManagement (You will need to restart the PowerShell extension after)?",
Type = MessageType.Warning,
Original file line number Diff line number Diff line change
@@ -17,12 +17,12 @@ namespace Microsoft.PowerShell.EditorServices.Handlers

internal class PSHostProcessAndRunspaceHandlers : IGetPSHostProcessesHandler, IGetRunspaceHandler
{
private readonly ILogger<GetVersionHandler> _logger;
private readonly ILogger<PSHostProcessAndRunspaceHandlers> _logger;
private readonly PowerShellContextService _powerShellContextService;

public PSHostProcessAndRunspaceHandlers(ILoggerFactory factory, PowerShellContextService powerShellContextService)
{
_logger = factory.CreateLogger<GetVersionHandler>();
_logger = factory.CreateLogger<PSHostProcessAndRunspaceHandlers>();
_powerShellContextService = powerShellContextService;
}

Original file line number Diff line number Diff line change
@@ -14,14 +14,14 @@ namespace Microsoft.PowerShell.EditorServices.Handlers
{
internal class TemplateHandlers : IGetProjectTemplatesHandler, INewProjectFromTemplateHandler
{
private readonly ILogger<GetVersionHandler> _logger;
private readonly ILogger<TemplateHandlers> _logger;
private readonly TemplateService _templateService;

public TemplateHandlers(
ILoggerFactory factory,
TemplateService templateService)
{
_logger = factory.CreateLogger<GetVersionHandler>();
_logger = factory.CreateLogger<TemplateHandlers>();
_templateService = templateService;
}

Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ namespace Microsoft.PowerShell.EditorServices.Services
/// Handles nested PowerShell prompts and also manages execution of
/// commands whether inside or outside of the debugger.
/// </summary>
internal class PowerShellContextService : IDisposable, IHostSupportsInteractiveSession
internal class PowerShellContextService : IHostSupportsInteractiveSession
{
private static readonly string s_commandsModulePath = Path.GetFullPath(
Path.Combine(
@@ -1402,11 +1402,12 @@ private void ResumeDebugger(DebuggerResumeAction resumeAction, bool shouldWaitFo
}

/// <summary>
/// Disposes the runspace and any other resources being used
/// Closes the runspace and any other resources being used
/// by this PowerShellContext.
/// </summary>
public void Dispose()
public void Close()
{
logger.LogDebug("Closing PowerShellContextService...");
this.PromptNest.Dispose();
this.SessionState = PowerShellContextState.Disposed;

Original file line number Diff line number Diff line change
@@ -50,7 +50,8 @@ public override AstVisitAction VisitFunctionDefinition(FunctionDefinitionAst fun
StartLineNumber = functionDefinitionAst.Extent.StartLineNumber,
StartColumnNumber = startColumnNumber,
EndLineNumber = functionDefinitionAst.Extent.StartLineNumber,
EndColumnNumber = startColumnNumber + functionDefinitionAst.Name.Length
EndColumnNumber = startColumnNumber + functionDefinitionAst.Name.Length,
File = functionDefinitionAst.Extent.File
};

if (symbolRef.SymbolType.Equals(SymbolType.Function) &&
Original file line number Diff line number Diff line change
@@ -129,7 +129,8 @@ public override AstVisitAction VisitHashtable(HashtableAst hashtableAst)
StartLineNumber = kvp.Item1.Extent.StartLineNumber,
EndLineNumber = kvp.Item2.Extent.EndLineNumber,
StartColumnNumber = kvp.Item1.Extent.StartColumnNumber,
EndColumnNumber = kvp.Item2.Extent.EndColumnNumber
EndColumnNumber = kvp.Item2.Extent.EndColumnNumber,
File = hashtableAst.Extent.File
};

SymbolType symbolType = SymbolType.HashtableKey;
Original file line number Diff line number Diff line change
@@ -14,12 +14,12 @@
using Microsoft.PowerShell.EditorServices.Utility;
using Newtonsoft.Json.Linq;
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;

namespace Microsoft.PowerShell.EditorServices.Handlers
{
internal class CodeActionHandler : ICodeActionHandler
internal class PsesCodeActionHandler : ICodeActionHandler
{
private static readonly CodeActionKind[] s_supportedCodeActions = new[]
{
@@ -36,9 +36,9 @@ internal class CodeActionHandler : ICodeActionHandler

private CodeActionCapability _capability;

public CodeActionHandler(ILoggerFactory factory, AnalysisService analysisService, WorkspaceService workspaceService)
public PsesCodeActionHandler(ILoggerFactory factory, AnalysisService analysisService, WorkspaceService workspaceService)
{
_logger = factory.CreateLogger<TextDocumentHandler>();
_logger = factory.CreateLogger<PsesCodeActionHandler>();
_analysisService = analysisService;
_workspaceService = workspaceService;
_registrationOptions = new CodeActionRegistrationOptions
Original file line number Diff line number Diff line change
@@ -17,22 +17,22 @@
using Microsoft.PowerShell.EditorServices.Utility;
using OmniSharp.Extensions.LanguageServer.Protocol;
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;

namespace Microsoft.PowerShell.EditorServices.Handlers
{
internal class CodeLensHandlers : ICodeLensHandler, ICodeLensResolveHandler
internal class PsesCodeLensHandlers : ICodeLensHandler, ICodeLensResolveHandler
{
private readonly ILogger _logger;
private readonly SymbolsService _symbolsService;
private readonly WorkspaceService _workspaceService;

private CodeLensCapability _capability;

public CodeLensHandlers(ILoggerFactory factory, SymbolsService symbolsService, WorkspaceService workspaceService, ConfigurationService configurationService)
public PsesCodeLensHandlers(ILoggerFactory factory, SymbolsService symbolsService, WorkspaceService workspaceService, ConfigurationService configurationService)
{
_logger = factory.CreateLogger<FoldingRangeHandler>();
_logger = factory.CreateLogger<PsesCodeLensHandlers>();
_workspaceService = workspaceService;
_symbolsService = symbolsService;
}
Loading