diff --git a/src/PowerShellEditorServices/PowerShellEditorServices.csproj b/src/PowerShellEditorServices/PowerShellEditorServices.csproj index 68111e381..32f43512c 100644 --- a/src/PowerShellEditorServices/PowerShellEditorServices.csproj +++ b/src/PowerShellEditorServices/PowerShellEditorServices.csproj @@ -54,8 +54,8 @@ - - + + diff --git a/src/PowerShellEditorServices/Services/TextDocument/FoldingReference.cs b/src/PowerShellEditorServices/Services/TextDocument/FoldingReference.cs index 909a1a2ba..cd45ec1e8 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/FoldingReference.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/FoldingReference.cs @@ -58,22 +58,18 @@ public int CompareTo(FoldingReference that) if (EndCharacter > that.EndCharacter) { return 1; } // They're the same range, but what about kind - if (Kind == null) + if (Kind == that.Kind) { - if (that.Kind == null) - { - return 0; - } - // that has a kind but this doesn't. - return 1; + return 0; } - if (that.Kind != null) + // That has a kind but this doesn't. + if (Kind is null && that.Kind is not null) { - return that.Kind.Value - Kind.Value; + return 1; } - // this has a kind but that doesn't. + // This has a kind but that doesn't. return -1; } diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentSymbolHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentSymbolHandler.cs index c6a24bc1b..310bd4a2c 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentSymbolHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentSymbolHandler.cs @@ -2,7 +2,6 @@ // Licensed under the MIT License. using System.Collections.Generic; -using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; @@ -10,7 +9,6 @@ using Microsoft.PowerShell.EditorServices.Services.Symbols; 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; @@ -48,7 +46,6 @@ public override async Task Handle(Do _logger.LogDebug($"Handling document symbols for {request.TextDocument.Uri}"); ScriptFile scriptFile = _workspaceService.GetFile(request.TextDocument.Uri); - string containerName = Path.GetFileNameWithoutExtension(scriptFile.FilePath); List symbols = new(); foreach (SymbolReference r in ProvideDocumentSymbols(scriptFile)) @@ -70,27 +67,11 @@ public override async Task Handle(Do continue; } - // TODO: This should be a DocumentSymbol now as SymbolInformation is deprecated. But - // this requires figuring out how to populate `children`. Once we do that, the range - // can be NameRegion. - // - // symbols.Add(new SymbolInformationOrDocumentSymbol(new DocumentSymbol - // { - // Name = SymbolTypeUtils.GetDecoratedSymbolName(r), - // Kind = SymbolTypeUtils.GetSymbolKind(r.SymbolType), - // Range = r.ScriptRegion.ToRange(), - // SelectionRange = r.NameRegion.ToRange() - // })); - symbols.Add(new SymbolInformationOrDocumentSymbol(new SymbolInformation + symbols.Add(new SymbolInformationOrDocumentSymbol(new DocumentSymbol { - ContainerName = containerName, Kind = SymbolTypeUtils.GetSymbolKind(r.Type), - Location = new Location - { - Uri = DocumentUri.From(r.FilePath), - // Jump to name start, but keep whole range to support symbol tree in outline - Range = new Range(r.NameRegion.ToRange().Start, r.ScriptRegion.ToRange().End) - }, + // Jump to name start, but keep whole range to support symbol tree in outline + Range = new Range(r.NameRegion.ToRange().Start, r.ScriptRegion.ToRange().End), Name = r.Name })); } diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/PsesSemanticTokensHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/PsesSemanticTokensHandler.cs index e5e69e60f..8fec81700 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/PsesSemanticTokensHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/PsesSemanticTokensHandler.cs @@ -25,7 +25,7 @@ internal class PsesSemanticTokensHandler : SemanticTokensHandlerBase { Delta = true }, - Range = true + Range = new SemanticTokensCapabilityRequestRange() { } }; private readonly WorkspaceService _workspaceService; diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/TextDocumentHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/TextDocumentHandler.cs index d9ece3db5..79af825ed 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/TextDocumentHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/TextDocumentHandler.cs @@ -61,7 +61,7 @@ public override Task Handle(DidChangeTextDocumentParams notification, Canc return Unit.Task; } - protected override TextDocumentSyncRegistrationOptions CreateRegistrationOptions(SynchronizationCapability capability, ClientCapabilities clientCapabilities) + protected override TextDocumentSyncRegistrationOptions CreateRegistrationOptions(TextSynchronizationCapability capability, ClientCapabilities clientCapabilities) { _isFileWatcherSupported = clientCapabilities.Workspace.DidChangeWatchedFiles.IsSupported; return new TextDocumentSyncRegistrationOptions() diff --git a/src/PowerShellEditorServices/Services/Workspace/Handlers/WorkspaceSymbolsHandler.cs b/src/PowerShellEditorServices/Services/Workspace/Handlers/WorkspaceSymbolsHandler.cs index fa7f1d49a..040a4fe67 100644 --- a/src/PowerShellEditorServices/Services/Workspace/Handlers/WorkspaceSymbolsHandler.cs +++ b/src/PowerShellEditorServices/Services/Workspace/Handlers/WorkspaceSymbolsHandler.cs @@ -19,7 +19,7 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { internal class PsesWorkspaceSymbolsHandler : WorkspaceSymbolsHandlerBase { - private static readonly Container s_emptySymbolInformationContainer = new(); + private static readonly Container s_emptySymbolInformationContainer = new(); private readonly ILogger _logger; private readonly SymbolsService _symbolsService; private readonly WorkspaceService _workspaceService; @@ -33,12 +33,12 @@ public PsesWorkspaceSymbolsHandler(ILoggerFactory loggerFactory, SymbolsService protected override WorkspaceSymbolRegistrationOptions CreateRegistrationOptions(WorkspaceSymbolCapability capability, ClientCapabilities clientCapabilities) => new() { }; - public override async Task> Handle(WorkspaceSymbolParams request, CancellationToken cancellationToken) + public override async Task> Handle(WorkspaceSymbolParams request, CancellationToken cancellationToken) { _logger.LogDebug($"Handling workspace symbols request for query {request.Query}"); await _symbolsService.ScanWorkspacePSFiles(cancellationToken).ConfigureAwait(false); - List symbols = new(); + List symbols = new(); foreach (ScriptFile scriptFile in _workspaceService.GetOpenedFiles()) { @@ -84,8 +84,7 @@ public override async Task> Handle(WorkspaceSymbolP Range = symbol.NameRegion.ToRange() }; - // TODO: This should be a WorkplaceSymbol now as SymbolInformation is deprecated. - symbols.Add(new SymbolInformation + symbols.Add(new WorkspaceSymbol { ContainerName = containerName, Kind = SymbolTypeUtils.GetSymbolKind(symbol.Type), diff --git a/src/PowerShellEditorServices/Utility/LspUtils.cs b/src/PowerShellEditorServices/Utility/LspUtils.cs index 68c5ffb0b..d47f2b6c4 100644 --- a/src/PowerShellEditorServices/Utility/LspUtils.cs +++ b/src/PowerShellEditorServices/Utility/LspUtils.cs @@ -7,19 +7,19 @@ namespace Microsoft.PowerShell.EditorServices.Utility { internal static class LspUtils { - public static DocumentSelector PowerShellDocumentSelector => new( - DocumentFilter.ForLanguage("powershell"), - DocumentFilter.ForLanguage("pwsh"), + public static TextDocumentSelector PowerShellDocumentSelector => new( + TextDocumentFilter.ForLanguage("powershell"), + TextDocumentFilter.ForLanguage("pwsh"), // The vim extension sets all PowerShell files as language "ps1" so this // makes sure we track those. - DocumentFilter.ForLanguage("ps1"), - DocumentFilter.ForLanguage("psm1"), - DocumentFilter.ForLanguage("psd1"), + TextDocumentFilter.ForLanguage("ps1"), + TextDocumentFilter.ForLanguage("psm1"), + TextDocumentFilter.ForLanguage("psd1"), // Also specify the file extensions to be thorough // This won't handle untitled files which is why we have to do the ones above. - DocumentFilter.ForPattern("**/*.ps*1") + TextDocumentFilter.ForPattern("**/*.ps*1") ); } } diff --git a/test/PowerShellEditorServices.Test.E2E/LanguageServerProtocolMessageTests.cs b/test/PowerShellEditorServices.Test.E2E/LanguageServerProtocolMessageTests.cs index 1a227278d..dd628f600 100644 --- a/test/PowerShellEditorServices.Test.E2E/LanguageServerProtocolMessageTests.cs +++ b/test/PowerShellEditorServices.Test.E2E/LanguageServerProtocolMessageTests.cs @@ -122,16 +122,16 @@ function CanSendWorkspaceSymbolRequest { } "); - Container symbols = await PsesLanguageClient + Container symbols = await PsesLanguageClient .SendRequest( "workspace/symbol", new WorkspaceSymbolParams { Query = "CanSendWorkspaceSymbolRequest" }) - .Returning>(CancellationToken.None).ConfigureAwait(true); + .Returning>(CancellationToken.None).ConfigureAwait(true); - SymbolInformation symbol = Assert.Single(symbols); + WorkspaceSymbol symbol = Assert.Single(symbols); Assert.Equal("function CanSendWorkspaceSymbolRequest ()", symbol.Name); } diff --git a/test/PowerShellEditorServices.Test.E2E/PowerShellEditorServices.Test.E2E.csproj b/test/PowerShellEditorServices.Test.E2E/PowerShellEditorServices.Test.E2E.csproj index c2dcc7d69..fed8ef490 100644 --- a/test/PowerShellEditorServices.Test.E2E/PowerShellEditorServices.Test.E2E.csproj +++ b/test/PowerShellEditorServices.Test.E2E/PowerShellEditorServices.Test.E2E.csproj @@ -24,8 +24,8 @@ - - + +