Skip to content

Commit

Permalink
WIP OmniSharp update
Browse files Browse the repository at this point in the history
  • Loading branch information
andyleejordan committed Mar 12, 2021
1 parent 95cdc09 commit a384a2c
Show file tree
Hide file tree
Showing 18 changed files with 94 additions and 134 deletions.
2 changes: 1 addition & 1 deletion src/PowerShellEditorServices/Server/PsesLanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public async Task StartAsync()
.AddPsesLanguageServices(_hostDetails))
.ConfigureLogging(builder => builder
.AddSerilog(Log.Logger)
.AddLanguageProtocolLogging(_minimumLogLevel)
.AddLanguageProtocolLogging()
.SetMinimumLevel(_minimumLogLevel))
.WithHandler<PsesWorkspaceSymbolsHandler>()
.WithHandler<PsesTextDocumentHandler>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ private void DebugService_BreakpointUpdated(object sender, BreakpointUpdatedEven
break;
}

OmniSharp.Extensions.DebugAdapter.Protocol.Models.Breakpoint breakpoint;
var breakpoint = new OmniSharp.Extensions.DebugAdapter.Protocol.Models.Breakpoint
{
Verified = e.UpdateType != BreakpointUpdateType.Disabled
};

if (e.Breakpoint is LineBreakpoint)
{
breakpoint = LspDebugUtils.CreateBreakpoint(BreakpointDetails.Create(e.Breakpoint));
Expand All @@ -162,8 +166,6 @@ private void DebugService_BreakpointUpdated(object sender, BreakpointUpdatedEven
return;
}

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

_debugAdapterServer.SendNotification(EventNames.Breakpoint,
new BreakpointEvent
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public DebuggerActionHandlers(
ILoggerFactory loggerFactory,
DebugService debugService)
{
_logger = loggerFactory.CreateLogger<ContinueHandler>();
_logger = loggerFactory.CreateLogger<IContinueHandler>();
_debugService = debugService;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace Microsoft.PowerShell.EditorServices.Handlers
{
internal class PsesLaunchRequestArguments : LaunchRequestArguments
internal record PsesLaunchRequestArguments : LaunchRequestArguments
{
/// <summary>
/// Gets or sets the absolute path to the script to debug.
Expand Down Expand Up @@ -70,7 +70,7 @@ internal class PsesLaunchRequestArguments : LaunchRequestArguments
public Dictionary<string, string> Env { get; set; }
}

internal class PsesAttachRequestArguments : AttachRequestArguments
internal record PsesAttachRequestArguments : AttachRequestArguments
{
public string ComputerName { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ public Task<ThreadsResponse> Handle(ThreadsArguments request, CancellationToken
{
return Task.FromResult(new ThreadsResponse
{
// TODO: What do I do with these?
Threads = new Container<OmniSharp.Extensions.DebugAdapter.Protocol.Models.Thread>(
new OmniSharp.Extensions.DebugAdapter.Protocol.Models.Thread
{
Id = 1,
Name = "Main Thread"
})
// TODO: This is an empty container of threads...do we need to make a thread?

This comment has been minimized.

Copy link
@rjmholt

rjmholt Mar 12, 2021

Contributor

Probably best to ask @david-driscoll about this

This comment has been minimized.

Copy link
@andyleejordan

andyleejordan Mar 12, 2021

Author Member

Better WIP: #1424 (obviously still nowhere close to done)

This comment has been minimized.

Copy link
@andyleejordan

andyleejordan Apr 20, 2021

Author Member

Oops 🤦

Threads = new Container<System.Threading.Thread>()
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@

namespace Microsoft.PowerShell.EditorServices.Handlers
{
internal class PsesCodeActionHandler : ICodeActionHandler
internal class PsesCodeActionHandler : CodeActionHandlerBase
{
private static readonly CodeActionKind[] s_supportedCodeActions = new[]
{
CodeActionKind.QuickFix
};

private readonly CodeActionRegistrationOptions _registrationOptions;

private readonly ILogger _logger;

private readonly AnalysisService _analysisService;
Expand All @@ -41,24 +39,31 @@ public PsesCodeActionHandler(ILoggerFactory factory, AnalysisService analysisSer
_logger = factory.CreateLogger<PsesCodeActionHandler>();
_analysisService = analysisService;
_workspaceService = workspaceService;
_registrationOptions = new CodeActionRegistrationOptions
}

protected override CodeActionRegistrationOptions CreateRegistrationOptions(CodeActionCapability capability, ClientCapabilities clientCapabilities) => new CodeActionRegistrationOptions
{
DocumentSelector = LspUtils.PowerShellDocumentSelector,
// TODO: What do we do with the arguments?

This comment has been minimized.

Copy link
@rjmholt

rjmholt Mar 12, 2021

Contributor
DocumentSelector = LspUtils.PowerShellDocumentSelector,
CodeActionKinds = s_supportedCodeActions
};
}
};

public CodeActionRegistrationOptions GetRegistrationOptions()
public void SetCapability(CodeActionCapability capability)
{
return _registrationOptions;
_capability = capability;
}

public void SetCapability(CodeActionCapability capability)
public override async Task<CodeAction> Handle(CodeAction request, CancellationToken cancellationToken)
{
_capability = capability;
// TODO: How on earth do we handle a CodeAction? This is new...

This comment has been minimized.

Copy link
@rjmholt

rjmholt Mar 12, 2021

Contributor
if (cancellationToken.IsCancellationRequested)
{
_logger.LogDebug("CodeAction request canceled for: {0}", request.Title);
}
return request;
}

public async Task<CommandOrCodeActionContainer> Handle(CodeActionParams request, CancellationToken cancellationToken)
public override async Task<CommandOrCodeActionContainer> Handle(CodeActionParams request, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
Expand Down Expand Up @@ -101,7 +106,7 @@ public async Task<CommandOrCodeActionContainer> Handle(CodeActionParams request,
new WorkspaceEditDocumentChange(
new TextDocumentEdit
{
TextDocument = new VersionedTextDocumentIdentifier
TextDocument = new OptionalVersionedTextDocumentIdentifier
{
Uri = request.TextDocument.Uri
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using Microsoft.PowerShell.EditorServices.Services;
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
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;
Expand All @@ -39,13 +38,15 @@ public PsesCodeLensHandlers(ILoggerFactory factory, SymbolsService symbolsServic
_symbolsService = symbolsService;
}

CodeLensRegistrationOptions IRegistration<CodeLensRegistrationOptions>.GetRegistrationOptions()
public CodeLensRegistrationOptions GetRegistrationOptions(CodeLensCapability capability, ClientCapabilities clientCapabilities) => new CodeLensRegistrationOptions
{
return new CodeLensRegistrationOptions
{
DocumentSelector = LspUtils.PowerShellDocumentSelector,
ResolveProvider = true
};
DocumentSelector = LspUtils.PowerShellDocumentSelector,
ResolveProvider = true
};

public void SetCapability(CodeLensCapability capability, ClientCapabilities clientCapabilities)
{
_capability = capability;
}

public Task<CodeLensContainer> Handle(CodeLensParams request, CancellationToken cancellationToken)
Expand All @@ -57,14 +58,6 @@ public Task<CodeLensContainer> Handle(CodeLensParams request, CancellationToken
return Task.FromResult(new CodeLensContainer(codeLensResults));
}

public TextDocumentRegistrationOptions GetRegistrationOptions()
{
return new TextDocumentRegistrationOptions
{
DocumentSelector = LspUtils.PowerShellDocumentSelector,
};
}

public bool CanResolve(CodeLens value)
{
CodeLensData codeLensData = value.Data.ToObject<CodeLensData>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace Microsoft.PowerShell.EditorServices.Handlers
{
internal class PsesCompletionHandler : ICompletionHandler, ICompletionResolveHandler
internal class PsesCompletionHandler : CompletionHandlerBase
{
const int DefaultWaitTimeoutMilliseconds = 5000;
private readonly SemaphoreSlim _completionLock = AsyncUtils.CreateSimpleLockingSemaphore();
Expand Down Expand Up @@ -51,17 +51,14 @@ public PsesCompletionHandler(
_workspaceService = workspaceService;
}

public CompletionRegistrationOptions GetRegistrationOptions()
protected override CompletionRegistrationOptions CreateRegistrationOptions(CompletionCapability capability, ClientCapabilities clientCapabilities) => new CompletionRegistrationOptions
{
return new CompletionRegistrationOptions
{
DocumentSelector = LspUtils.PowerShellDocumentSelector,
ResolveProvider = true,
TriggerCharacters = new[] { ".", "-", ":", "\\" }
};
}
DocumentSelector = LspUtils.PowerShellDocumentSelector,
ResolveProvider = true,
TriggerCharacters = new[] { ".", "-", ":", "\\" }
};

public async Task<CompletionList> Handle(CompletionParams request, CancellationToken cancellationToken)
public override async Task<CompletionList> Handle(CompletionParams request, CancellationToken cancellationToken)
{
int cursorLine = request.Position.Line + 1;
int cursorColumn = request.Position.Character + 1;
Expand Down Expand Up @@ -117,7 +114,7 @@ public bool CanResolve(CompletionItem value)
}

// Handler for "completionItem/resolve". In VSCode this is fired when a completion item is highlighted in the completion list.
public async Task<CompletionItem> Handle(CompletionItem request, CancellationToken cancellationToken)
public async override Task<CompletionItem> Handle(CompletionItem request, CancellationToken cancellationToken)
{
// We currently only support this request for anything that returns a CommandInfo: functions, cmdlets, aliases.
if (request.Kind != CompletionItemKind.Function)
Expand Down Expand Up @@ -145,10 +142,11 @@ await CommandHelpers.GetCommandInfoAsync(

if (commandInfo != null)
{
request.Documentation =
await CommandHelpers.GetCommandSynopsisAsync(
commandInfo,
_powerShellContextService).ConfigureAwait(false);
return new CompletionItem()
{
// TODO: Do we need to fill in the rest of the fields?
Documentation = await CommandHelpers.GetCommandSynopsisAsync(commandInfo, _powerShellContextService).ConfigureAwait(false)
};
}

// Send back the updated CompletionItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@ public PsesDefinitionHandler(
_workspaceService = workspaceService;
}

public DefinitionRegistrationOptions GetRegistrationOptions()
public DefinitionRegistrationOptions GetRegistrationOptions(DefinitionCapability capability, ClientCapabilities clientCapabilities) => new DefinitionRegistrationOptions
{
return new DefinitionRegistrationOptions
{
DocumentSelector = LspUtils.PowerShellDocumentSelector
};
}
DocumentSelector = LspUtils.PowerShellDocumentSelector
};

public async Task<LocationOrLocationLinks> Handle(DefinitionParams request, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,10 @@ public PsesDocumentHighlightHandler(
_logger.LogInformation("highlight handler loaded");
}

public DocumentHighlightRegistrationOptions GetRegistrationOptions()
public DocumentHighlightRegistrationOptions GetRegistrationOptions(DocumentHighlightCapability capab, ClientCapabilities clientCapabilities) => new DocumentHighlightRegistrationOptions
{
return new DocumentHighlightRegistrationOptions
{
DocumentSelector = LspUtils.PowerShellDocumentSelector
};
}
DocumentSelector = LspUtils.PowerShellDocumentSelector
};

public Task<DocumentHighlightContainer> Handle(
DocumentHighlightParams request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace Microsoft.PowerShell.EditorServices.Handlers
{
internal class PsesDocumentSymbolHandler : IDocumentSymbolHandler
internal class PsesDocumentSymbolHandler : DocumentSymbolHandlerBase
{
private readonly ILogger _logger;
private readonly WorkspaceService _workspaceService;
Expand All @@ -44,15 +44,12 @@ public PsesDocumentSymbolHandler(ILoggerFactory factory, ConfigurationService co
};
}

public DocumentSymbolRegistrationOptions GetRegistrationOptions()
protected override DocumentSymbolRegistrationOptions CreateRegistrationOptions(DocumentSymbolCapability capability, ClientCapabilities clientCapabilities) => new DocumentSymbolRegistrationOptions
{
return new DocumentSymbolRegistrationOptions
{
DocumentSelector = LspUtils.PowerShellDocumentSelector
};
}
DocumentSelector = LspUtils.PowerShellDocumentSelector
};

public Task<SymbolInformationOrDocumentSymbolContainer> Handle(DocumentSymbolParams request, CancellationToken cancellationToken)
public override Task<SymbolInformationOrDocumentSymbolContainer> Handle(DocumentSymbolParams request, CancellationToken cancellationToken)
{
ScriptFile scriptFile = _workspaceService.GetFile(request.TextDocument.Uri);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Microsoft.PowerShell.EditorServices.Handlers
{
internal class PsesFoldingRangeHandler : IFoldingRangeHandler
internal class PsesFoldingRangeHandler : FoldingRangeHandlerBase
{
private readonly ILogger _logger;
private readonly ConfigurationService _configurationService;
Expand All @@ -26,20 +26,17 @@ internal class PsesFoldingRangeHandler : IFoldingRangeHandler

public PsesFoldingRangeHandler(ILoggerFactory factory, ConfigurationService configurationService, WorkspaceService workspaceService)
{
_logger = factory.CreateLogger<FoldingRangeHandler>();
_logger = factory.CreateLogger<PsesFoldingRangeHandler>();
_configurationService = configurationService;
_workspaceService = workspaceService;
}

public FoldingRangeRegistrationOptions GetRegistrationOptions()
protected override FoldingRangeRegistrationOptions CreateRegistrationOptions(FoldingRangeCapability capability, ClientCapabilities clientCapabilities) => new FoldingRangeRegistrationOptions
{
return new FoldingRangeRegistrationOptions
{
DocumentSelector = LspUtils.PowerShellDocumentSelector
};
}
DocumentSelector = LspUtils.PowerShellDocumentSelector
};

public Task<Container<FoldingRange>> Handle(FoldingRangeRequestParam request, CancellationToken cancellationToken)
public override Task<Container<FoldingRange>> Handle(FoldingRangeRequestParam request, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
using Microsoft.PowerShell.EditorServices.Utility;
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
using OmniSharp.Extensions.LanguageServer.Protocol.Document.Proposals;
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Models.Proposals;

namespace Microsoft.PowerShell.EditorServices.Handlers
{
internal class PsesSemanticTokensHandler : SemanticTokensHandlerBase
{
private static readonly SemanticTokensRegistrationOptions s_registrationOptions = new SemanticTokensRegistrationOptions
protected override SemanticTokensRegistrationOptions CreateRegistrationOptions(SemanticTokensCapability capability, ClientCapabilities clientCapabilities) => new SemanticTokensRegistrationOptions
{
DocumentSelector = LspUtils.PowerShellDocumentSelector,
Legend = new SemanticTokensLegend(),
Expand All @@ -36,7 +35,6 @@ internal class PsesSemanticTokensHandler : SemanticTokensHandlerBase
private readonly WorkspaceService _workspaceService;

public PsesSemanticTokensHandler(ILogger<PsesSemanticTokensHandler> logger, WorkspaceService workspaceService)
: base(s_registrationOptions)
{
_logger = logger;
_workspaceService = workspaceService;
Expand Down Expand Up @@ -161,7 +159,7 @@ protected override Task<SemanticTokensDocument> GetSemanticTokensDocument(
ITextDocumentIdentifierParams @params,
CancellationToken cancellationToken)
{
return Task.FromResult(new SemanticTokensDocument(GetRegistrationOptions().Legend));
return Task.FromResult(new SemanticTokensDocument(RegistrationOptions.Legend));
}
}
}
Loading

0 comments on commit a384a2c

Please sign in to comment.