Skip to content

Conversation

@tcx4c70
Copy link
Contributor

@tcx4c70 tcx4c70 commented Feb 28, 2023

This PR is trying to add support for inlay hint. In fact, Roslyn has
already implemented the feature via language service in
https://github.com/dotnet/roslyn/blob/main/src/Features/CSharp/Portable/InlineHints/CSharpInlineTypeHintsService.cs &
https://github.com/dotnet/roslyn/blob/main/src/Features/CSharp/Portable/InlineHints/CSharpInlineParameterNameHintsService.cs.
However, the implementation and the interface, IInlineHintsService,
are internal, so we can't call the implementation directly (we can't
even get the implementation via
doc.Project.LanguageServices.GetRequiredService<IInlineHintsService>).

Hence, this PR rewrites the implementation using F#. Unlike the
implementation in Roslyn, however, this PR always puts type inlay hints
after the identifier and parameter inlay hints before the argument, just
like what clangd does, because not only will it keep the implementation
simple, but also it's the position I like.

Signed-off-by: Adam Tao <tcx4c70@gmail.com>
Add type inlay hint to the end of identifiers, just like what clangd
does.

This commit is almost a rewrite of https://github.com/dotnet/roslyn/blob/main/src/Features/CSharp/Portable/InlineHints/CSharpInlineTypeHintsService.cs.
Because Roslyn doesn't exposes the related classes/methods (they are
`internal`), we can't call them directly. Therefore, I try to rewrite
them using F# in this commit.

Signed-off-by: Adam Tao <tcx4c70@gmail.com>
Signed-off-by: Adam Tao <tcx4c70@gmail.com>
Add parameter inlay hints before afguments, just like what clangd does.

This commit is almost a rewrite of https://github.com/dotnet/roslyn/blob/main/src/Features/CSharp/Portable/InlineHints/CSharpInlineParameterNameHintsService.cs.

Signed-off-by: Adam Tao <tcx4c70@gmail.com>
Signed-off-by: Adam Tao <tcx4c70@gmail.com>
1. Suppress parameter hint for indexer.
2. Suppress parameter hint if argument matches parameter name.

Signed-off-by: Adam Tao <tcx4c70@gmail.com>
@tcx4c70
Copy link
Contributor Author

tcx4c70 commented Feb 28, 2023

A simple example from my editor (vim + coc.nvim):

image

(Italic text is the inlay hint.)

@razzmatazz
Copy link
Owner

However, the implementation and the interface, IInlineHintsService,
are internal, so we can't call the implementation directly (we can't
even get the implementation via
doc.Project.LanguageServices.GetRequiredService).

I was dabbling into this some months ago and had the same observation. But you did reimplement it properly, 🙇🏻

@razzmatazz
Copy link
Owner

Will do some testing and will merge.

Thank you!

@razzmatazz
Copy link
Owner

Works with vscode nicely! Thanks! (I was using https://github.com/statiolake/vscode-csharp-ls to test this, because emacs/lsp-mode does not apparently support inlay hints yet)

@razzmatazz
Copy link
Owner

I do see a little issue (see screenshot below).

@tcx4c70

The var-declared list has inlay hint that defines nothing, probably something to fix?

Bildschirm­foto 2023-03-03 um 07 54 42

@razzmatazz razzmatazz merged commit 3bbe13c into razzmatazz:master Mar 3, 2023
@tcx4c70
Copy link
Contributor Author

tcx4c70 commented Mar 3, 2023

I do see a little issue (see screenshot below).

@tcx4c70

The var-declared list has inlay hint that defines nothing, probably something to fix?

Bildschirm­foto 2023-03-03 um 07 54 42

@razzmatazz Will investigate it and will try to fix. Thanks for your testing!

@tcx4c70 tcx4c70 deleted the feat/inlay-hint branch March 3, 2023 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants