Skip to content

Commit

Permalink
fix OmniSharp#2550 inlay hints labdas parameter type null reference e…
Browse files Browse the repository at this point in the history
…xception
  • Loading branch information
madiele committed Feb 17, 2024
1 parent 8495e47 commit 8a52fe9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
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

0 comments on commit 8a52fe9

Please sign in to comment.