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

fix #2550 inlay hints lambdas parameter type null reference exception #2604

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private static LSPInlayHint ToLSPInlayHint(OmniSharpInlayHint hint)
? new MarkupContent() { Kind = MarkupKind.Markdown, Value = hint.Tooltip }
: null,
Position = ToPosition(hint.Position),
TextEdits = new(ToTextEdits(hint.TextEdits)),
TextEdits = hint.TextEdits is not null ? new(ToTextEdits(hint.TextEdits)) : null,
PaddingLeft = hint.Label.Length > trimmedStartLabel.Length,
PaddingRight = trimmedStartLabel.Length > trimmedLabel.Length,
Data = JToken.FromObject(hint.Data),
Expand Down
37 changes: 37 additions & 0 deletions tests/OmniSharp.Lsp.Tests/OmniSharpInlayHintHandlerFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,43 @@ public async Task InlayHintsForVarTypes(string fileName)
}
}

[Theory]
[InlineData("dummy.cs")]
[InlineData("dummy.csx")]
public async Task InlayHintsForLambdaParameterTypeNearFunctionParameterName(string fileName)
{
var code = @"
using System;
void fun(Func<int, bool> lambda) {}
{|ihRegion:fun(b => true);|}
";

var options = InlayHintsOptions.AllOn with { ForLambdaParameterTypes = false };

{
await SetInlayHintOptionsAsync(options);
var response = await GetInlayHints(fileName, code);
AssertEx.Equal(new[]
{
new InlayHint { Position = new Position { Line = 3, Character = 4 }, Label = "lambda:", Kind = InlayHintKind.Parameter, Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 3, Character = 4 }, End = new Position() { Line = 3, Character = 4 } }, NewText = "lambda: " } }, PaddingLeft = false, PaddingRight = true },
},
response,
ignoreDataComparer);
}

{
await SetInlayHintOptionsAsync(options with { ForLambdaParameterTypes = true });
var response = await GetInlayHints(fileName, code);
AssertEx.Equal(new[]
{
new InlayHint { Position = new Position { Line = 3, Character = 4 }, Label = "lambda:", Kind = InlayHintKind.Parameter, Tooltip = null, TextEdits = new[] { new TextEdit { Range = new Range() { Start = new Position() { Line = 3, Character = 4 }, End = new Position() { Line = 3, Character = 4 } }, NewText = "lambda: " } }, PaddingLeft = false, PaddingRight = true },
new InlayHint { Position = new Position { Line = 3, Character = 4 }, Label = "int", Kind = InlayHintKind.Type, Tooltip = null, TextEdits = null, PaddingLeft = false, PaddingRight = true },
},
response,
ignoreDataComparer);
}
}

[Theory]
[InlineData("dummy.cs")]
[InlineData("dummy.csx")]
Expand Down
Loading