Skip to content

Commit

Permalink
TODO: Use ABCs in these classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
andyleejordan committed Mar 12, 2021
1 parent 105bc89 commit 3194f8a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
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;

namespace Microsoft.PowerShell.EditorServices.Handlers
{
// TODO: Use ABCs.
internal class PsesCodeLensHandlers : ICodeLensHandler, ICodeLensResolveHandler
{
private readonly Guid _id = new Guid();
Expand All @@ -39,13 +39,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 +59,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,6 +21,7 @@

namespace Microsoft.PowerShell.EditorServices.Handlers
{
// TODO: Use ABCs.
internal class PsesCompletionHandler : ICompletionHandler, ICompletionResolveHandler
{
const int DefaultWaitTimeoutMilliseconds = 5000;
Expand Down Expand Up @@ -51,17 +52,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[] { ".", "-", ":", "\\" }
};
}
};

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 +115,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 +143,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 @@ -17,6 +17,7 @@
namespace Microsoft.PowerShell.EditorServices.Handlers
{
// TODO: Add IDocumentOnTypeFormatHandler to support on-type formatting.
// TODO: Use ABCs.
internal class PsesDocumentFormattingHandlers : IDocumentFormattingHandler, IDocumentRangeFormattingHandler
{
private readonly ILogger _logger;
Expand Down

0 comments on commit 3194f8a

Please sign in to comment.