Improve Inlay Hints Handling with [@merlin.hide]#1894
Improve Inlay Hints Handling with [@merlin.hide]#1894mlasson wants to merge 9 commits intoocaml:mainfrom
Conversation
c110cb7 to
1440a86
Compare
|
Is it ok to change the protocol/library in a non-backward compatible way ? |
|
It took me a while, but I finally understood why top-level let bindings were not annotated even with "hint_let_binding"—this is because code lenses already handle them. In a future pull request, we could make this behavior configurable with a new option, allowing users to choose between inlay hints and code lenses. In the meantime, I’ve reverted my change to the structure item iterator in commit 9b69539. I still need to rewrite it slightly to ensure we don’t skip a [@merlin.hide] attribute on value bindings. |
|
Hi @mlasson, sorry for not having answered earlier, I must have missed it. Looking at the tests this seems really interesting, thanks for that well though of and tested PR. Are you happy with it's current state ? Do you think you could rebase it so that we can do a proper review ? |
Description
Previously, inlay hints logic relied on ghost locations to avoid annotating generated code. But it lead to some inconsistencies because ghost locations are used in non-generated code, for instance:
In this case, an inlay hint appears for
xinf, but no hint is shown forg.In VS Code, this results in the following display:

This is because
is syntactic sugar for:
where
fun _ ->introduces a ghost location (the whole fun node).This is why you needed to disable the check on ghost location in your
samples.ttest.Proposed Fix
This PR replaces ghost location handling with the [@merlin.hide] attribute. This allows for more precise control over which parts of the AST should be ignored for inlay hints.
To make this approach work correctly, I refactored the main AST iterator to use
Ast_iterators.iter_only_visible. The iterator now ensures attributes are not skipped by recursing on non-immediate sub-terms.Also, this restructuring simplifies the code and makes inlay hints more consistent across different contexts (e.g., top-level
letbindings, class-levelletbindings, and expressionletbindings).Additional Changes
samples.twith new test cases illustrating the improved inlay hints behavior.avoid-ghost-locationoption (both in the CLI and protocol).Related
Screenshot