Skip to content
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

Add InlayHint implementation to OmniSharp.LSP #2566

Merged
merged 9 commits into from
Sep 22, 2023
10 changes: 5 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<MicrosoftTestPackageVersion>17.6.0</MicrosoftTestPackageVersion>
<MSBuildPackageVersion>17.3.2</MSBuildPackageVersion>
<NuGetPackageVersion>6.8.0-preview.1.41</NuGetPackageVersion>
<RoslynPackageVersion>4.8.0-1.23374.10</RoslynPackageVersion>
<RoslynPackageVersion>4.8.0-1.23419.1</RoslynPackageVersion>
<XunitPackageVersion>2.4.1</XunitPackageVersion>
</PropertyGroup>

Expand Down Expand Up @@ -84,9 +84,9 @@
<PackageVersion Include="NuGet.Protocol" Version="$(NuGetPackageVersion)" />
<PackageVersion Include="NuGet.Versioning" Version="$(NuGetPackageVersion)" />

<PackageVersion Include="OmniSharp.Extensions.LanguageServer" Version="0.19.7" />
<PackageVersion Include="OmniSharp.Extensions.LanguageProtocol.Testing" Version="0.19.7" />
<PackageVersion Include="OmniSharp.Extensions.JsonRpc" Version="0.19.7" />
<PackageVersion Include="OmniSharp.Extensions.LanguageServer" Version="0.19.8" />
<PackageVersion Include="OmniSharp.Extensions.LanguageProtocol.Testing" Version="0.19.8" />
<PackageVersion Include="OmniSharp.Extensions.JsonRpc" Version="0.19.8" />

<PackageVersion Include="SQLitePCLRaw.bundle_green" Version="2.1.0" />
<PackageVersion Include="System.Collections.Immutable" Version="7.0.0" />
Expand All @@ -98,7 +98,7 @@
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="7.0.0" />
<PackageVersion Include="System.ValueTuple" Version="4.5.0" />

<PackageVersion Include="System.Reactive" Version="5.0.0" />
<PackageVersion Include="System.Reactive" Version="6.0.0" />

<PackageVersion Include="System.Reflection.DispatchProxy" Version="4.5.1" />
<PackageVersion Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.100-preview.4.23260.5",
"rollForward": "patch"
"rollForward": "latestMinor"
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
using System.Linq;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using Microsoft.CodeAnalysis;
using NuGet.Protocol;
using OmniSharp.Extensions.JsonRpc;
using OmniSharp.Extensions.LanguageServer.Protocol;
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
using OmniSharp.Models.V2.CodeActions;
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
using OmniSharp.Extensions.LanguageServer.Protocol.Workspace;
using Diagnostic = OmniSharp.Extensions.LanguageServer.Protocol.Models.Diagnostic;
using OmniSharp.Models.V2.CodeActions;
using CodeActionKind = OmniSharp.Extensions.LanguageServer.Protocol.Models.CodeActionKind;
using Diagnostic = OmniSharp.Extensions.LanguageServer.Protocol.Models.Diagnostic;
using OmniSharpCodeActionKind = OmniSharp.Models.V2.CodeActions.CodeActionKind;
using System;
using Range = OmniSharp.Extensions.LanguageServer.Protocol.Models.Range;
using NuGet.Protocol;

namespace OmniSharp.LanguageServerProtocol.Handlers
{
Expand All @@ -39,14 +39,14 @@ public static IEnumerable<IJsonRpcHandler> Enumerate(

private readonly Mef.IRequestHandler<GetCodeActionsRequest, GetCodeActionsResponse> _getActionsHandler;
private readonly Mef.IRequestHandler<RunCodeActionRequest, RunCodeActionResponse> _runActionHandler;
private readonly DocumentSelector _documentSelector;
private readonly TextDocumentSelector _documentSelector;
private readonly ILanguageServer _server;
private readonly DocumentVersions _documentVersions;

public OmniSharpCodeActionHandler(
Mef.IRequestHandler<GetCodeActionsRequest, GetCodeActionsResponse> getActionsHandler,
Mef.IRequestHandler<RunCodeActionRequest, RunCodeActionResponse> runActionHandler,
DocumentSelector documentSelector,
TextDocumentSelector documentSelector,
ILanguageServer server,
DocumentVersions documentVersions)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)

private readonly Mef.IRequestHandler<MembersTreeRequest, FileMemberTree> _membersAsTreeHandler;
private readonly Mef.IRequestHandler<FindUsagesRequest, QuickFixResponse> _findUsagesHandler;
private readonly DocumentSelector _documentSelector;
private readonly TextDocumentSelector _documentSelector;

public OmniSharpCodeLensHandler(
Mef.IRequestHandler<MembersTreeRequest, FileMemberTree> membersAsTreeHandler,
Mef.IRequestHandler<FindUsagesRequest, QuickFixResponse> findUsagesHandler,
DocumentSelector documentSelector)
TextDocumentSelector documentSelector)
{
_membersAsTreeHandler = membersAsTreeHandler;
_findUsagesHandler = findUsagesHandler;
Expand Down Expand Up @@ -68,8 +68,8 @@ public override async Task<CodeLens> Handle(CodeLens request, CancellationToken
var omnisharpRequest = new FindUsagesRequest
{
FileName = Helpers.FromUri(request.Data.ToObject<Uri>()),
Column = (int) request.Range.Start.Character,
Line = (int) request.Range.Start.Line,
Column = (int)request.Range.Start.Character,
Line = (int)request.Range.Start.Line,
OnlyThisFile = false,
ExcludeDefinition = true
};
Expand All @@ -83,11 +83,13 @@ public override async Task<CodeLens> Handle(CodeLens request, CancellationToken
ContractResolver = new CamelCasePropertyNamesContractResolver()
};

request = request with { Command = new Command
request = request with
{
Title = length == 1 ? "1 reference" : $"{length} references",
Name = "omnisharp/client/findReferences",
Arguments = new JArray(
Command = new Command
{
Title = length == 1 ? "1 reference" : $"{length} references",
Name = "omnisharp/client/findReferences",
Arguments = new JArray(
new[]
{
JObject.FromObject(
Expand All @@ -98,7 +100,8 @@ public override async Task<CodeLens> Handle(CodeLens request, CancellationToken
},
jsonCamelCaseContract)
}),
} };
}
};

return request;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Models.v1.Completion;

using CompletionTriggerKind = OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionTriggerKind;
using OmnisharpCompletionTriggerKind = OmniSharp.Models.v1.Completion.CompletionTriggerKind;
using CompletionItemKind = OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionItemKind;
using OmnisharpCompletionItemKind = OmniSharp.Models.v1.Completion.CompletionItemKind;
using static OmniSharp.LanguageServerProtocol.Helpers;
using CompletionItem = OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionItem;
using OmnisharpCompletionItem = OmniSharp.Models.v1.Completion.CompletionItem;
using CompletionItemKind = OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionItemKind;
using CompletionItemTag = OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionItemTag;
using OmnisharpCompletionItemTag = OmniSharp.Models.v1.Completion.CompletionItemTag;
using CompletionTriggerKind = OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionTriggerKind;
using InsertTextFormat = OmniSharp.Extensions.LanguageServer.Protocol.Models.InsertTextFormat;
using OmnisharpCompletionItem = OmniSharp.Models.v1.Completion.CompletionItem;
using OmnisharpCompletionItemKind = OmniSharp.Models.v1.Completion.CompletionItemKind;
using OmnisharpCompletionItemTag = OmniSharp.Models.v1.Completion.CompletionItemTag;
using OmnisharpCompletionTriggerKind = OmniSharp.Models.v1.Completion.CompletionTriggerKind;
using OmnisharpInsertTextFormat = OmniSharp.Models.v1.Completion.InsertTextFormat;

#nullable enable
Expand All @@ -43,12 +43,12 @@ public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)

private readonly Mef.IRequestHandler<CompletionRequest, CompletionResponse> _completionHandler;
private readonly Mef.IRequestHandler<CompletionResolveRequest, CompletionResolveResponse> _completionResolveHandler;
private readonly DocumentSelector _documentSelector;
private readonly TextDocumentSelector _documentSelector;

public OmniSharpCompletionHandler(
Mef.IRequestHandler<CompletionRequest, CompletionResponse> completionHandler,
Mef.IRequestHandler<CompletionResolveRequest, CompletionResolveResponse> completionResolveHandler,
DocumentSelector documentSelector)
TextDocumentSelector documentSelector)
{
_completionHandler = completionHandler;
_completionResolveHandler = completionResolveHandler;
Expand All @@ -62,7 +62,7 @@ public override async Task<CompletionList> Handle(CompletionParams request, Canc
FileName = Helpers.FromUri(request.TextDocument.Uri),
Column = Convert.ToInt32(request.Position.Character),
Line = Convert.ToInt32(request.Position.Line),
CompletionTrigger = ConvertEnum<CompletionTriggerKind, OmnisharpCompletionTriggerKind>(request.Context?.TriggerKind ?? CompletionTriggerKind.Invoked),
CompletionTrigger = Helpers.ConvertEnum<CompletionTriggerKind, OmnisharpCompletionTriggerKind>(request.Context?.TriggerKind ?? CompletionTriggerKind.Invoked),
TriggerCharacter = request.Context?.TriggerCharacter is { Length: > 0 } str ? str[0] : null
};

Expand Down Expand Up @@ -94,40 +94,6 @@ protected override CompletionRegistrationOptions CreateRegistrationOptions(Compl
};
}

private static T2 ConvertEnum<T1, T2>(T1 t1)
where T1 : struct, Enum
where T2 : struct, Enum
{
VerifyEnumsInSync(typeof(T1), typeof(T2));
// The JIT will optimize this box away
return (T2)(object)t1;
}

[Conditional("DEBUG")]
private static void VerifyEnumsInSync(Type enum1, Type enum2)
{
Debug.Assert(enum1.IsEnum);
Debug.Assert(enum2.IsEnum);

var lspValues = Enum.GetValues(enum1);
var modelValues = Enum.GetValues(enum2);
Debug.Assert(lspValues.Length == modelValues.Length);
for (int i = 0; i < lspValues.Length; i++)
{
var lspValue = lspValues.GetValue(i);
var modelValue = modelValues.GetValue(i);

if (lspValue is null || modelValue is null)
{
Debug.Assert(lspValue is null && modelValue is null);
}
else
{
Debug.Assert((int)lspValue == (int)modelValue);
}
}
}

private CompletionItem ToLSPCompletionItem(OmnisharpCompletionItem omnisharpCompletionItem)
=> new CompletionItem
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
}

private readonly Mef.IRequestHandler<GotoDefinitionRequest, GotoDefinitionResponse> _definitionHandler;
private readonly DocumentSelector _documentSelector;
private readonly TextDocumentSelector _documentSelector;

public OmniSharpDefinitionHandler(Mef.IRequestHandler<GotoDefinitionRequest, GotoDefinitionResponse> definitionHandler, DocumentSelector documentSelector)
public OmniSharpDefinitionHandler(Mef.IRequestHandler<GotoDefinitionRequest, GotoDefinitionResponse> definitionHandler, TextDocumentSelector documentSelector)
{
_definitionHandler = definitionHandler;
_documentSelector = documentSelector;
Expand Down Expand Up @@ -57,7 +57,7 @@ protected override DefinitionRegistrationOptions CreateRegistrationOptions(Defin
{
return new DefinitionRegistrationOptions()
{
DocumentSelector = _documentSelector
DocumentSelector = _documentSelector,
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
}

private readonly Mef.IRequestHandler<FormatRangeRequest, FormatRangeResponse> _formatRangeHandler;
private readonly DocumentSelector _documentSelector;
private readonly TextDocumentSelector _documentSelector;

public OmniSharpDocumentFormatRangeHandler(Mef.IRequestHandler<FormatRangeRequest, FormatRangeResponse> formatRangeHandler, DocumentSelector documentSelector)
public OmniSharpDocumentFormatRangeHandler(Mef.IRequestHandler<FormatRangeRequest, FormatRangeResponse> formatRangeHandler, TextDocumentSelector documentSelector)
{
_formatRangeHandler = formatRangeHandler;
_documentSelector = documentSelector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
}

private readonly Mef.IRequestHandler<CodeFormatRequest, CodeFormatResponse> _codeFormatHandler;
private readonly DocumentSelector _documentSelector;
private readonly TextDocumentSelector _documentSelector;

public OmniSharpDocumentFormattingHandler(Mef.IRequestHandler<CodeFormatRequest, CodeFormatResponse> codeFormatHandler, DocumentSelector documentSelector)
public OmniSharpDocumentFormattingHandler(Mef.IRequestHandler<CodeFormatRequest, CodeFormatResponse> codeFormatHandler, TextDocumentSelector documentSelector)
{
_codeFormatHandler = codeFormatHandler;
_documentSelector = documentSelector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
}

private readonly Mef.IRequestHandler<FindUsagesRequest, QuickFixResponse> _findUsagesHandler;
private readonly DocumentSelector _documentSelector;
private readonly TextDocumentSelector _documentSelector;

public OmniSharpDocumentHighlightHandler(Mef.IRequestHandler<FindUsagesRequest, QuickFixResponse> findUsagesHandler, DocumentSelector documentSelector)
public OmniSharpDocumentHighlightHandler(Mef.IRequestHandler<FindUsagesRequest, QuickFixResponse> findUsagesHandler, TextDocumentSelector documentSelector)
{
_findUsagesHandler = findUsagesHandler;
_documentSelector = documentSelector;
Expand Down Expand Up @@ -62,7 +62,7 @@ protected override DocumentHighlightRegistrationOptions CreateRegistrationOption
{
return new DocumentHighlightRegistrationOptions()
{
DocumentSelector = _documentSelector
DocumentSelector = _documentSelector,
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
}

private readonly Mef.IRequestHandler<FormatAfterKeystrokeRequest, FormatRangeResponse> _formatAfterKeystrokeHandler;
private readonly DocumentSelector _documentSelector;
private readonly TextDocumentSelector _documentSelector;

public OmniSharpDocumentOnTypeFormattingHandler(Mef.IRequestHandler<FormatAfterKeystrokeRequest, FormatRangeResponse> formatAfterKeystrokeHandler, DocumentSelector documentSelector)
public OmniSharpDocumentOnTypeFormattingHandler(Mef.IRequestHandler<FormatAfterKeystrokeRequest, FormatRangeResponse> formatAfterKeystrokeHandler, TextDocumentSelector documentSelector)
{
_formatAfterKeystrokeHandler = formatAfterKeystrokeHandler;
_documentSelector = documentSelector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
}

private readonly Mef.IRequestHandler<CodeStructureRequest, CodeStructureResponse> _codeStructureHandler;
private readonly DocumentSelector _documentSelector;
private readonly TextDocumentSelector _documentSelector;

public OmniSharpDocumentSymbolHandler(Mef.IRequestHandler<CodeStructureRequest, CodeStructureResponse> codeStructureHandler, DocumentSelector documentSelector)
public OmniSharpDocumentSymbolHandler(Mef.IRequestHandler<CodeStructureRequest, CodeStructureResponse> codeStructureHandler, TextDocumentSelector documentSelector)
{
_codeStructureHandler = codeStructureHandler;
_documentSelector = documentSelector;
Expand Down Expand Up @@ -66,7 +66,7 @@ protected override DocumentSymbolRegistrationOptions CreateRegistrationOptions(D
{
return new DocumentSymbolRegistrationOptions()
{
DocumentSelector = _documentSelector
DocumentSelector = _documentSelector,
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
}

private readonly Mef.IRequestHandler<BlockStructureRequest, BlockStructureResponse> _definitionHandler;
private readonly DocumentSelector _documentSelector;
private readonly TextDocumentSelector _documentSelector;

public OmniSharpFoldingRangenHandler(Mef.IRequestHandler<BlockStructureRequest, BlockStructureResponse> definitionHandler, DocumentSelector documentSelector)
public OmniSharpFoldingRangenHandler(Mef.IRequestHandler<BlockStructureRequest, BlockStructureResponse> definitionHandler, TextDocumentSelector documentSelector)
{
_definitionHandler = definitionHandler;
_documentSelector = documentSelector;
Expand Down Expand Up @@ -68,7 +68,7 @@ protected override FoldingRangeRegistrationOptions CreateRegistrationOptions(Fol
{
return new FoldingRangeRegistrationOptions()
{
DocumentSelector = _documentSelector
DocumentSelector = _documentSelector,
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public static IEnumerable<IJsonRpcHandler> Enumerate(RequestHandlers handlers)
}

private readonly Mef.IRequestHandler<QuickInfoRequest, QuickInfoResponse> _definitionHandler;
private readonly DocumentSelector _documentSelector;
private readonly TextDocumentSelector _documentSelector;

public OmniSharpHoverHandler(Mef.IRequestHandler<QuickInfoRequest, QuickInfoResponse> definitionHandler, DocumentSelector documentSelector)
public OmniSharpHoverHandler(Mef.IRequestHandler<QuickInfoRequest, QuickInfoResponse> definitionHandler, TextDocumentSelector documentSelector)
{
_definitionHandler = definitionHandler;
_documentSelector = documentSelector;
Expand Down Expand Up @@ -52,7 +52,7 @@ protected override HoverRegistrationOptions CreateRegistrationOptions(HoverCapab
{
return new HoverRegistrationOptions()
{
DocumentSelector = _documentSelector
DocumentSelector = _documentSelector,
};
}
}
Expand Down
Loading