Skip to content

Update OmniSharp #2079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/PowerShellEditorServices/PowerShellEditorServices.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
</When>
<Otherwise>
<ItemGroup>
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.19.7" />
<PackageReference Include="OmniSharp.Extensions.DebugAdapter.Server" Version="0.19.7" />
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.19.8" />
<PackageReference Include="OmniSharp.Extensions.DebugAdapter.Server" Version="0.19.8" />
</ItemGroup>
</Otherwise>
</Choose>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
// Licensed under the MIT License.

using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.PowerShell.EditorServices.Services;
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;
Expand Down Expand Up @@ -48,7 +46,6 @@ public override async Task<SymbolInformationOrDocumentSymbolContainer> 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<SymbolInformationOrDocumentSymbol> symbols = new();

foreach (SymbolReference r in ProvideDocumentSymbols(scriptFile))
Expand All @@ -70,27 +67,11 @@ public override async Task<SymbolInformationOrDocumentSymbolContainer> 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
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal class PsesSemanticTokensHandler : SemanticTokensHandlerBase
{
Delta = true
},
Range = true
Range = new SemanticTokensCapabilityRequestRange() { }
};

private readonly WorkspaceService _workspaceService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public override Task<Unit> 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Microsoft.PowerShell.EditorServices.Handlers
{
internal class PsesWorkspaceSymbolsHandler : WorkspaceSymbolsHandlerBase
{
private static readonly Container<SymbolInformation> s_emptySymbolInformationContainer = new();
private static readonly Container<WorkspaceSymbol> s_emptySymbolInformationContainer = new();
private readonly ILogger _logger;
private readonly SymbolsService _symbolsService;
private readonly WorkspaceService _workspaceService;
Expand All @@ -33,12 +33,12 @@ public PsesWorkspaceSymbolsHandler(ILoggerFactory loggerFactory, SymbolsService

protected override WorkspaceSymbolRegistrationOptions CreateRegistrationOptions(WorkspaceSymbolCapability capability, ClientCapabilities clientCapabilities) => new() { };

public override async Task<Container<SymbolInformation>> Handle(WorkspaceSymbolParams request, CancellationToken cancellationToken)
public override async Task<Container<WorkspaceSymbol>> Handle(WorkspaceSymbolParams request, CancellationToken cancellationToken)
{
_logger.LogDebug($"Handling workspace symbols request for query {request.Query}");

await _symbolsService.ScanWorkspacePSFiles(cancellationToken).ConfigureAwait(false);
List<SymbolInformation> symbols = new();
List<WorkspaceSymbol> symbols = new();

foreach (ScriptFile scriptFile in _workspaceService.GetOpenedFiles())
{
Expand Down Expand Up @@ -84,8 +84,7 @@ public override async Task<Container<SymbolInformation>> 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),
Expand Down
14 changes: 7 additions & 7 deletions src/PowerShellEditorServices/Utility/LspUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ function CanSendWorkspaceSymbolRequest {
}
");

Container<SymbolInformation> symbols = await PsesLanguageClient
Container<WorkspaceSymbol> symbols = await PsesLanguageClient
.SendRequest(
"workspace/symbol",
new WorkspaceSymbolParams
{
Query = "CanSendWorkspaceSymbolRequest"
})
.Returning<Container<SymbolInformation>>(CancellationToken.None).ConfigureAwait(true);
.Returning<Container<WorkspaceSymbol>>(CancellationToken.None).ConfigureAwait(true);

SymbolInformation symbol = Assert.Single(symbols);
WorkspaceSymbol symbol = Assert.Single(symbols);
Assert.Equal("function CanSendWorkspaceSymbolRequest ()", symbol.Name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
</When>
<Otherwise>
<ItemGroup>
<PackageReference Include="OmniSharp.Extensions.LanguageClient" Version="0.19.7" />
<PackageReference Include="OmniSharp.Extensions.DebugAdapter.Client" Version="0.19.7" />
<PackageReference Include="OmniSharp.Extensions.LanguageClient" Version="0.19.8" />
<PackageReference Include="OmniSharp.Extensions.DebugAdapter.Client" Version="0.19.8" />
</ItemGroup>
</Otherwise>
</Choose>
Expand Down