From 9f364acbec874878586d2fc9c3b564e91821b327 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Thu, 14 Sep 2023 11:51:42 -0700 Subject: [PATCH 1/9] Move to renamed LSP types --- .../Handlers/OmniSharpCodeActionHandler.cs | 16 +++++++------- .../Handlers/OmniSharpCodeLensHandler.cs | 21 +++++++++++-------- .../Handlers/OmniSharpCompletionHandler.cs | 17 +++++++-------- .../Handlers/OmniSharpDefinitionHandler.cs | 6 +++--- .../OmniSharpDocumentFormatRangeHandler.cs | 4 ++-- .../OmniSharpDocumentFormattingHandler.cs | 4 ++-- .../OmniSharpDocumentHighlightHandler.cs | 6 +++--- ...mniSharpDocumentOnTypeFormattingHandler.cs | 4 ++-- .../OmniSharpDocumentSymbolHandler.cs | 6 +++--- .../Handlers/OmniSharpFoldingRangeHandler.cs | 6 +++--- .../Handlers/OmniSharpHoverHandler.cs | 6 +++--- .../OmniSharpImplementationHandler.cs | 6 +++--- .../Handlers/OmniSharpReferencesHandler.cs | 6 +++--- .../Handlers/OmniSharpRenameHandler.cs | 4 ++-- .../OmniSharpSemanticTokensHandler.cs | 4 ++-- .../Handlers/OmniSharpSignatureHelpHandler.cs | 4 ++-- .../OmniSharpTextDocumentSyncHandler.cs | 6 +++--- .../OmniSharpTypeDefinitionHandler.cs | 6 +++--- .../OmniSharpWorkspaceSymbolsHandler.cs | 4 ++-- .../LanguageServerHost.cs | 8 +++---- .../RequestHandlerCollection.cs | 4 ++-- .../RequestHandlers.cs | 12 +++++------ 22 files changed, 81 insertions(+), 79 deletions(-) diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCodeActionHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCodeActionHandler.cs index 181643965f..ee4faec871 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCodeActionHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCodeActionHandler.cs @@ -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 { @@ -39,14 +39,14 @@ public static IEnumerable Enumerate( private readonly Mef.IRequestHandler _getActionsHandler; private readonly Mef.IRequestHandler _runActionHandler; - private readonly DocumentSelector _documentSelector; + private readonly TextDocumentSelector _documentSelector; private readonly ILanguageServer _server; private readonly DocumentVersions _documentVersions; public OmniSharpCodeActionHandler( Mef.IRequestHandler getActionsHandler, Mef.IRequestHandler runActionHandler, - DocumentSelector documentSelector, + TextDocumentSelector documentSelector, ILanguageServer server, DocumentVersions documentVersions) { diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCodeLensHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCodeLensHandler.cs index 18469ba369..d79da224f0 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCodeLensHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCodeLensHandler.cs @@ -33,12 +33,12 @@ public static IEnumerable Enumerate(RequestHandlers handlers) private readonly Mef.IRequestHandler _membersAsTreeHandler; private readonly Mef.IRequestHandler _findUsagesHandler; - private readonly DocumentSelector _documentSelector; + private readonly TextDocumentSelector _documentSelector; public OmniSharpCodeLensHandler( Mef.IRequestHandler membersAsTreeHandler, Mef.IRequestHandler findUsagesHandler, - DocumentSelector documentSelector) + TextDocumentSelector documentSelector) { _membersAsTreeHandler = membersAsTreeHandler; _findUsagesHandler = findUsagesHandler; @@ -68,8 +68,8 @@ public override async Task Handle(CodeLens request, CancellationToken var omnisharpRequest = new FindUsagesRequest { FileName = Helpers.FromUri(request.Data.ToObject()), - 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 }; @@ -83,11 +83,13 @@ public override async Task 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( @@ -98,7 +100,8 @@ public override async Task Handle(CodeLens request, CancellationToken }, jsonCamelCaseContract) }), - } }; + } + }; return request; } diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCompletionHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCompletionHandler.cs index 72a912c085..e24d4bce2f 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCompletionHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCompletionHandler.cs @@ -10,16 +10,15 @@ 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 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 @@ -43,12 +42,12 @@ public static IEnumerable Enumerate(RequestHandlers handlers) private readonly Mef.IRequestHandler _completionHandler; private readonly Mef.IRequestHandler _completionResolveHandler; - private readonly DocumentSelector _documentSelector; + private readonly TextDocumentSelector _documentSelector; public OmniSharpCompletionHandler( Mef.IRequestHandler completionHandler, Mef.IRequestHandler completionResolveHandler, - DocumentSelector documentSelector) + TextDocumentSelector documentSelector) { _completionHandler = completionHandler; _completionResolveHandler = completionResolveHandler; diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDefinitionHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDefinitionHandler.cs index 5395567893..894cefb0df 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDefinitionHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDefinitionHandler.cs @@ -22,9 +22,9 @@ public static IEnumerable Enumerate(RequestHandlers handlers) } private readonly Mef.IRequestHandler _definitionHandler; - private readonly DocumentSelector _documentSelector; + private readonly TextDocumentSelector _documentSelector; - public OmniSharpDefinitionHandler(Mef.IRequestHandler definitionHandler, DocumentSelector documentSelector) + public OmniSharpDefinitionHandler(Mef.IRequestHandler definitionHandler, TextDocumentSelector documentSelector) { _definitionHandler = definitionHandler; _documentSelector = documentSelector; @@ -57,7 +57,7 @@ protected override DefinitionRegistrationOptions CreateRegistrationOptions(Defin { return new DefinitionRegistrationOptions() { - DocumentSelector = _documentSelector + DocumentSelector = _documentSelector, }; } } diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentFormatRangeHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentFormatRangeHandler.cs index df04c498b9..0b3fa731d5 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentFormatRangeHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentFormatRangeHandler.cs @@ -24,9 +24,9 @@ public static IEnumerable Enumerate(RequestHandlers handlers) } private readonly Mef.IRequestHandler _formatRangeHandler; - private readonly DocumentSelector _documentSelector; + private readonly TextDocumentSelector _documentSelector; - public OmniSharpDocumentFormatRangeHandler(Mef.IRequestHandler formatRangeHandler, DocumentSelector documentSelector) + public OmniSharpDocumentFormatRangeHandler(Mef.IRequestHandler formatRangeHandler, TextDocumentSelector documentSelector) { _formatRangeHandler = formatRangeHandler; _documentSelector = documentSelector; diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentFormattingHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentFormattingHandler.cs index 28c9d2bd0b..328d5c549a 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentFormattingHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentFormattingHandler.cs @@ -24,9 +24,9 @@ public static IEnumerable Enumerate(RequestHandlers handlers) } private readonly Mef.IRequestHandler _codeFormatHandler; - private readonly DocumentSelector _documentSelector; + private readonly TextDocumentSelector _documentSelector; - public OmniSharpDocumentFormattingHandler(Mef.IRequestHandler codeFormatHandler, DocumentSelector documentSelector) + public OmniSharpDocumentFormattingHandler(Mef.IRequestHandler codeFormatHandler, TextDocumentSelector documentSelector) { _codeFormatHandler = codeFormatHandler; _documentSelector = documentSelector; diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentHighlightHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentHighlightHandler.cs index 2a92e1d6cc..a52df92708 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentHighlightHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentHighlightHandler.cs @@ -23,9 +23,9 @@ public static IEnumerable Enumerate(RequestHandlers handlers) } private readonly Mef.IRequestHandler _findUsagesHandler; - private readonly DocumentSelector _documentSelector; + private readonly TextDocumentSelector _documentSelector; - public OmniSharpDocumentHighlightHandler(Mef.IRequestHandler findUsagesHandler, DocumentSelector documentSelector) + public OmniSharpDocumentHighlightHandler(Mef.IRequestHandler findUsagesHandler, TextDocumentSelector documentSelector) { _findUsagesHandler = findUsagesHandler; _documentSelector = documentSelector; @@ -62,7 +62,7 @@ protected override DocumentHighlightRegistrationOptions CreateRegistrationOption { return new DocumentHighlightRegistrationOptions() { - DocumentSelector = _documentSelector + DocumentSelector = _documentSelector, }; } } diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentOnTypeFormattingHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentOnTypeFormattingHandler.cs index 7da882467f..f7237c3e7f 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentOnTypeFormattingHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentOnTypeFormattingHandler.cs @@ -24,9 +24,9 @@ public static IEnumerable Enumerate(RequestHandlers handlers) } private readonly Mef.IRequestHandler _formatAfterKeystrokeHandler; - private readonly DocumentSelector _documentSelector; + private readonly TextDocumentSelector _documentSelector; - public OmniSharpDocumentOnTypeFormattingHandler(Mef.IRequestHandler formatAfterKeystrokeHandler, DocumentSelector documentSelector) + public OmniSharpDocumentOnTypeFormattingHandler(Mef.IRequestHandler formatAfterKeystrokeHandler, TextDocumentSelector documentSelector) { _formatAfterKeystrokeHandler = formatAfterKeystrokeHandler; _documentSelector = documentSelector; diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentSymbolHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentSymbolHandler.cs index dad7e913ea..c2b06fd337 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentSymbolHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpDocumentSymbolHandler.cs @@ -24,9 +24,9 @@ public static IEnumerable Enumerate(RequestHandlers handlers) } private readonly Mef.IRequestHandler _codeStructureHandler; - private readonly DocumentSelector _documentSelector; + private readonly TextDocumentSelector _documentSelector; - public OmniSharpDocumentSymbolHandler(Mef.IRequestHandler codeStructureHandler, DocumentSelector documentSelector) + public OmniSharpDocumentSymbolHandler(Mef.IRequestHandler codeStructureHandler, TextDocumentSelector documentSelector) { _codeStructureHandler = codeStructureHandler; _documentSelector = documentSelector; @@ -66,7 +66,7 @@ protected override DocumentSymbolRegistrationOptions CreateRegistrationOptions(D { return new DocumentSymbolRegistrationOptions() { - DocumentSelector = _documentSelector + DocumentSelector = _documentSelector, }; } } diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpFoldingRangeHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpFoldingRangeHandler.cs index c63353cad8..5f75f3f1a4 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpFoldingRangeHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpFoldingRangeHandler.cs @@ -21,9 +21,9 @@ public static IEnumerable Enumerate(RequestHandlers handlers) } private readonly Mef.IRequestHandler _definitionHandler; - private readonly DocumentSelector _documentSelector; + private readonly TextDocumentSelector _documentSelector; - public OmniSharpFoldingRangenHandler(Mef.IRequestHandler definitionHandler, DocumentSelector documentSelector) + public OmniSharpFoldingRangenHandler(Mef.IRequestHandler definitionHandler, TextDocumentSelector documentSelector) { _definitionHandler = definitionHandler; _documentSelector = documentSelector; @@ -68,7 +68,7 @@ protected override FoldingRangeRegistrationOptions CreateRegistrationOptions(Fol { return new FoldingRangeRegistrationOptions() { - DocumentSelector = _documentSelector + DocumentSelector = _documentSelector, }; } } diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpHoverHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpHoverHandler.cs index 1ad7968ee5..cf99f81790 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpHoverHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpHoverHandler.cs @@ -21,9 +21,9 @@ public static IEnumerable Enumerate(RequestHandlers handlers) } private readonly Mef.IRequestHandler _definitionHandler; - private readonly DocumentSelector _documentSelector; + private readonly TextDocumentSelector _documentSelector; - public OmniSharpHoverHandler(Mef.IRequestHandler definitionHandler, DocumentSelector documentSelector) + public OmniSharpHoverHandler(Mef.IRequestHandler definitionHandler, TextDocumentSelector documentSelector) { _definitionHandler = definitionHandler; _documentSelector = documentSelector; @@ -52,7 +52,7 @@ protected override HoverRegistrationOptions CreateRegistrationOptions(HoverCapab { return new HoverRegistrationOptions() { - DocumentSelector = _documentSelector + DocumentSelector = _documentSelector, }; } } diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpImplementationHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpImplementationHandler.cs index 3249dd96f9..13e159856d 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpImplementationHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpImplementationHandler.cs @@ -24,9 +24,9 @@ public static IEnumerable Enumerate(RequestHandlers handlers) } private readonly Mef.IRequestHandler _findImplementationsHandler; - private readonly DocumentSelector _documentSelector; + private readonly TextDocumentSelector _documentSelector; - public OmniSharpImplementationHandler(Mef.IRequestHandler findImplementationsHandler, DocumentSelector documentSelector) + public OmniSharpImplementationHandler(Mef.IRequestHandler findImplementationsHandler, TextDocumentSelector documentSelector) { _findImplementationsHandler = findImplementationsHandler; _documentSelector = documentSelector; @@ -54,7 +54,7 @@ protected override ImplementationRegistrationOptions CreateRegistrationOptions(I { return new ImplementationRegistrationOptions() { - DocumentSelector = _documentSelector + DocumentSelector = _documentSelector, }; } } diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpReferencesHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpReferencesHandler.cs index e72edb2fa8..59be63a8fd 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpReferencesHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpReferencesHandler.cs @@ -24,9 +24,9 @@ public static IEnumerable Enumerate(RequestHandlers handlers) } private readonly Mef.IRequestHandler _findUsagesHandler; - private readonly DocumentSelector _documentSelector; + private readonly TextDocumentSelector _documentSelector; - public OmniSharpReferencesHandler(Mef.IRequestHandler findUsagesHandler, DocumentSelector documentSelector) + public OmniSharpReferencesHandler(Mef.IRequestHandler findUsagesHandler, TextDocumentSelector documentSelector) { _findUsagesHandler = findUsagesHandler; _documentSelector = documentSelector; @@ -56,7 +56,7 @@ protected override ReferenceRegistrationOptions CreateRegistrationOptions(Refere { return new ReferenceRegistrationOptions() { - DocumentSelector = _documentSelector + DocumentSelector = _documentSelector, }; } } diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpRenameHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpRenameHandler.cs index 69e7bb5f32..d54d5217ad 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpRenameHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpRenameHandler.cs @@ -15,9 +15,9 @@ namespace OmniSharp.LanguageServerProtocol.Handlers internal class OmniSharpRenameHandler : RenameHandlerBase { private readonly Mef.IRequestHandler _renameHandler; - private readonly DocumentSelector _documentSelector; + private readonly TextDocumentSelector _documentSelector; - public OmniSharpRenameHandler(Mef.IRequestHandler renameHandler, DocumentSelector documentSelector) + public OmniSharpRenameHandler(Mef.IRequestHandler renameHandler, TextDocumentSelector documentSelector) { _renameHandler = renameHandler; _documentSelector = documentSelector; diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpSemanticTokensHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpSemanticTokensHandler.cs index 744cc937bf..67ccd03aea 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpSemanticTokensHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpSemanticTokensHandler.cs @@ -46,7 +46,7 @@ public static IEnumerable Enumerate(RequestHandlers handlers) }.ToImmutableDictionary(); private readonly Mef.IRequestHandler _definitionHandler; - private readonly DocumentSelector _documentSelector; + private readonly TextDocumentSelector _documentSelector; private static string MakeLSPCompatibleString(string str) => char.ToLower(str[0]) + str.Substring(1); @@ -71,7 +71,7 @@ private static readonly ImmutableDictionary(_tokenModifiers.Values), }; - public OmniSharpSemanticTokensHandler(Mef.IRequestHandler definitionHandler, DocumentSelector documentSelector) + public OmniSharpSemanticTokensHandler(Mef.IRequestHandler definitionHandler, TextDocumentSelector documentSelector) { _definitionHandler = definitionHandler; _documentSelector = documentSelector; diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpSignatureHelpHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpSignatureHelpHandler.cs index 890f68cd8a..f3bcab56cd 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpSignatureHelpHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpSignatureHelpHandler.cs @@ -15,9 +15,9 @@ namespace OmniSharp.LanguageServerProtocol.Handlers internal class OmniSharpSignatureHelpHandler : SignatureHelpHandlerBase { private readonly Mef.IRequestHandler _signatureHandler; - private readonly DocumentSelector _documentSelector; + private readonly TextDocumentSelector _documentSelector; - public OmniSharpSignatureHelpHandler(Mef.IRequestHandler signatureHandler, DocumentSelector documentSelector) + public OmniSharpSignatureHelpHandler(Mef.IRequestHandler signatureHandler, TextDocumentSelector documentSelector) { _signatureHandler = signatureHandler; _documentSelector = documentSelector; diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpTextDocumentSyncHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpTextDocumentSyncHandler.cs index 44fe6bfca0..3ede8f3d84 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpTextDocumentSyncHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpTextDocumentSyncHandler.cs @@ -44,7 +44,7 @@ public static IEnumerable Enumerate( private readonly Mef.IRequestHandler _openHandler; private readonly Mef.IRequestHandler _closeHandler; private readonly Mef.IRequestHandler _bufferHandler; - private readonly DocumentSelector _documentSelector; + private readonly TextDocumentSelector _documentSelector; private readonly TextDocumentSyncKind _documentSyncKind; private readonly OmniSharpWorkspace _workspace; private readonly DocumentVersions _documentVersions; @@ -53,7 +53,7 @@ public OmniSharpTextDocumentSyncHandler( Mef.IRequestHandler openHandler, Mef.IRequestHandler closeHandler, Mef.IRequestHandler bufferHandler, - DocumentSelector documentSelector, + TextDocumentSelector documentSelector, TextDocumentSyncKind documentSyncKind, OmniSharpWorkspace workspace, DocumentVersions documentVersions) @@ -160,7 +160,7 @@ await _bufferHandler.Handle(new UpdateBufferRequest() return Unit.Value; } - protected override TextDocumentSyncRegistrationOptions CreateRegistrationOptions(SynchronizationCapability capability, ClientCapabilities clientCapabilities) + protected override TextDocumentSyncRegistrationOptions CreateRegistrationOptions(TextSynchronizationCapability capability, ClientCapabilities clientCapabilities) { return new TextDocumentSyncRegistrationOptions() { diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpTypeDefinitionHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpTypeDefinitionHandler.cs index e250f7dc58..a7d349ecca 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpTypeDefinitionHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpTypeDefinitionHandler.cs @@ -22,9 +22,9 @@ public static IEnumerable Enumerate(RequestHandlers handlers) } private readonly Mef.IRequestHandler _definitionHandler; - private readonly DocumentSelector _documentSelector; + private readonly TextDocumentSelector _documentSelector; - public OmniSharpTypeDefinitionHandler(Mef.IRequestHandler definitionHandler, DocumentSelector documentSelector) + public OmniSharpTypeDefinitionHandler(Mef.IRequestHandler definitionHandler, TextDocumentSelector documentSelector) { _definitionHandler = definitionHandler; _documentSelector = documentSelector; @@ -57,7 +57,7 @@ protected override TypeDefinitionRegistrationOptions CreateRegistrationOptions(T { return new TypeDefinitionRegistrationOptions() { - DocumentSelector = _documentSelector + DocumentSelector = _documentSelector, }; } } diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpWorkspaceSymbolsHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpWorkspaceSymbolsHandler.cs index 4086fc68fe..e00cbb9e88 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpWorkspaceSymbolsHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpWorkspaceSymbolsHandler.cs @@ -39,7 +39,7 @@ public OmniSharpWorkspaceSymbolsHandler( _findSymbolsHandlers = findSymbolsHandlers.ToArray(); } - public override async Task> Handle( + public override async Task> Handle( WorkspaceSymbolParams request, CancellationToken cancellationToken) { @@ -56,7 +56,7 @@ public override async Task> Handle( return responses .SelectMany(z => z?.QuickFixes.OfType() ?? Enumerable.Empty()) .Select( - x => new SymbolInformation + x => new WorkspaceSymbol { Name = x.Text, Kind = Helpers.ToSymbolKind(x.Kind), diff --git a/src/OmniSharp.LanguageServerProtocol/LanguageServerHost.cs b/src/OmniSharp.LanguageServerProtocol/LanguageServerHost.cs index 20c7d61de5..d8102eb788 100644 --- a/src/OmniSharp.LanguageServerProtocol/LanguageServerHost.cs +++ b/src/OmniSharp.LanguageServerProtocol/LanguageServerHost.cs @@ -242,7 +242,7 @@ internal static RequestHandlers ConfigureCompositionHost(ILanguageServer server, .GroupBy(x => x.Language) .Select(x => ( language: x.Key, - selector: new DocumentSelector(x + selector: new TextDocumentSelector(x .SelectMany(z => z.Extensions) .Distinct() .SelectMany(z => @@ -251,14 +251,14 @@ internal static RequestHandlers ConfigureCompositionHost(ILanguageServer server, { return new[] { - new DocumentFilter() {Pattern = $"**/*{z}"}, - new DocumentFilter() {Scheme = "csharp"} + new TextDocumentFilter() {Pattern = $"**/*{z}"}, + new TextDocumentFilter() {Scheme = "csharp"} }; } return new[] { - new DocumentFilter() {Pattern = $"**/*{z}"}, + new TextDocumentFilter() {Pattern = $"**/*{z}"}, }; }) ) diff --git a/src/OmniSharp.LanguageServerProtocol/RequestHandlerCollection.cs b/src/OmniSharp.LanguageServerProtocol/RequestHandlerCollection.cs index 48e24ff35c..dd4ee9ba44 100644 --- a/src/OmniSharp.LanguageServerProtocol/RequestHandlerCollection.cs +++ b/src/OmniSharp.LanguageServerProtocol/RequestHandlerCollection.cs @@ -9,7 +9,7 @@ public class RequestHandlerCollection : IEnumerable { private readonly IEnumerable _handlers; - public RequestHandlerCollection(string language, IEnumerable handlers, DocumentSelector documentSelector) + public RequestHandlerCollection(string language, IEnumerable handlers, TextDocumentSelector documentSelector) { DocumentSelector = documentSelector; _handlers = handlers; @@ -17,7 +17,7 @@ public RequestHandlerCollection(string language, IEnumerable ha } public string Language { get; } - public DocumentSelector DocumentSelector { get; } + public TextDocumentSelector DocumentSelector { get; } public IEnumerator GetEnumerator() { diff --git a/src/OmniSharp.LanguageServerProtocol/RequestHandlers.cs b/src/OmniSharp.LanguageServerProtocol/RequestHandlers.cs index a6250683e4..646f9665ae 100644 --- a/src/OmniSharp.LanguageServerProtocol/RequestHandlers.cs +++ b/src/OmniSharp.LanguageServerProtocol/RequestHandlers.cs @@ -11,11 +11,11 @@ namespace OmniSharp.LanguageServerProtocol public class RequestHandlers : IEnumerable { private readonly IEnumerable> _requestHandlers; - private readonly IEnumerable<(string language, DocumentSelector selector)> _documentSelectors; + private readonly IEnumerable<(string language, TextDocumentSelector selector)> _documentSelectors; public RequestHandlers( IEnumerable> requestHandlers, - IEnumerable<(string language, DocumentSelector selector)> documentSelectors) + IEnumerable<(string language, TextDocumentSelector selector)> documentSelectors) { _requestHandlers = requestHandlers; _documentSelectors = documentSelectors; @@ -32,7 +32,7 @@ public IEnumerator GetEnumerator() .GetEnumerator(); } - public IEnumerable<(DocumentSelector selector, T handler)> OfType() + public IEnumerable<(TextDocumentSelector selector, T handler)> OfType() where T : IRequestHandler { foreach (var group in this) @@ -44,7 +44,7 @@ public IEnumerator GetEnumerator() } } - public IEnumerable<(DocumentSelector selector, T handler, T2 handler2)> OfType() + public IEnumerable<(TextDocumentSelector selector, T handler, T2 handler2)> OfType() where T : IRequestHandler where T2 : IRequestHandler { @@ -58,7 +58,7 @@ public IEnumerator GetEnumerator() } } - public IEnumerable<(DocumentSelector selector, T handler, T2 handler2, T3 handler3)> OfType() + public IEnumerable<(TextDocumentSelector selector, T handler, T2 handler2, T3 handler3)> OfType() where T : IRequestHandler where T2 : IRequestHandler where T3 : IRequestHandler @@ -74,7 +74,7 @@ public IEnumerator GetEnumerator() } } - public IEnumerable<(DocumentSelector selector, T handler, T2 handler2, T3 handler3, T4 handler4)> OfType() + public IEnumerable<(TextDocumentSelector selector, T handler, T2 handler2, T3 handler3, T4 handler4)> OfType() where T : IRequestHandler where T2 : IRequestHandler where T3 : IRequestHandler From 86cc1349c0f3a666e80e41cc972c770247a00a2c Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Fri, 15 Sep 2023 23:21:00 -0700 Subject: [PATCH 2/9] Add InlayHintHandler implementation to OmniSharp.LSP --- Directory.Packages.props | 10 +- global.json | 2 +- .../Handlers/OmniSharpCompletionHandler.cs | 37 +- .../Handlers/OmniSharpInlayHintHandler.cs | 110 ++++ .../Helpers.cs | 58 ++ .../LanguageServerHost.cs | 1 + .../OmniSharpInlayHintHandlerFacts.cs | 560 ++++++++++++++++++ 7 files changed, 737 insertions(+), 41 deletions(-) create mode 100644 src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpInlayHintHandler.cs create mode 100644 tests/OmniSharp.Lsp.Tests/OmniSharpInlayHintHandlerFacts.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index dff6f3cc82..62f5103457 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -8,7 +8,7 @@ 17.6.0 17.3.2 6.8.0-preview.1.41 - 4.8.0-1.23374.10 + 4.8.0-1.23419.1 2.4.1 @@ -84,9 +84,9 @@ - - - + + + @@ -98,7 +98,7 @@ - + diff --git a/global.json b/global.json index a0d64e6f31..0645b687ae 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { "version": "8.0.100-preview.4.23260.5", - "rollForward": "patch" + "rollForward": "latestMinor" } } diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCompletionHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCompletionHandler.cs index e24d4bce2f..4ed204d94e 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCompletionHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpCompletionHandler.cs @@ -10,6 +10,7 @@ using OmniSharp.Extensions.LanguageServer.Protocol.Document; using OmniSharp.Extensions.LanguageServer.Protocol.Models; using OmniSharp.Models.v1.Completion; +using static OmniSharp.LanguageServerProtocol.Helpers; using CompletionItem = OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionItem; using CompletionItemKind = OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionItemKind; using CompletionItemTag = OmniSharp.Extensions.LanguageServer.Protocol.Models.CompletionItemTag; @@ -61,7 +62,7 @@ public override async Task Handle(CompletionParams request, Canc FileName = Helpers.FromUri(request.TextDocument.Uri), Column = Convert.ToInt32(request.Position.Character), Line = Convert.ToInt32(request.Position.Line), - CompletionTrigger = ConvertEnum(request.Context?.TriggerKind ?? CompletionTriggerKind.Invoked), + CompletionTrigger = Helpers.ConvertEnum(request.Context?.TriggerKind ?? CompletionTriggerKind.Invoked), TriggerCharacter = request.Context?.TriggerCharacter is { Length: > 0 } str ? str[0] : null }; @@ -93,40 +94,6 @@ protected override CompletionRegistrationOptions CreateRegistrationOptions(Compl }; } - private static T2 ConvertEnum(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 { diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpInlayHintHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpInlayHintHandler.cs new file mode 100644 index 0000000000..c1d74ee570 --- /dev/null +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpInlayHintHandler.cs @@ -0,0 +1,110 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Newtonsoft.Json.Linq; +using OmniSharp.Extensions.JsonRpc; +using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities; +using OmniSharp.Extensions.LanguageServer.Protocol.Document; +using OmniSharp.Extensions.LanguageServer.Protocol.Models; +using OmniSharp.Models.v1.InlayHints; +using static OmniSharp.LanguageServerProtocol.Helpers; +using LSPInlayHint = OmniSharp.Extensions.LanguageServer.Protocol.Models.InlayHint; +using LSPInlayHintKind = OmniSharp.Extensions.LanguageServer.Protocol.Models.InlayHintKind; +using OmniSharpInlayHint = OmniSharp.Models.v1.InlayHints.InlayHint; +using OmniSharpInlayHintKind = OmniSharp.Models.v1.InlayHints.InlayHintKind; + +namespace OmniSharp.LanguageServerProtocol.Handlers +{ + class OmniSharpInlayHintHandler : InlayHintsHandlerBase + { + public static IEnumerable Enumerate(RequestHandlers handlers) + { + foreach (var (selector, handler, resolveHandler) in handlers + .OfType, Mef.IRequestHandler>()) + { + if (handler != null && resolveHandler != null) + yield return new OmniSharpInlayHintHandler(handler, resolveHandler, selector); + } + } + + private readonly Mef.IRequestHandler _inlayHintHandler; + private readonly Mef.IRequestHandler _inlayHintResolveHandler; + private readonly TextDocumentSelector _documentSelector; + + public OmniSharpInlayHintHandler( + Mef.IRequestHandler inlayHintHandler, + Mef.IRequestHandler inlayHintResolveHandler, + TextDocumentSelector documentSelector) + { + _inlayHintHandler = inlayHintHandler; + _inlayHintResolveHandler = inlayHintResolveHandler; + _documentSelector = documentSelector; + } + + public override async Task Handle(InlayHintParams request, CancellationToken cancellationToken) + { + var omnisharpRequest = new InlayHintRequest() + { + Location = new Models.V2.Location() + { + FileName = FromUri(request.TextDocument.Uri), + Range = FromRange(request.Range), + } + }; + + var omnisharpResponse = await _inlayHintHandler.Handle(omnisharpRequest); + + return new InlayHintContainer(omnisharpResponse.InlayHints.Select(ToLSPInlayHint)); + } + + public override async Task Handle(LSPInlayHint request, CancellationToken cancellationToken) + { + var omnisharpRequest = new InlayHintResolveRequest() + { + Hint = FromLSPInlayHint(request) + }; + + var omnisharpResponse = await _inlayHintResolveHandler.Handle(omnisharpRequest); + + return ToLSPInlayHint(omnisharpResponse); + } + + private static LSPInlayHint ToLSPInlayHint(OmniSharpInlayHint hint) + { + var trimmedStartLabel = hint.Label.TrimStart(); + var trimmedLabel = trimmedStartLabel.TrimEnd(); + return new LSPInlayHint() + { + Label = hint.Label, + Tooltip = hint.Tooltip, + Position = ToPosition(hint.Position), + TextEdits = new(ToTextEdits(hint.TextEdits)), + PaddingLeft = hint.Label.Length > trimmedStartLabel.Length, + PaddingRight = trimmedStartLabel.Length > trimmedLabel.Length, + Data = JToken.FromObject(hint.Data), + }; + } + + private static OmniSharpInlayHint FromLSPInlayHint(LSPInlayHint hint) + { + return new OmniSharpInlayHint() + { + Label = $"{(hint.PaddingLeft == true ? " " : "")}{hint.Label.String}{(hint.PaddingRight == true ? " " : "")}", + Tooltip = hint.Tooltip?.String, + Position = FromPosition(hint.Position), + TextEdits = hint.TextEdits is null ? null : FromTextEdits(hint.TextEdits), + Data = hint.Data.ToObject<(string SolutionVersion, int Position)>() + }; + } + + protected override InlayHintRegistrationOptions CreateRegistrationOptions(InlayHintWorkspaceClientCapabilities capability, ClientCapabilities clientCapabilities) + { + return new InlayHintRegistrationOptions() + { + DocumentSelector = _documentSelector, + ResolveProvider = true, + }; + } + } +} diff --git a/src/OmniSharp.LanguageServerProtocol/Helpers.cs b/src/OmniSharp.LanguageServerProtocol/Helpers.cs index e79653478f..95cec9e1fd 100644 --- a/src/OmniSharp.LanguageServerProtocol/Helpers.cs +++ b/src/OmniSharp.LanguageServerProtocol/Helpers.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using Newtonsoft.Json.Linq; @@ -116,6 +117,15 @@ public static Position ToPosition(OmniSharp.Models.V2.Point point) return new Position(point.Line, point.Column); } + public static OmniSharp.Models.V2.Point FromPosition(Position position) + { + return new Models.V2.Point() + { + Line = position.Line, + Column = position.Character, + }; + } + public static Range ToRange((int column, int line) start, (int column, int line) end) { return new Range() @@ -231,6 +241,14 @@ public static WorkspaceEditDocumentChange ToWorkspaceEditDocumentChange(FileOper return default; } + public static IEnumerable ToTextEdits(LinePositionSpanTextChange[] textChanges) + { + foreach (var change in textChanges) + { + yield return ToTextEdit(change); + } + } + public static IEnumerable ToTextEdits(FileOperationResponse response) { if (!(response is ModifiedFileResponse modified)) yield break; @@ -252,6 +270,11 @@ public static TextEdit ToTextEdit(LinePositionSpanTextChange textChange) }; } + public static LinePositionSpanTextChange[] FromTextEdits(IEnumerable textEdits) + { + return textEdits?.Select(FromTextEdit).ToArray() ?? Array.Empty(); + } + public static LinePositionSpanTextChange FromTextEdit(TextEdit textEdit) => new LinePositionSpanTextChange { @@ -261,6 +284,41 @@ public static LinePositionSpanTextChange FromTextEdit(TextEdit textEdit) StartColumn = textEdit.Range.Start.Character, EndColumn = textEdit.Range.End.Character }; + + + public static T2 ConvertEnum(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); + } + } + } } public static class CommandExtensions diff --git a/src/OmniSharp.LanguageServerProtocol/LanguageServerHost.cs b/src/OmniSharp.LanguageServerProtocol/LanguageServerHost.cs index d8102eb788..81dfbddf5d 100644 --- a/src/OmniSharp.LanguageServerProtocol/LanguageServerHost.cs +++ b/src/OmniSharp.LanguageServerProtocol/LanguageServerHost.cs @@ -383,6 +383,7 @@ internal static void RegisterHandlers(ILanguageServer server, CompositionHost co .Concat(OmniSharpFoldingRangenHandler.Enumerate(handlers)) .Concat(OmniSharpHoverHandler.Enumerate(handlers)) .Concat(OmniSharpImplementationHandler.Enumerate(handlers)) + .Concat(OmniSharpInlayHintHandler.Enumerate(handlers)) .Concat(OmniSharpReferencesHandler.Enumerate(handlers)) .Concat(OmniSharpRenameHandler.Enumerate(handlers)) .Concat(OmniSharpSemanticTokensHandler.Enumerate(handlers)) diff --git a/tests/OmniSharp.Lsp.Tests/OmniSharpInlayHintHandlerFacts.cs b/tests/OmniSharp.Lsp.Tests/OmniSharpInlayHintHandlerFacts.cs new file mode 100644 index 0000000000..511b7898c3 --- /dev/null +++ b/tests/OmniSharp.Lsp.Tests/OmniSharpInlayHintHandlerFacts.cs @@ -0,0 +1,560 @@ +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using OmniSharp.Extensions.LanguageServer.Protocol.Document; +using OmniSharp.Extensions.LanguageServer.Protocol.Models; +using OmniSharp.Options; +using Roslyn.Test.Utilities; +using TestUtility; +using Xunit; +using Xunit.Abstractions; + +namespace OmniSharp.Lsp.Tests; + +public class OmnisharpInlayHintHandlerFacts : AbstractLanguageServerTestBase +{ + private static readonly IgnoreDataComparer ignoreDataComparer = new IgnoreDataComparer(); + + public OmnisharpInlayHintHandlerFacts(ITestOutputHelper output) : base(output) + { + } + + [Theory] + [InlineData("dummy.cs")] + [InlineData("dummy.csx")] + public async Task InlayHintsRetrievedForTopLevelStatements(string fileName) + { + var code = @" +{|ihRegion:var testA = new C(); +var testB = new C(); +M(testA, testB)|}; + +void M(C param1, C paramB) { } + +class C { } +"; + + await SetInlayHintOptionsAsync(InlayHintsOptions.AllOn); + + var response = await GetInlayHints(fileName, code); + InlayHint[] inlayHints = response.ToArray(); + + AssertEx.Equal(new[] + { + new InlayHint { Position = new Position { Line = 3, Character = 2 }, Label = "param1:", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 3, Character = 2 }, End = new Position() { Line = 3, Character = 2 } }, NewText = "param1: " } }, PaddingLeft = false, PaddingRight = true }, + new InlayHint { Position = new Position { Line = 3, Character = 9 }, Label = "paramB:", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 3, Character = 9 }, End = new Position() { Line = 3, Character = 9 } }, NewText = "paramB: " } }, PaddingLeft = false, PaddingRight = true }, + new InlayHint { Position = new Position { Line = 1, Character = 4 }, Label = "C", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 1, Character = 0 }, End = new Position() { Line = 1, Character = 3 } }, NewText = "C" } }, PaddingLeft = false, PaddingRight = true }, + new InlayHint { Position = new Position { Line = 2, Character = 4 }, Label = "C", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 2, Character = 0 }, End = new Position() { Line = 2, Character = 3 } }, NewText = "C" } }, PaddingLeft = false, PaddingRight = true }, + }, + inlayHints, + ignoreDataComparer); + + var param1 = await ResolveInlayHint(inlayHints[0]); + AssertEx.AssertEqualToleratingWhitespaceDifferences(@" +```csharp +(parameter) C param1 +```", param1.Tooltip.String); + + var paramB = await ResolveInlayHint(inlayHints[1]); + AssertEx.AssertEqualToleratingWhitespaceDifferences(@" +```csharp +(parameter) C paramB +```", paramB.Tooltip.String); + + var c1 = await ResolveInlayHint(inlayHints[2]); + AssertEx.AssertEqualToleratingWhitespaceDifferences(@" +```csharp +class C +```", c1.Tooltip.String); + + var c2 = await ResolveInlayHint(inlayHints[3]); + AssertEx.AssertEqualToleratingWhitespaceDifferences(@" +```csharp +class C +```", c2.Tooltip.String); + } + + [Theory] + [InlineData("dummy.cs")] + [InlineData("dummy.csx")] + public async Task InlayHintsRetrievedForOnlyTypes(string fileName) + { + var code = @" +{|ihRegion:var testA = 1; +var testB = 2; +M(testA, testB)|}; + +void M(int param1, int paramB) { } +"; + + var options = InlayHintsOptions.AllOn with { EnableForParameters = false }; + await SetInlayHintOptionsAsync(options); + + var response = await GetInlayHints(fileName, code); + AssertEx.Equal(new[] + { + new InlayHint { Position = new Position { Line = 1, Character = 4 }, Label = "int", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 1, Character = 0 }, End = new Position() { Line = 1, Character = 3 } }, NewText = "int" } }, PaddingLeft = false, PaddingRight = true }, + new InlayHint { Position = new Position { Line = 2, Character = 4 }, Label = "int", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 2, Character = 0 }, End = new Position() { Line = 2, Character = 3 } }, NewText = "int" } }, PaddingLeft = false, PaddingRight = true }, + }, + response, + ignoreDataComparer); + } + + [Theory] + [InlineData("dummy.cs")] + [InlineData("dummy.csx")] + public async Task InlayHintsRetrievedForOnlyParameters(string fileName) + { + var code = @" +{|ihRegion:var testA = 1; +var testB = 2; +M(testA, testB)|}; + +void M(int param1, int paramB) { } +"; + + var options = InlayHintsOptions.AllOn with { EnableForTypes = false }; + await SetInlayHintOptionsAsync(options); + + var response = await GetInlayHints(fileName, code); + AssertEx.Equal(new[] + { + new InlayHint { Position = new Position { Line = 3, Character = 2 }, Label = "param1:", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 3, Character = 2 }, End = new Position() { Line = 3, Character = 2 } }, NewText = "param1: " } }, PaddingLeft = false, PaddingRight = true }, + new InlayHint { Position = new Position { Line = 3, Character = 9 }, Label = "paramB:", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 3, Character = 9 }, End = new Position() { Line = 3, Character = 9 } }, NewText = "paramB: " } }, PaddingLeft = false, PaddingRight = true }, + }, + response, + ignoreDataComparer); + } + + [Theory] + [InlineData("dummy.cs")] + [InlineData("dummy.csx")] + public async Task InlayHintsForVarTypes(string fileName) + { + var code = @" +{|ihRegion:var x = 1|}; +"; + + var options = InlayHintsOptions.AllOn with { ForImplicitVariableTypes = false }; + + { + await SetInlayHintOptionsAsync(options); + var response = await GetInlayHints(fileName, code); + Assert.Empty(response); + } + + { + await SetInlayHintOptionsAsync(options with { ForImplicitVariableTypes = true }); + var response = await GetInlayHints(fileName, code); + AssertEx.Equal(new[] + { + new InlayHint { Position = new Position { Line = 1, Character = 4 }, Label = "int", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 1, Character = 0 }, End = new Position() { Line = 1, Character = 3 } }, NewText = "int" } }, PaddingLeft = false, PaddingRight = true }, + }, + response, + ignoreDataComparer); + } + } + + [Theory] + [InlineData("dummy.cs")] + [InlineData("dummy.csx")] + public async Task InlayHintsForLambdaParameterTypes(string fileName) + { + var code = @" +using System; +{|ihRegion:Func lambda = (a, b) => true;|} +"; + + var options = InlayHintsOptions.AllOn with { ForLambdaParameterTypes = false }; + + { + await SetInlayHintOptionsAsync(options); + var response = await GetInlayHints(fileName, code); + Assert.Empty(response); + } + + { + await SetInlayHintOptionsAsync(options with { ForLambdaParameterTypes = true }); + var response = await GetInlayHints(fileName, code); + AssertEx.Equal(new[] + { + new InlayHint { Position = new Position { Line = 2, Character = 34 }, Label = "int", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 2, Character = 34 }, End = new Position() { Line = 2, Character = 34 } }, NewText = "int " } }, PaddingLeft = false, PaddingRight = true }, + new InlayHint { Position = new Position { Line = 2, Character = 37 }, Label = "string", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 2, Character = 37 }, End = new Position() { Line = 2, Character = 37 } }, NewText = "string " } }, PaddingLeft = false, PaddingRight = true } + }, + response, + ignoreDataComparer); + } + } + + [Theory] + [InlineData("dummy.cs")] + [InlineData("dummy.csx")] + public async Task InlayHintsForImplicitObjectCreation(string fileName) + { + var code = @" +{|ihRegion:string x = new()|}; +"; + + var options = InlayHintsOptions.AllOn with { ForImplicitObjectCreation = false }; + + { + await SetInlayHintOptionsAsync(options); + var response = await GetInlayHints(fileName, code); + Assert.Empty(response); + } + + { + await SetInlayHintOptionsAsync(options with { ForImplicitObjectCreation = true }); + var response = await GetInlayHints(fileName, code); + AssertEx.Equal(new[] + { + new InlayHint { Position = new Position { Line = 1, Character = 14 }, Label = "string", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 1, Character = 14 }, End = new Position() { Line = 1, Character = 14 } }, NewText = " string" } }, PaddingLeft = true, PaddingRight = false } + }, + response, + ignoreDataComparer); + } + } + + [Theory] + [InlineData("dummy.cs")] + [InlineData("dummy.csx")] + public async Task InlayHintsForLiteralParameters(string fileName) + { + var code = @" +{|ihRegion:M(1)|}; +void M(int i) {} +"; + + var options = InlayHintsOptions.AllOn with { ForLiteralParameters = false }; + + { + await SetInlayHintOptionsAsync(options); + var response = await GetInlayHints(fileName, code); + Assert.Empty(response); + } + + { + await SetInlayHintOptionsAsync(options with { ForLiteralParameters = true }); + var response = await GetInlayHints(fileName, code); + AssertEx.Equal(new[] + { + new InlayHint { Position = new Position { Line = 1, Character = 2 }, Label = "i:", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 1, Character = 2 }, End = new Position() { Line = 1, Character = 2 } }, NewText = "i: " } }, PaddingLeft = false, PaddingRight = true } + }, + response, + ignoreDataComparer); + } + } + + [Theory] + [InlineData("dummy.cs")] + [InlineData("dummy.csx")] + public async Task InlayHintsForIndexerParameters(string fileName) + { + var code = @" +var c = new C(); +int i = 1; +{|ihRegion:c[i] = c[i]|}; + +class C +{ + public int this[int test] { get => throw null; set => throw null; } +} +"; + + var options = InlayHintsOptions.AllOn with { ForIndexerParameters = false }; + + { + await SetInlayHintOptionsAsync(options); + var response = await GetInlayHints(fileName, code); + Assert.Empty(response); + } + + { + await SetInlayHintOptionsAsync(options with { ForIndexerParameters = true }); + var response = await GetInlayHints(fileName, code); + AssertEx.Equal(new[] + { + new InlayHint { Position = new Position { Line = 3, Character = 2 }, Label = "test:", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 3, Character = 2 }, End = new Position() { Line = 3, Character = 2 } }, NewText = "test: " } }, PaddingLeft = false, PaddingRight = true }, + new InlayHint { Position = new Position { Line = 3, Character = 9 }, Label = "test:", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 3, Character = 9 }, End = new Position() { Line = 3, Character = 9 } }, NewText = "test: " } }, PaddingLeft = false, PaddingRight = true } + }, + response, + ignoreDataComparer); + } + } + + [Theory] + [InlineData("dummy.cs")] + [InlineData("dummy.csx")] + public async Task InlayHintsForObjectCreationParameters(string fileName) + { + var code = @" +int i = 1; +{|ihRegion:M(new C())|}; + +void M(C c) {} + +class C +{ +} +"; + + var options = InlayHintsOptions.AllOn with { ForObjectCreationParameters = false }; + + { + await SetInlayHintOptionsAsync(options); + var response = await GetInlayHints(fileName, code); + Assert.Empty(response); + } + + { + await SetInlayHintOptionsAsync(options with { ForObjectCreationParameters = true }); + var response = await GetInlayHints(fileName, code); + AssertEx.Equal(new[] + { + new InlayHint { Position = new Position { Line = 2, Character = 2 }, Label = "c:", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 2, Character = 2 }, End = new Position() { Line = 2, Character = 2 } }, NewText = "c: " } }, PaddingLeft = false, PaddingRight = true } + }, + response, + ignoreDataComparer); + } + } + + [Theory] + [InlineData("dummy.cs")] + [InlineData("dummy.csx")] + public async Task InlayHintsForOtherParameters(string fileName) + { + var code = @" +int i = 1; +{|ihRegion:M(i)|}; + +void M(int test) {} +"; + + var options = InlayHintsOptions.AllOn with { ForOtherParameters = false }; + + { + + await SetInlayHintOptionsAsync(options); + var response = await GetInlayHints(fileName, code); + Assert.Empty(response); + } + + { + await SetInlayHintOptionsAsync(options with { ForOtherParameters = true }); + var response = await GetInlayHints(fileName, code); + AssertEx.Equal(new[] + { + new InlayHint { Position = new Position { Line = 2, Character = 2 }, Label = "test:", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 2, Character = 2 }, End = new Position() { Line = 2, Character = 2 } }, NewText = "test: " } }, PaddingLeft = false, PaddingRight = true } + }, + response, + ignoreDataComparer); + } + } + + [Theory] + [InlineData("dummy.cs")] + [InlineData("dummy.csx")] + public async Task InlayHintsSuppressForParametersThatDifferOnlyBySuffix(string fileName) + { + var code = @" +{|ihRegion:M(1, 2)|}; + +void M(int test1, int test2) {} +"; + + var options = InlayHintsOptions.AllOn; + + { + await SetInlayHintOptionsAsync(options); + var response = await GetInlayHints(fileName, code); + Assert.Empty(response); + } + + { + await SetInlayHintOptionsAsync(options with { SuppressForParametersThatDifferOnlyBySuffix = false }); + var response = await GetInlayHints(fileName, code); + AssertEx.Equal(new[] + { + new InlayHint { Position = new Position { Line = 1, Character = 2 }, Label = "test1:", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 1, Character = 2 }, End = new Position() { Line = 1, Character = 2 } }, NewText = "test1: " } }, PaddingLeft = false, PaddingRight = true }, + new InlayHint { Position = new Position { Line = 1, Character = 5 }, Label = "test2:", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 1, Character = 5 }, End = new Position() { Line = 1, Character = 5 } }, NewText = "test2: " } }, PaddingLeft = false, PaddingRight = true } + }, + response, + ignoreDataComparer); + } + } + + [Theory] + [InlineData("dummy.cs")] + [InlineData("dummy.csx")] + public async Task InlayHintsSuppressForParametersThatMatchMethodIntent(string fileName) + { + var code = @" +{|ihRegion:C.EnableSomething(true)|}; + +class C +{ + public static void EnableSomething(bool enabled) {} +} +"; + + var options = InlayHintsOptions.AllOn; + + { + await SetInlayHintOptionsAsync(options); + var response = await GetInlayHints(fileName, code); + Assert.Empty(response); + } + + { + await SetInlayHintOptionsAsync(options with { SuppressForParametersThatMatchMethodIntent = false }); + var response = await GetInlayHints(fileName, code); + AssertEx.Equal(new[] + { + new InlayHint { Position = new Position { Line = 1, Character = 18 }, Label = "enabled:", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 1, Character = 18 }, End = new Position() { Line = 1, Character = 18 } }, NewText = "enabled: " } }, PaddingLeft = false, PaddingRight = true } + }, + response, + ignoreDataComparer); + } + } + + [Theory] + [InlineData("dummy.cs")] + [InlineData("dummy.csx")] + public async Task InlayHintsSuppressForParametersThatMatchArgumentName(string fileName) + { + var code = @" +int i = 0; +{|ihRegion:C.M(i)|}; + +class C +{ + public static void M(int i) {} +} +"; + + var options = InlayHintsOptions.AllOn; + + { + await SetInlayHintOptionsAsync(options); + var response = await GetInlayHints(fileName, code); + Assert.Empty(response); + } + + { + await SetInlayHintOptionsAsync(options with { SuppressForParametersThatMatchArgumentName = false }); + var response = await GetInlayHints(fileName, code); + AssertEx.Equal(new[] + { + new InlayHint { Position = new Position { Line = 2, Character = 4 }, Label = "i:", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 2, Character = 4 }, End = new Position() { Line = 2, Character = 4 } }, NewText = "i: " } }, PaddingLeft = false, PaddingRight = true } + }, + response, + ignoreDataComparer); + } + } + + protected async Task GetInlayHints(string filename, string source) + { + var bufferPath = $"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}somepath{Path.DirectorySeparatorChar}{filename}"; + var testFile = new TestFile(bufferPath, source); + + OmniSharpTestHost.AddFilesToWorkspace(new[] { testFile }); + + var range = testFile.Content.GetRangeFromSpan(testFile.Content.GetSpans("ihRegion").Single()).GetSelection(); + + var request = new InlayHintParams + { + TextDocument = new TextDocumentIdentifier(bufferPath), + Range = new Range() + { + Start = new Position() + { + Line = range.Start.Line, + Character = range.Start.Column + }, + End = new Position() + { + Line = range.End.Line, + Character = range.End.Column + } + } + }; + + return await Client.RequestInlayHints(request); + } + + protected async Task ResolveInlayHint(InlayHint inlayHint) + { + return await Client.ResolveInlayHint(inlayHint); + } + + protected async Task SetInlayHintOptionsAsync(InlayHintsOptions options) + { + await Restart(configurationData: InlayHintsOptionsToDictionary(options)); + } + + private Dictionary InlayHintsOptionsToDictionary(InlayHintsOptions options) + => new() + { + [$"{nameof(RoslynExtensionsOptions)}:{nameof(InlayHintsOptions)}:{nameof(InlayHintsOptions.EnableForParameters)}"] = options.EnableForParameters.ToString(), + [$"{nameof(RoslynExtensionsOptions)}:{nameof(InlayHintsOptions)}:{nameof(InlayHintsOptions.ForLiteralParameters)}"] = options.ForLiteralParameters.ToString(), + [$"{nameof(RoslynExtensionsOptions)}:{nameof(InlayHintsOptions)}:{nameof(InlayHintsOptions.ForIndexerParameters)}"] = options.ForIndexerParameters.ToString(), + [$"{nameof(RoslynExtensionsOptions)}:{nameof(InlayHintsOptions)}:{nameof(InlayHintsOptions.ForObjectCreationParameters)}"] = options.ForObjectCreationParameters.ToString(), + [$"{nameof(RoslynExtensionsOptions)}:{nameof(InlayHintsOptions)}:{nameof(InlayHintsOptions.ForOtherParameters)}"] = options.ForOtherParameters.ToString(), + [$"{nameof(RoslynExtensionsOptions)}:{nameof(InlayHintsOptions)}:{nameof(InlayHintsOptions.SuppressForParametersThatDifferOnlyBySuffix)}"] = options.SuppressForParametersThatDifferOnlyBySuffix.ToString(), + [$"{nameof(RoslynExtensionsOptions)}:{nameof(InlayHintsOptions)}:{nameof(InlayHintsOptions.SuppressForParametersThatMatchMethodIntent)}"] = options.SuppressForParametersThatMatchMethodIntent.ToString(), + [$"{nameof(RoslynExtensionsOptions)}:{nameof(InlayHintsOptions)}:{nameof(InlayHintsOptions.SuppressForParametersThatMatchArgumentName)}"] = options.SuppressForParametersThatMatchArgumentName.ToString(), + [$"{nameof(RoslynExtensionsOptions)}:{nameof(InlayHintsOptions)}:{nameof(InlayHintsOptions.EnableForTypes)}"] = options.EnableForTypes.ToString(), + [$"{nameof(RoslynExtensionsOptions)}:{nameof(InlayHintsOptions)}:{nameof(InlayHintsOptions.ForImplicitVariableTypes)}"] = options.ForImplicitVariableTypes.ToString(), + [$"{nameof(RoslynExtensionsOptions)}:{nameof(InlayHintsOptions)}:{nameof(InlayHintsOptions.ForLambdaParameterTypes)}"] = options.ForLambdaParameterTypes.ToString(), + [$"{nameof(RoslynExtensionsOptions)}:{nameof(InlayHintsOptions)}:{nameof(InlayHintsOptions.ForImplicitObjectCreation)}"] = options.ForImplicitObjectCreation.ToString(), + }; + + private class IgnoreDataComparer : IEqualityComparer + { + public bool Equals(InlayHint x, InlayHint y) + { + if (ReferenceEquals(x, y)) return true; + if (x is null) return false; + if (y is null) return false; + + return x.Position == y.Position + && x.Label == y.Label + && x.Tooltip == y.Tooltip + && TextEditsEqual(x.TextEdits?.ToArray(), y.TextEdits?.ToArray()) + && x.PaddingLeft == y.PaddingLeft + && x.PaddingRight == y.PaddingRight; + } + + private static bool TextEditsEqual(TextEdit[] a, TextEdit[] b) + { + if (a is null) + { + return b is null; + } + + if (b is null) + { + return false; + } + + if (a.Length != b.Length) + { + return false; + } + + for (int index = 0; index < a.Length; index++) + { + if (!a[index].Equals(b[index])) + { + return false; + } + } + + return true; + } + + public int GetHashCode(InlayHint x) + => (x.Position, x.Label, x.Tooltip, x.TextEdits?.GetHashCode() ?? 0, x.PaddingLeft, x.PaddingRight).GetHashCode(); + } +} From 5a90ffadc9593d90c11d7cf6cb9241a5bc2d934d Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Mon, 18 Sep 2023 06:15:14 -0700 Subject: [PATCH 3/9] Update default language version should be latest test --- tests/OmniSharp.Script.Tests/ScriptProjectProviderTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/OmniSharp.Script.Tests/ScriptProjectProviderTests.cs b/tests/OmniSharp.Script.Tests/ScriptProjectProviderTests.cs index c4fda182e3..d71165b28c 100644 --- a/tests/OmniSharp.Script.Tests/ScriptProjectProviderTests.cs +++ b/tests/OmniSharp.Script.Tests/ScriptProjectProviderTests.cs @@ -17,7 +17,7 @@ public void DefaultLanguageVersionShouldBeLatest() var scriptProjectProvider = new ScriptProjectProvider(new ScriptOptions(), new OmniSharpEnvironment(), new LoggerFactory(), true, false); var scriptProjectInfo = scriptProjectProvider.CreateProject("test.csx", Enumerable.Empty(), Path.GetTempPath(), typeof(CommandLineScriptGlobals)); Assert.Equal(LanguageVersion.Latest, ((CSharpParseOptions)scriptProjectInfo.ParseOptions).SpecifiedLanguageVersion); - Assert.Equal(LanguageVersion.CSharp11, ((CSharpParseOptions)scriptProjectInfo.ParseOptions).LanguageVersion); + Assert.Equal(LanguageVersion.CSharp12, ((CSharpParseOptions)scriptProjectInfo.ParseOptions).LanguageVersion); } } } From 152ab466ef16048302b0b9bc3d2345ecf3cc2fae Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Mon, 18 Sep 2023 07:19:27 -0700 Subject: [PATCH 4/9] Return the trimmed InlayHint label. --- .../Handlers/OmniSharpInlayHintHandler.cs | 2 +- tests/OmniSharp.Lsp.Tests/OmniSharpInlayHintHandlerFacts.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpInlayHintHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpInlayHintHandler.cs index c1d74ee570..3355f670c9 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpInlayHintHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpInlayHintHandler.cs @@ -76,7 +76,7 @@ private static LSPInlayHint ToLSPInlayHint(OmniSharpInlayHint hint) var trimmedLabel = trimmedStartLabel.TrimEnd(); return new LSPInlayHint() { - Label = hint.Label, + Label = trimmedLabel, Tooltip = hint.Tooltip, Position = ToPosition(hint.Position), TextEdits = new(ToTextEdits(hint.TextEdits)), diff --git a/tests/OmniSharp.Lsp.Tests/OmniSharpInlayHintHandlerFacts.cs b/tests/OmniSharp.Lsp.Tests/OmniSharpInlayHintHandlerFacts.cs index 511b7898c3..c2f4147680 100644 --- a/tests/OmniSharp.Lsp.Tests/OmniSharpInlayHintHandlerFacts.cs +++ b/tests/OmniSharp.Lsp.Tests/OmniSharpInlayHintHandlerFacts.cs @@ -149,7 +149,7 @@ public async Task InlayHintsForVarTypes(string fileName) var response = await GetInlayHints(fileName, code); AssertEx.Equal(new[] { - new InlayHint { Position = new Position { Line = 1, Character = 4 }, Label = "int", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 1, Character = 0 }, End = new Position() { Line = 1, Character = 3 } }, NewText = "int" } }, PaddingLeft = false, PaddingRight = true }, + new InlayHint { Position = new Position { Line = 1, Character = 4 }, Label = "int", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 1, Character = 0 }, End = new Position() { Line = 1, Character = 3 } }, NewText = "int " } }, PaddingLeft = false, PaddingRight = true }, }, response, ignoreDataComparer); @@ -239,8 +239,8 @@ void M(int i) {} var response = await GetInlayHints(fileName, code); AssertEx.Equal(new[] { - new InlayHint { Position = new Position { Line = 1, Character = 2 }, Label = "i:", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 1, Character = 2 }, End = new Position() { Line = 1, Character = 2 } }, NewText = "i: " } }, PaddingLeft = false, PaddingRight = true } - }, + new InlayHint { Position = new Position { Line = 1, Character = 2 }, Label = "i:", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 1, Character = 2 }, End = new Position() { Line = 1, Character = 2 } }, NewText = "i: " } }, PaddingLeft = false, PaddingRight = true } + }, response, ignoreDataComparer); } From 507430929110cc71341f688a683f37c8ddb6adb2 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Mon, 18 Sep 2023 08:17:34 -0700 Subject: [PATCH 5/9] Fix test --- tests/OmniSharp.Lsp.Tests/OmniSharpInlayHintHandlerFacts.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/OmniSharp.Lsp.Tests/OmniSharpInlayHintHandlerFacts.cs b/tests/OmniSharp.Lsp.Tests/OmniSharpInlayHintHandlerFacts.cs index c2f4147680..2e4bb1da89 100644 --- a/tests/OmniSharp.Lsp.Tests/OmniSharpInlayHintHandlerFacts.cs +++ b/tests/OmniSharp.Lsp.Tests/OmniSharpInlayHintHandlerFacts.cs @@ -149,7 +149,7 @@ public async Task InlayHintsForVarTypes(string fileName) var response = await GetInlayHints(fileName, code); AssertEx.Equal(new[] { - new InlayHint { Position = new Position { Line = 1, Character = 4 }, Label = "int", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 1, Character = 0 }, End = new Position() { Line = 1, Character = 3 } }, NewText = "int " } }, PaddingLeft = false, PaddingRight = true }, + new InlayHint { Position = new Position { Line = 1, Character = 4 }, Label = "int", Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 1, Character = 0 }, End = new Position() { Line = 1, Character = 3 } }, NewText = "int" } }, PaddingLeft = false, PaddingRight = true }, }, response, ignoreDataComparer); From f97297e69b96e5ae11dacb07a47c684c1644fc50 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Wed, 20 Sep 2023 09:13:53 -0700 Subject: [PATCH 6/9] Update pinned SDK to .NET 8 RC1 --- .github/workflows/build.yml | 2 +- .github/workflows/tests-net6.yml | 2 +- .github/workflows/tests.yml | 2 +- .pipelines/init.yml | 2 +- azure-pipelines.yml | 2 +- build.json | 4 ++-- global.json | 2 +- test-assets/test-projects/Net80Project/global.json | 2 +- .../ProjectLoadListenerTests.cs | 13 ++++++------- tests/OmniSharp.Tests/DotNetCliServiceFacts.cs | 2 +- 10 files changed, 16 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2584e2a9c7..bb7cf564de 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,7 @@ name: 'Build' env: - DotNetVersion: "8.0.100-preview.4.23260.5" + DotNetVersion: "8.0.100-rc.1.23463.5" DotNetVersion2: "7.0.302" DotNetVersion3: "6.0.203" NuGetVersion: "6.5.0" diff --git a/.github/workflows/tests-net6.yml b/.github/workflows/tests-net6.yml index a971ab186e..c3818e31cc 100644 --- a/.github/workflows/tests-net6.yml +++ b/.github/workflows/tests-net6.yml @@ -1,7 +1,7 @@ name: 'Tests net6.0' env: - DotNetVersion: "8.0.100-preview.4.23260.5" + DotNetVersion: "8.0.100-rc.1.23463.5" DotNetVersion2: "7.0.302" DotNetVersion3: "6.0.203" NuGetVersion: "6.5.0" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b802bc4c19..aea7444a09 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,7 +1,7 @@ name: 'Tests' env: - DotNetVersion: "8.0.100-preview.4.23260.5" + DotNetVersion: "8.0.100-rc.1.23463.5" DotNetVersion2: "7.0.302" DotNetVersion3: "6.0.203" NuGetVersion: "6.5.0" diff --git a/.pipelines/init.yml b/.pipelines/init.yml index 579685656c..28f941900d 100644 --- a/.pipelines/init.yml +++ b/.pipelines/init.yml @@ -1,7 +1,7 @@ parameters: # Configuration: Release Verbosity: Normal - DotNetVersion: "8.0.100-preview.4.23260.5" + DotNetVersion: "8.0.100-rc.1.23463.5" DotNetVersion2: "7.0.302" DotNetVersion3: "6.0.203" CakeVersion: "1.1.0" diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 6af92c2360..d2c4a20444 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -32,7 +32,7 @@ resources: variables: Verbosity: Diagnostic - DotNetVersion: "8.0.100-preview.4.23260.5" + DotNetVersion: "8.0.100-rc.1.23463.5" CakeVersion: "3.0.0" NuGetVersion: "6.5.0" GitVersionVersion: "5.0.1" diff --git a/build.json b/build.json index f519809236..d4869b6928 100644 --- a/build.json +++ b/build.json @@ -4,7 +4,7 @@ "DotNetVersions": [ "6.0.203", "7.0.302", - "8.0.100-preview.4.23260.5" + "8.0.100-rc.1.23463.5" ], "RequiredMonoVersion": "6.6.0", "DownloadURL": "https://roslynomnisharp.blob.core.windows.net/ext", @@ -54,4 +54,4 @@ "RestoreOnlyTestAssets": [ "ProjectWithMissingType" ] -} \ No newline at end of file +} diff --git a/global.json b/global.json index 0645b687ae..ff9d0be2a6 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "8.0.100-preview.4.23260.5", + "version": "8.0.100-rc.1.23463.5", "rollForward": "latestMinor" } } diff --git a/test-assets/test-projects/Net80Project/global.json b/test-assets/test-projects/Net80Project/global.json index 49e7f1ad73..9464089fc5 100644 --- a/test-assets/test-projects/Net80Project/global.json +++ b/test-assets/test-projects/Net80Project/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "8.0.100-preview.4.23260.5" + "version": "8.0.100-rc.1.23463.5" } } \ No newline at end of file diff --git a/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs b/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs index c0692865f2..6a35385019 100644 --- a/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs @@ -1,14 +1,13 @@ -using Microsoft.Build.Construction; -using Microsoft.Build.Execution; -using Microsoft.CodeAnalysis; -using Microsoft.Extensions.Logging; - -using OmniSharp.Services; using System.Collections.Generic; using System.Collections.Immutable; using System.IO; using System.Linq; using System.Threading.Tasks; +using Microsoft.Build.Construction; +using Microsoft.Build.Execution; +using Microsoft.CodeAnalysis; +using Microsoft.Extensions.Logging; +using OmniSharp.Services; using TestUtility; using Xunit; using Xunit.Abstractions; @@ -244,7 +243,7 @@ public async Task The_correct_sdk_version_is_emitted_NET8() using var testProject = await TestAssets.Instance.GetTestProjectAsync("Net80Project"); using var host = CreateMSBuildTestHost(testProject.Directory, emitter.AsExportDescriptionProvider(LoggerFactory)); Assert.Single(emitter.ReceivedMessages); - Assert.Equal(GetHashedFileExtension("8.0.100-preview.4.23260.5"), emitter.ReceivedMessages[0].SdkVersion); + Assert.Equal(GetHashedFileExtension("8.0.100-rc.1.23463.5"), emitter.ReceivedMessages[0].SdkVersion); } private string GetHashedFileExtension(string fileExtension) diff --git a/tests/OmniSharp.Tests/DotNetCliServiceFacts.cs b/tests/OmniSharp.Tests/DotNetCliServiceFacts.cs index 01e504f99c..4438a4afdf 100644 --- a/tests/OmniSharp.Tests/DotNetCliServiceFacts.cs +++ b/tests/OmniSharp.Tests/DotNetCliServiceFacts.cs @@ -7,7 +7,7 @@ namespace OmniSharp.Tests { public class DotNetCliServiceFacts : AbstractTestFixture { - private const string DotNetVersion = "8.0.100-preview.4.23260.5"; + private const string DotNetVersion = "8.0.100-rc.1.23463.5"; private int Major { get; } private int Minor { get; } private int Patch { get; } From c55a53f661b379006799aaa1ab55e78a0aec248f Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Thu, 21 Sep 2023 16:27:43 -0700 Subject: [PATCH 7/9] Update OmniSharp.Extensions.LanguageServer to v0.19.9 --- Directory.Packages.props | 13 ++++--------- .../Handlers/OmniSharpInlayHintHandler.cs | 10 +++++++--- .../OmniSharp.LanguageServerProtocol.csproj | 6 ------ 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 62f5103457..508fdee960 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -4,6 +4,7 @@ true true + 0.19.9 7.0.0 17.6.0 17.3.2 @@ -65,12 +66,6 @@ - - - - @@ -84,9 +79,9 @@ - - - + + + diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpInlayHintHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpInlayHintHandler.cs index 3355f670c9..fac147f164 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpInlayHintHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpInlayHintHandler.cs @@ -77,7 +77,9 @@ private static LSPInlayHint ToLSPInlayHint(OmniSharpInlayHint hint) return new LSPInlayHint() { Label = trimmedLabel, - Tooltip = hint.Tooltip, + Tooltip = hint.Tooltip is null + ? null + : new MarkupContent() { Kind = MarkupKind.Markdown, Value = hint.Tooltip }, Position = ToPosition(hint.Position), TextEdits = new(ToTextEdits(hint.TextEdits)), PaddingLeft = hint.Label.Length > trimmedStartLabel.Length, @@ -91,14 +93,16 @@ private static OmniSharpInlayHint FromLSPInlayHint(LSPInlayHint hint) return new OmniSharpInlayHint() { Label = $"{(hint.PaddingLeft == true ? " " : "")}{hint.Label.String}{(hint.PaddingRight == true ? " " : "")}", - Tooltip = hint.Tooltip?.String, + Tooltip = hint.Tooltip.HasMarkupContent + ? hint.Tooltip.MarkupContent.Value + : hint.Tooltip?.String, Position = FromPosition(hint.Position), TextEdits = hint.TextEdits is null ? null : FromTextEdits(hint.TextEdits), Data = hint.Data.ToObject<(string SolutionVersion, int Position)>() }; } - protected override InlayHintRegistrationOptions CreateRegistrationOptions(InlayHintWorkspaceClientCapabilities capability, ClientCapabilities clientCapabilities) + protected override InlayHintRegistrationOptions CreateRegistrationOptions(InlayHintClientCapabilities capability, ClientCapabilities clientCapabilities) { return new InlayHintRegistrationOptions() { diff --git a/src/OmniSharp.LanguageServerProtocol/OmniSharp.LanguageServerProtocol.csproj b/src/OmniSharp.LanguageServerProtocol/OmniSharp.LanguageServerProtocol.csproj index 0ec36f821d..3ba8f94765 100644 --- a/src/OmniSharp.LanguageServerProtocol/OmniSharp.LanguageServerProtocol.csproj +++ b/src/OmniSharp.LanguageServerProtocol/OmniSharp.LanguageServerProtocol.csproj @@ -14,12 +14,6 @@ - - - - From 49300e575ad4242788054a760b6e3c0c6bfc6c38 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Fri, 22 Sep 2023 08:06:04 -0700 Subject: [PATCH 8/9] Fix null ref in FromLSPInlayHint method --- .../Handlers/OmniSharpInlayHintHandler.cs | 14 ++++++++------ .../OmniSharpInlayHintHandlerFacts.cs | 8 ++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpInlayHintHandler.cs b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpInlayHintHandler.cs index fac147f164..b2673e7b75 100644 --- a/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpInlayHintHandler.cs +++ b/src/OmniSharp.LanguageServerProtocol/Handlers/OmniSharpInlayHintHandler.cs @@ -77,9 +77,9 @@ private static LSPInlayHint ToLSPInlayHint(OmniSharpInlayHint hint) return new LSPInlayHint() { Label = trimmedLabel, - Tooltip = hint.Tooltip is null - ? null - : new MarkupContent() { Kind = MarkupKind.Markdown, Value = hint.Tooltip }, + Tooltip = hint.Tooltip is not null + ? new MarkupContent() { Kind = MarkupKind.Markdown, Value = hint.Tooltip } + : null, Position = ToPosition(hint.Position), TextEdits = new(ToTextEdits(hint.TextEdits)), PaddingLeft = hint.Label.Length > trimmedStartLabel.Length, @@ -93,9 +93,11 @@ private static OmniSharpInlayHint FromLSPInlayHint(LSPInlayHint hint) return new OmniSharpInlayHint() { Label = $"{(hint.PaddingLeft == true ? " " : "")}{hint.Label.String}{(hint.PaddingRight == true ? " " : "")}", - Tooltip = hint.Tooltip.HasMarkupContent - ? hint.Tooltip.MarkupContent.Value - : hint.Tooltip?.String, + Tooltip = hint.Tooltip is not null + ? hint.Tooltip.HasMarkupContent + ? hint.Tooltip.MarkupContent.Value + : hint.Tooltip.String + : null, Position = FromPosition(hint.Position), TextEdits = hint.TextEdits is null ? null : FromTextEdits(hint.TextEdits), Data = hint.Data.ToObject<(string SolutionVersion, int Position)>() diff --git a/tests/OmniSharp.Lsp.Tests/OmniSharpInlayHintHandlerFacts.cs b/tests/OmniSharp.Lsp.Tests/OmniSharpInlayHintHandlerFacts.cs index 2e4bb1da89..3d6d570dfc 100644 --- a/tests/OmniSharp.Lsp.Tests/OmniSharpInlayHintHandlerFacts.cs +++ b/tests/OmniSharp.Lsp.Tests/OmniSharpInlayHintHandlerFacts.cs @@ -54,25 +54,25 @@ class C { } AssertEx.AssertEqualToleratingWhitespaceDifferences(@" ```csharp (parameter) C param1 -```", param1.Tooltip.String); +```", param1.Tooltip.MarkupContent.Value); var paramB = await ResolveInlayHint(inlayHints[1]); AssertEx.AssertEqualToleratingWhitespaceDifferences(@" ```csharp (parameter) C paramB -```", paramB.Tooltip.String); +```", paramB.Tooltip.MarkupContent.Value); var c1 = await ResolveInlayHint(inlayHints[2]); AssertEx.AssertEqualToleratingWhitespaceDifferences(@" ```csharp class C -```", c1.Tooltip.String); +```", c1.Tooltip.MarkupContent.Value); var c2 = await ResolveInlayHint(inlayHints[3]); AssertEx.AssertEqualToleratingWhitespaceDifferences(@" ```csharp class C -```", c2.Tooltip.String); +```", c2.Tooltip.MarkupContent.Value); } [Theory] From 008a0c35539a2289b7f965af8e1a73ad35999332 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Fri, 22 Sep 2023 09:45:03 -0700 Subject: [PATCH 9/9] Update NuGet packages to 6.8.0-preview.1.69 --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 508fdee960..b28d8f9903 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -8,7 +8,7 @@ 7.0.0 17.6.0 17.3.2 - 6.8.0-preview.1.41 + 6.8.0-preview.1.69 4.8.0-1.23419.1 2.4.1