Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR backports upstream pr ocaml/merlin#1864, which fixes some behavior in the
type-enclosingquery. By default,type-enclosingreturns a list of results, corresponding to nodes enclosing the given position with expanding ranges. For example, if you runtype-enclosingonSome (x + 1)with the cursor onx, you will get results corresponding to the expressionsx,x + 1, andSome (x + 1).Printing types is expensive, so Merlin offers a parameter
-indextotype-enclosingthat allows you to only request the nth element of that list. Thus, editors can start by requesting only the innermost result and then progressively increase the range as a user requests to.But the current implementation has a problem. Merlin has some logic to deduplicate results, but the logic is partially based on the types that are printed. Since Merlin will only print types for the requested index(es), the deduplication is based on what index is requested. This means that the list changes out from under you as you attempt to increase the range. This has caused bad behavior in emacs.
The upstream PR that this backports makes deduplication stable by not relying on printing. As a consequence, results are sometimes duplicated, and it is left to the client (which can maintain state between queries, unlike Merlin) to deduplicate them.
But after this upstream PR, Merlin still deduplicates results based on the ranges of the corresponding nodes. Nodes may sometimes have the same range, and I argue that if two nodes have the same range:
So this PR also makes the change such that we never deduplicate results. The short-term consequence of this (until we update clients to perform deduplication) will be that users sometimes see duplicate results. But this seems better than the current state of the world, which is that progressively expanding the range will frequently fail.
I've discussed this with JS lsp folks and they are on board with this change.
Reviewing