yaml-language-server icon indicating copy to clipboard operation
yaml-language-server copied to clipboard

Add anchor preview in hover

Open Hugo-Hache opened this issue 2 months ago • 4 comments

What does this PR do?

It displays the preview of an anchor when hovering it.

image

What issues does this PR fix or reference?

This is a very rough proposal to check if you would be interested in merging this feature. If this is the case, I'll put more time in writing the test and improving the code based on your remarks.

Hugo-Hache avatar Dec 05 '25 17:12 Hugo-Hache

Coverage Status

coverage: 82.913% (-1.0%) from 83.961% when pulling 235ca9f98ee99c7a5bfa2e7c39626de49d152a1c on Hugo-Hache:hh/hover-anchor into d17039f1fc1880a3edce45589988822608f3b44d on redhat-developer:main.

coveralls avatar Dec 05 '25 19:12 coveralls

I think this sounds helpful. I can find time to review it, though I can't promise I'll be fast.

I tried it out, and I have a good initial impression of it. I haven't tested it thoroughly or looked closely at the code yet though.

I noticed it was disabled by default, any reason for that? It seems like a helpful feature, and I can't think of drawbacks of enabling it by default. People need to go out of their way to find any features that aren't enabled by default, which could mean it doesn't get used.

datho7561 avatar Dec 05 '25 21:12 datho7561

As I didn't know if it was a common use case I conservatively set the default to false, but I agree with you that plenty of users might discover this hover by serendipity and enjoy it.

For the resolveYamlMapMergeKeys function I guess we would need to limit the number of recursion to prevent performance issue in very large YAML (but I noticed there is a maxItemsComputed, so maybe it's enough to prevent it).

Anyway it's good news it looks helpful to you. Thanks for the time you'll invest in testing/reviewing it.

Hugo-Hache avatar Dec 05 '25 22:12 Hugo-Hache

  • Changed shouldHoverAnchor to default as true
  • Added MAX_MERGE_RECURSION_LEVEL (and simplified code by removing resolveYamlMapMergeKeys or seenKeys)

I committed a max recursion level of 10, does it look good to you? (screenshot with a modified local limit of 3)

Screenshot 2025-12-10 at 18 05 39

Hugo-Hache avatar Dec 10 '25 17:12 Hugo-Hache