Fix cmd+click find all references fallback not working in Vim mode (#10684)

Exclude go-to-definition links returned by LSP that points to the
current cursor position. This fixes #10392 . Related PR #9243 .

The previous implementation first performs go-to-definition, and if the
selected text covers the clicked position, it figures out that it is
already clicking on a definition, and should instead look for
references.

However, the selected range does not necessarily cover the clicked
position after clicking on a definition, as in VIM mode.

After the PR, if cmd+click on definitions, the definition links would be
an empty list, so no go-to-definition is performed, and
find-all-references is performed instead.

Release Notes:

- Fixed #10392 , now `cmd+click`ing to find all references works in vim
mode.
This commit is contained in:
Congyu 2024-04-25 23:07:14 +08:00 committed by GitHub
parent 11bcfea6d2
commit 21022f1644
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 53 additions and 67 deletions

View file

@ -7745,7 +7745,13 @@ impl Editor {
.update(&mut cx, |editor, cx| {
editor.navigate_to_hover_links(
Some(kind),
definitions.into_iter().map(HoverLink::Text).collect(),
definitions
.into_iter()
.filter(|location| {
hover_links::exclude_link_to_position(&buffer, &head, location, cx)
})
.map(HoverLink::Text)
.collect::<Vec<_>>(),
split,
cx,
)