diff --git a/src/PowerShellEditorServices/PowerShellEditorServices.csproj b/src/PowerShellEditorServices/PowerShellEditorServices.csproj index 0a9c845f0..b4726773b 100644 --- a/src/PowerShellEditorServices/PowerShellEditorServices.csproj +++ b/src/PowerShellEditorServices/PowerShellEditorServices.csproj @@ -39,7 +39,7 @@ - + @@ -49,7 +49,7 @@ - + diff --git a/src/PowerShellEditorServices/Server/PsesDebugServer.cs b/src/PowerShellEditorServices/Server/PsesDebugServer.cs index 81ef23e55..ea570a0d3 100644 --- a/src/PowerShellEditorServices/Server/PsesDebugServer.cs +++ b/src/PowerShellEditorServices/Server/PsesDebugServer.cs @@ -66,7 +66,7 @@ public async Task StartAsync() _jsonRpcServer = await JsonRpcServer.From(options => { options.Serializer = new DapProtocolSerializer(); - options.Reciever = new DapReciever(); + options.Receiver = new DapReceiver(); options.LoggerFactory = _loggerFactory; ILogger logger = options.LoggerFactory.CreateLogger("DebugOptionsStartup"); diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeActionHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeActionHandler.cs index 053e6a2b0..7a9508192 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeActionHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeActionHandler.cs @@ -60,14 +60,18 @@ public void SetCapability(CodeActionCapability capability) public async Task Handle(CodeActionParams request, CancellationToken cancellationToken) { + if (cancellationToken.IsCancellationRequested) + { + return Array.Empty(); + } + // On Windows, VSCode still gives us file URIs like "file:///c%3a/...", so we need to escape them IReadOnlyDictionary corrections = await _analysisService.GetMostRecentCodeActionsForFileAsync( _workspaceService.GetFile(request.TextDocument.Uri)).ConfigureAwait(false); if (corrections == null) { - // TODO: Find out if we can cache this empty value - return new CommandOrCodeActionContainer(); + return Array.Empty(); } var codeActions = new List(); @@ -100,7 +104,7 @@ public async Task Handle(CodeActionParams request, { Uri = request.TextDocument.Uri }, - Edits = new Container(correction.Edits.Select(ScriptRegion.ToTextEdit)) + Edits = new TextEditContainer(correction.Edits.Select(ScriptRegion.ToTextEdit)) })) } }); diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/CompletionHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/CompletionHandler.cs index 654f8a92e..ffb10178d 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/CompletionHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/CompletionHandler.cs @@ -24,7 +24,7 @@ namespace Microsoft.PowerShell.EditorServices.Handlers internal class CompletionHandler : ICompletionHandler, ICompletionResolveHandler { const int DefaultWaitTimeoutMilliseconds = 5000; - private readonly CompletionItem[] s_emptyCompletionResult = Array.Empty(); + private readonly SemaphoreSlim _completionLock = AsyncUtils.CreateSimpleLockingSemaphore(); private readonly ILogger _logger; private readonly PowerShellContextService _powerShellContextService; @@ -67,24 +67,39 @@ public async Task Handle(CompletionParams request, CancellationT ScriptFile scriptFile = _workspaceService.GetFile(request.TextDocument.Uri); - CompletionResults completionResults = - await GetCompletionsInFileAsync( - scriptFile, - cursorLine, - cursorColumn).ConfigureAwait(false); + await _completionLock.WaitAsync().ConfigureAwait(false); - CompletionItem[] completionItems = s_emptyCompletionResult; - - if (completionResults != null) + try { - completionItems = new CompletionItem[completionResults.Completions.Length]; + if (cancellationToken.IsCancellationRequested) + { + _logger.LogDebug("Completion request canceled for file: {0}", request.TextDocument.Uri); + return Array.Empty(); + } + + CompletionResults completionResults = + await GetCompletionsInFileAsync( + scriptFile, + cursorLine, + cursorColumn).ConfigureAwait(false); + + if (completionResults == null) + { + return Array.Empty(); + } + + CompletionItem[] completionItems = new CompletionItem[completionResults.Completions.Length]; for (int i = 0; i < completionItems.Length; i++) { completionItems[i] = CreateCompletionItem(completionResults.Completions[i], completionResults.ReplacedRange, i + 1); } - } - return new CompletionList(completionItems); + return completionItems; + } + finally + { + _completionLock.Release(); + } } public bool CanResolve(CompletionItem value) diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DefinitionHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DefinitionHandler.cs index bf500acf3..b9173b949 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DefinitionHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DefinitionHandler.cs @@ -35,9 +35,9 @@ public DefinitionHandler( _workspaceService = workspaceService; } - public TextDocumentRegistrationOptions GetRegistrationOptions() + public DefinitionRegistrationOptions GetRegistrationOptions() { - return new TextDocumentRegistrationOptions + return new DefinitionRegistrationOptions { DocumentSelector = LspUtils.PowerShellDocumentSelector }; diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentHighlightHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentHighlightHandler.cs index 9181e490f..34b3da768 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentHighlightHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentHighlightHandler.cs @@ -27,8 +27,6 @@ internal class DocumentHighlightHandler : IDocumentHighlightHandler private readonly SymbolsService _symbolsService; - private readonly TextDocumentRegistrationOptions _registrationOptions; - private DocumentHighlightCapability _capability; public DocumentHighlightHandler( @@ -36,19 +34,18 @@ public DocumentHighlightHandler( WorkspaceService workspaceService, SymbolsService symbolService) { - _logger = loggerFactory.CreateLogger(); + _logger = loggerFactory.CreateLogger(); _workspaceService = workspaceService; _symbolsService = symbolService; - _registrationOptions = new TextDocumentRegistrationOptions() - { - DocumentSelector = LspUtils.PowerShellDocumentSelector - }; _logger.LogInformation("highlight handler loaded"); } - public TextDocumentRegistrationOptions GetRegistrationOptions() + public DocumentHighlightRegistrationOptions GetRegistrationOptions() { - return _registrationOptions; + return new DocumentHighlightRegistrationOptions + { + DocumentSelector = LspUtils.PowerShellDocumentSelector + }; } public Task Handle( diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentSymbolHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentSymbolHandler.cs index f702c629b..22c1a99d6 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentSymbolHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentSymbolHandler.cs @@ -33,7 +33,7 @@ internal class DocumentSymbolHandler : IDocumentSymbolHandler public DocumentSymbolHandler(ILoggerFactory factory, ConfigurationService configurationService, WorkspaceService workspaceService) { - _logger = factory.CreateLogger(); + _logger = factory.CreateLogger(); _workspaceService = workspaceService; _providers = new IDocumentSymbolProvider[] { @@ -43,11 +43,11 @@ public DocumentSymbolHandler(ILoggerFactory factory, ConfigurationService config }; } - public TextDocumentRegistrationOptions GetRegistrationOptions() + public DocumentSymbolRegistrationOptions GetRegistrationOptions() { - return new TextDocumentRegistrationOptions + return new DocumentSymbolRegistrationOptions { - DocumentSelector = LspUtils.PowerShellDocumentSelector, + DocumentSelector = LspUtils.PowerShellDocumentSelector }; } diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/FoldingRangeHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/FoldingRangeHandler.cs index fd9769e15..657694f97 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/FoldingRangeHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/FoldingRangeHandler.cs @@ -30,16 +30,22 @@ public FoldingRangeHandler(ILoggerFactory factory, ConfigurationService configur _configurationService = configurationService; _workspaceService = workspaceService; } - public TextDocumentRegistrationOptions GetRegistrationOptions() + + public FoldingRangeRegistrationOptions GetRegistrationOptions() { - return new TextDocumentRegistrationOptions() + return new FoldingRangeRegistrationOptions { - DocumentSelector = LspUtils.PowerShellDocumentSelector, + DocumentSelector = LspUtils.PowerShellDocumentSelector }; } public Task> Handle(FoldingRangeRequestParam request, CancellationToken cancellationToken) { + if (cancellationToken.IsCancellationRequested) + { + return Task.FromResult(new Container()); + } + // TODO Should be using dynamic registrations if (!_configurationService.CurrentSettings.CodeFolding.Enable) { return null; } diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/FormattingHandlers.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/FormattingHandlers.cs index 619a24187..e26bf4f17 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/FormattingHandlers.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/FormattingHandlers.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging; using Microsoft.PowerShell.EditorServices.Services; using Microsoft.PowerShell.EditorServices.Utility; +using OmniSharp.Extensions.LanguageServer.Protocol; using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; using OmniSharp.Extensions.LanguageServer.Protocol.Models; using OmniSharp.Extensions.LanguageServer.Protocol.Server; @@ -37,9 +38,17 @@ public DocumentFormattingHandlers( _workspaceService = workspaceService; } - public TextDocumentRegistrationOptions GetRegistrationOptions() + public DocumentFormattingRegistrationOptions GetRegistrationOptions() { - return new TextDocumentRegistrationOptions + return new DocumentFormattingRegistrationOptions + { + DocumentSelector = LspUtils.PowerShellDocumentSelector + }; + } + + DocumentRangeFormattingRegistrationOptions IRegistration.GetRegistrationOptions() + { + return new DocumentRangeFormattingRegistrationOptions { DocumentSelector = LspUtils.PowerShellDocumentSelector }; diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/HoverHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/HoverHandler.cs index 8ab57413a..307aa7b46 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/HoverHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/HoverHandler.cs @@ -38,11 +38,11 @@ public HoverHandler( _powerShellContextService = powerShellContextService; } - public TextDocumentRegistrationOptions GetRegistrationOptions() + public HoverRegistrationOptions GetRegistrationOptions() { - return new TextDocumentRegistrationOptions + return new HoverRegistrationOptions { - DocumentSelector = LspUtils.PowerShellDocumentSelector, + DocumentSelector = LspUtils.PowerShellDocumentSelector }; } diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/ReferencesHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/ReferencesHandler.cs index 9917c557f..1880dd023 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/ReferencesHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/ReferencesHandler.cs @@ -22,7 +22,7 @@ class ReferencesHandler : IReferencesHandler private readonly ILogger _logger; private readonly SymbolsService _symbolsService; private readonly WorkspaceService _workspaceService; - private ReferencesCapability _capability; + private ReferenceCapability _capability; public ReferencesHandler(ILoggerFactory factory, SymbolsService symbolsService, WorkspaceService workspaceService) { @@ -31,9 +31,9 @@ public ReferencesHandler(ILoggerFactory factory, SymbolsService symbolsService, _workspaceService = workspaceService; } - public TextDocumentRegistrationOptions GetRegistrationOptions() + public ReferenceRegistrationOptions GetRegistrationOptions() { - return new TextDocumentRegistrationOptions + return new ReferenceRegistrationOptions { DocumentSelector = LspUtils.PowerShellDocumentSelector }; @@ -72,7 +72,7 @@ public async Task Handle(ReferenceParams request, Cancellatio return new LocationContainer(locations); } - public void SetCapability(ReferencesCapability capability) + public void SetCapability(ReferenceCapability capability) { _capability = capability; } diff --git a/src/PowerShellEditorServices/Services/Workspace/Handlers/WorkspaceSymbolsHandler.cs b/src/PowerShellEditorServices/Services/Workspace/Handlers/WorkspaceSymbolsHandler.cs index fdb026556..6bda1ed6e 100644 --- a/src/PowerShellEditorServices/Services/Workspace/Handlers/WorkspaceSymbolsHandler.cs +++ b/src/PowerShellEditorServices/Services/Workspace/Handlers/WorkspaceSymbolsHandler.cs @@ -32,13 +32,12 @@ public WorkspaceSymbolsHandler(ILoggerFactory loggerFactory, SymbolsService symb _workspaceService = workspace; } - public object GetRegistrationOptions() + public WorkspaceSymbolRegistrationOptions GetRegistrationOptions() { - return null; - // throw new NotImplementedException(); + return new WorkspaceSymbolRegistrationOptions(); } - public Task Handle(WorkspaceSymbolParams request, CancellationToken cancellationToken) + public Task> Handle(WorkspaceSymbolParams request, CancellationToken cancellationToken) { var symbols = new List(); @@ -75,7 +74,7 @@ public Task Handle(WorkspaceSymbolParams request, Ca } _logger.LogWarning("Logging in a handler works now."); - return Task.FromResult(new SymbolInformationContainer(symbols)); + return Task.FromResult(new Container(symbols)); } public void SetCapability(WorkspaceSymbolCapability capability) diff --git a/test/PowerShellEditorServices.Test.E2E/LanguageServerProtocolMessageTests.cs b/test/PowerShellEditorServices.Test.E2E/LanguageServerProtocolMessageTests.cs index 8e1501814..b18c48339 100644 --- a/test/PowerShellEditorServices.Test.E2E/LanguageServerProtocolMessageTests.cs +++ b/test/PowerShellEditorServices.Test.E2E/LanguageServerProtocolMessageTests.cs @@ -124,7 +124,7 @@ function CanSendWorkspaceSymbolRequest { } "); - SymbolInformationContainer symbols = await LanguageClient.SendRequest( + Container symbols = await LanguageClient.SendRequest>( "workspace/symbol", new WorkspaceSymbolParams { diff --git a/test/PowerShellEditorServices.Test.E2E/PowerShellEditorServices.Test.E2E.csproj b/test/PowerShellEditorServices.Test.E2E/PowerShellEditorServices.Test.E2E.csproj index 9688c0a06..b3225e1b5 100644 --- a/test/PowerShellEditorServices.Test.E2E/PowerShellEditorServices.Test.E2E.csproj +++ b/test/PowerShellEditorServices.Test.E2E/PowerShellEditorServices.Test.E2E.csproj @@ -10,7 +10,7 @@ - +