Skip to content

Commit bedcc39

Browse files
committed
WIP: It builds!
1 parent f5497c1 commit bedcc39

File tree

3 files changed

+31
-49
lines changed

3 files changed

+31
-49
lines changed

src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeLensHandlers.cs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,21 @@
1515
using Microsoft.PowerShell.EditorServices.Services;
1616
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
1717
using Microsoft.PowerShell.EditorServices.Utility;
18-
using OmniSharp.Extensions.LanguageServer.Protocol;
1918
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
2019
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
2120
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
2221

2322
namespace Microsoft.PowerShell.EditorServices.Handlers
2423
{
24+
// TODO: Use ABCs.
2525
internal class PsesCodeLensHandlers : ICodeLensHandler, ICodeLensResolveHandler
2626
{
27-
private readonly Guid _id = new Guid();
2827
private readonly ILogger _logger;
2928
private readonly SymbolsService _symbolsService;
3029
private readonly WorkspaceService _workspaceService;
31-
3230
private CodeLensCapability _capability;
33-
public Guid Id => _id;
31+
private readonly Guid _id = Guid.NewGuid();
32+
Guid ICanBeIdentifiedHandler.Id => _id;
3433

3534
public PsesCodeLensHandlers(ILoggerFactory factory, SymbolsService symbolsService, WorkspaceService workspaceService, ConfigurationService configurationService)
3635
{
@@ -39,13 +38,15 @@ public PsesCodeLensHandlers(ILoggerFactory factory, SymbolsService symbolsServic
3938
_symbolsService = symbolsService;
4039
}
4140

42-
CodeLensRegistrationOptions IRegistration<CodeLensRegistrationOptions>.GetRegistrationOptions()
41+
public CodeLensRegistrationOptions GetRegistrationOptions(CodeLensCapability capability, ClientCapabilities clientCapabilities) => new CodeLensRegistrationOptions
4342
{
44-
return new CodeLensRegistrationOptions
45-
{
46-
DocumentSelector = LspUtils.PowerShellDocumentSelector,
47-
ResolveProvider = true
48-
};
43+
DocumentSelector = LspUtils.PowerShellDocumentSelector,
44+
ResolveProvider = true
45+
};
46+
47+
public void SetCapability(CodeLensCapability capability, ClientCapabilities clientCapabilities)
48+
{
49+
_capability = capability;
4950
}
5051

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

60-
public TextDocumentRegistrationOptions GetRegistrationOptions()
61-
{
62-
return new TextDocumentRegistrationOptions
63-
{
64-
DocumentSelector = LspUtils.PowerShellDocumentSelector,
65-
};
66-
}
67-
6861
public bool CanResolve(CodeLens value)
6962
{
7063
CodeLensData codeLensData = value.Data.ToObject<CodeLensData>();

src/PowerShellEditorServices/Services/TextDocument/Handlers/CompletionHandler.cs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,22 @@
2121

2222
namespace Microsoft.PowerShell.EditorServices.Handlers
2323
{
24+
// TODO: Use ABCs.
2425
internal class PsesCompletionHandler : ICompletionHandler, ICompletionResolveHandler
2526
{
2627
const int DefaultWaitTimeoutMilliseconds = 5000;
2728
private readonly SemaphoreSlim _completionLock = AsyncUtils.CreateSimpleLockingSemaphore();
2829
private readonly SemaphoreSlim _completionResolveLock = AsyncUtils.CreateSimpleLockingSemaphore();
29-
3030
private readonly ILogger _logger;
3131
private readonly PowerShellContextService _powerShellContextService;
3232
private readonly WorkspaceService _workspaceService;
33-
3433
private CompletionResults _mostRecentCompletions;
35-
3634
private int _mostRecentRequestLine;
37-
3835
private int _mostRecentRequestOffest;
39-
4036
private string _mostRecentRequestFile;
41-
4237
private CompletionCapability _capability;
38+
private readonly Guid _id = Guid.NewGuid();
39+
Guid ICanBeIdentifiedHandler.Id => _id;
4340

4441
public PsesCompletionHandler(
4542
ILoggerFactory factory,
@@ -51,15 +48,12 @@ public PsesCompletionHandler(
5148
_workspaceService = workspaceService;
5249
}
5350

54-
public CompletionRegistrationOptions GetRegistrationOptions()
51+
public CompletionRegistrationOptions GetRegistrationOptions(CompletionCapability capability, ClientCapabilities clientCapabilities) => new CompletionRegistrationOptions
5552
{
56-
return new CompletionRegistrationOptions
57-
{
58-
DocumentSelector = LspUtils.PowerShellDocumentSelector,
59-
ResolveProvider = true,
60-
TriggerCharacters = new[] { ".", "-", ":", "\\" }
61-
};
62-
}
53+
DocumentSelector = LspUtils.PowerShellDocumentSelector,
54+
ResolveProvider = true,
55+
TriggerCharacters = new[] { ".", "-", ":", "\\" }
56+
};
6357

6458
public async Task<CompletionList> Handle(CompletionParams request, CancellationToken cancellationToken)
6559
{
@@ -145,10 +139,10 @@ await CommandHelpers.GetCommandInfoAsync(
145139

146140
if (commandInfo != null)
147141
{
148-
request.Documentation =
149-
await CommandHelpers.GetCommandSynopsisAsync(
150-
commandInfo,
151-
_powerShellContextService).ConfigureAwait(false);
142+
request = request with
143+
{
144+
Documentation = await CommandHelpers.GetCommandSynopsisAsync(commandInfo, _powerShellContextService).ConfigureAwait(false)
145+
};
152146
}
153147

154148
// Send back the updated CompletionItem
@@ -160,7 +154,7 @@ await CommandHelpers.GetCommandSynopsisAsync(
160154
}
161155
}
162156

163-
public void SetCapability(CompletionCapability capability)
157+
public void SetCapability(CompletionCapability capability, ClientCapabilities clientCapabilities)
164158
{
165159
_capability = capability;
166160
}

src/PowerShellEditorServices/Services/TextDocument/Handlers/FormattingHandlers.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
namespace Microsoft.PowerShell.EditorServices.Handlers
1818
{
1919
// TODO: Add IDocumentOnTypeFormatHandler to support on-type formatting.
20+
// TODO: Use ABCs.
2021
internal class PsesDocumentFormattingHandlers : IDocumentFormattingHandler, IDocumentRangeFormattingHandler
2122
{
2223
private readonly ILogger _logger;
@@ -39,21 +40,15 @@ public PsesDocumentFormattingHandlers(
3940
_workspaceService = workspaceService;
4041
}
4142

42-
public DocumentFormattingRegistrationOptions GetRegistrationOptions()
43+
public DocumentFormattingRegistrationOptions GetRegistrationOptions(DocumentFormattingCapability capability, ClientCapabilities clientCapabilities) => new DocumentFormattingRegistrationOptions
4344
{
44-
return new DocumentFormattingRegistrationOptions
45-
{
46-
DocumentSelector = LspUtils.PowerShellDocumentSelector
47-
};
48-
}
45+
DocumentSelector = LspUtils.PowerShellDocumentSelector
46+
};
4947

50-
DocumentRangeFormattingRegistrationOptions IRegistration<DocumentRangeFormattingRegistrationOptions>.GetRegistrationOptions()
48+
public DocumentRangeFormattingRegistrationOptions GetRegistrationOptions(DocumentRangeFormattingCapability capability, ClientCapabilities clientCapabilities) => new DocumentRangeFormattingRegistrationOptions
5149
{
52-
return new DocumentRangeFormattingRegistrationOptions
53-
{
54-
DocumentSelector = LspUtils.PowerShellDocumentSelector
55-
};
56-
}
50+
DocumentSelector = LspUtils.PowerShellDocumentSelector
51+
};
5752

5853
public async Task<TextEditContainer> Handle(DocumentFormattingParams request, CancellationToken cancellationToken)
5954
{

0 commit comments

Comments
 (0)