Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd+click symbol definition to find all references does not work in vim mode #10392

Closed
1 task done
Congyuwang opened this issue Apr 11, 2024 · 5 comments · Fixed by #10684
Closed
1 task done

cmd+click symbol definition to find all references does not work in vim mode #10392

Congyuwang opened this issue Apr 11, 2024 · 5 comments · Fixed by #10684
Labels
defect [core label] editor Feedback for code editing, formatting, editor iterations, etc vim

Comments

@Congyuwang
Copy link
Contributor

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

When "vim_mode": true, cmd + click only GoToDefinition but does not FindAllReference when clicking on def (in INSERT or NORMAL mode).

If vim mode is disabled, however, the bidirectional cmd + click works properly.

2024-04-11.09.24.52.mov

__

Environment

Zed: v0.131.1 (Zed Preview)
OS: macOS 14.4.1
Memory: 16 GiB
Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

Bidirectional cmd + click should work also in vim mode. Related #9259 .

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

No response

@Congyuwang Congyuwang added admin read Pending admin review defect [core label] triage Maintainer needs to classify the issue labels Apr 11, 2024
@JosephTLyons JosephTLyons added vim editor Feedback for code editing, formatting, editor iterations, etc and removed triage Maintainer needs to classify the issue admin read Pending admin review labels Apr 11, 2024
@Congyuwang
Copy link
Contributor Author

I wonder whether this is reproducible by others?

@mrnugget
Copy link
Member

Yeah, I can reproduce it.

@Congyuwang
Copy link
Contributor Author

Congyuwang commented Apr 17, 2024

I investigated the code. The current implementation: after cmd+clicking, if definition is found, check whether the selected definition range covers where the cursor previously was before the definition is revealed (if definition is not revealed elsewhere, it is revealed right here, so I am clicking right on the definition, so let's do FindAllReference).

fn revealed_elsewhere(
editor: &mut Editor,
before_revealing: Range<Anchor>,
cx: &mut ViewContext<'_, Editor>,
) -> bool {
let multi_buffer_snapshot = editor.buffer().read(cx).snapshot(cx);
let selection_after_revealing = editor.selections.newest::<Point>(cx);
let after_revealing_head = selection_after_revealing.head();
let after_revealing_tail = selection_after_revealing.tail();
let after_revealing = match after_revealing_tail.cmp(&after_revealing_head) {
cmp::Ordering::Equal | cmp::Ordering::Less => {
multi_buffer_snapshot.anchor_after(after_revealing_tail)
..multi_buffer_snapshot.anchor_before(after_revealing_head)
}
cmp::Ordering::Greater => {
multi_buffer_snapshot.anchor_after(after_revealing_head)
..multi_buffer_snapshot.anchor_before(after_revealing_tail)
}
};
let before_intersects_after_range = (before_revealing
.start
.cmp(&after_revealing.start, &multi_buffer_snapshot)
.is_ge()
&& before_revealing
.start
.cmp(&after_revealing.end, &multi_buffer_snapshot)
.is_le())
|| (before_revealing
.end
.cmp(&after_revealing.start, &multi_buffer_snapshot)
.is_ge()
&& before_revealing
.end
.cmp(&after_revealing.end, &multi_buffer_snapshot)
.is_le());
!before_intersects_after_range
}

This is working fine when vim mode is false. However, when vim mode is enabled, let selection_after_revealing = editor.selections.newest::<Point>(cx); does not select the whole definition range, but only the first character of the definition, which does not overlap with the old cursor position, and so revealed_elsewhere = ! before_intersects_after_range is now true, and FindAllReference is not performed.

@Congyuwang
Copy link
Contributor Author

Should vim go to VISUAL mode when jumping to definition?

@mrnugget
Copy link
Member

Should vim go to VISUAL mode when jumping to definition?

Hmmm, I'm not sure but that sounds wrong. I wonder whether we could change the check to say that if vim mode { if current_cursor already within the range of the definition } or something like that.

ConradIrwin pushed a commit that referenced this issue Apr 25, 2024
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect [core label] editor Feedback for code editing, formatting, editor iterations, etc vim
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants