Skip to content
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

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

Merged
Show file tree
Hide file tree
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
Expand Up @@ -93,7 +93,7 @@ internal EditorScriptFile(
ScriptFile scriptFile)
{
_scriptFile = scriptFile;
Uri = new Uri(scriptFile.DocumentUri);
Uri = scriptFile.DocumentUri.ToUri();
Lines = _scriptFile.FileLines.AsReadOnly();
}

Expand Down
6 changes: 3 additions & 3 deletions src/PowerShellEditorServices/Extensions/FileContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand All @@ -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>
Expand Down
29 changes: 15 additions & 14 deletions src/PowerShellEditorServices/Server/PsesLanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -66,8 +66,7 @@ private CodeLens[] GetPesterLens(PesterSymbolReference pesterSymbol, ScriptFile
false /* No debug */,
pesterSymbol.TestName,
pesterSymbol.ScriptRegion?.StartLineNumber
},
Serializer.Instance.JsonSerializer)
}, Serializer.Instance.JsonSerializer)
}
},

Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public CodeLens[] ProvideCodeLenses(ScriptFile scriptFile)
{
Uri = scriptFile.DocumentUri,
ProviderId = nameof(ReferencesCodeLensProvider)
}),
}, Serializer.Instance.JsonSerializer),
Range = sym.ScriptRegion.ToRange()
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public SetExceptionBreakpointsHandler(
DebugService debugService,
DebugStateService debugStateService)
{
_logger = loggerFactory.CreateLogger<SetFunctionBreakpointsHandler>();
_logger = loggerFactory.CreateLogger<SetExceptionBreakpointsHandler>();
_debugService = debugService;
_debugStateService = debugStateService;
}
Expand Down Expand Up @@ -133,7 +133,7 @@ public SetBreakpointsHandler(
DebugStateService debugStateService,
WorkspaceService workspaceService)
{
_logger = loggerFactory.CreateLogger<SetFunctionBreakpointsHandler>();
_logger = loggerFactory.CreateLogger<SetBreakpointsHandler>();
_debugService = debugService;
_debugStateService = debugStateService;
_workspaceService = workspaceService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public ConfigurationDoneHandler(
PowerShellContextService powerShellContextService,
WorkspaceService workspaceService)
{
_logger = loggerFactory.CreateLogger<SetFunctionBreakpointsHandler>();
_logger = loggerFactory.CreateLogger<ConfigurationDoneHandler>();
_jsonRpcServer = jsonRpcServer;
_debugService = debugService;
_debugStateService = debugStateService;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public VariablesHandler(
ILoggerFactory loggerFactory,
DebugService debugService)
{
_logger = loggerFactory.CreateLogger<ScopesHandler>();
_logger = loggerFactory.CreateLogger<VariablesHandler>();
_debugService = debugService;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
{
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading