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

GoTo Definition for marked template type not working as expected #307

Open
juxeii opened this issue Mar 16, 2022 · 5 comments
Open

GoTo Definition for marked template type not working as expected #307

juxeii opened this issue Mar 16, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@juxeii
Copy link

juxeii commented Mar 16, 2022

In the term std::optional<types::nr_rrc::BandList>, I mark BandList and hit Go to Definition.
I would expect that this jumps to types::nr_rrc::BandList, but it jumps to std::optional.

Do I miss something here?

@juxeii juxeii added the enhancement New feature or request label Mar 16, 2022
@HighCommander4
Copy link
Contributor

HighCommander4 commented Mar 16, 2022

The Language Server Protocol currently only accepts a single position as input for the go-to-definition request, not a range.

Assuming you've selected the range BandList in the forward direction, such that your cursor is between the t and >, it's this cursor position that's sent.

Clangd then needs to decide whether to use the > or the t for targeting. It tries the character to the right of the cursor first, i.e. the >, which is associated with the class template, so it navigates to the class template.

I agree this behaviour is suboptimal. Hopefully, LSP can add support for sending the entire range in microsoft/language-server-protocol#1029.

@sam-mccall
Copy link
Member

I don't think MS is likely to fix this.
I think we should probably add an extension client capability to control the behavior and set it in the VSCode plugin. For ibeam-editors bias-toward-identifier is better than bias-right.

Last time i thought about this i got stuck on the idea that this might not be fixed for an editor (e.g. vim mode for VSCode) or even vary over time (modal editing). But this is probably perfect-as-enemy-of-the-good.

@HighCommander4
Copy link
Contributor

I don't think MS is likely to fix this.

I'm all for making the clangd-only fix you describe, but I'm also curious why you don't think this will be fixed in LSP. Range inputs seem useful independent of this specific issue; are you expecting resistance to them for a particular reason, rather than just being a matter of someone doing the work of a fleshed-out proposal with spec and vscode client changes?

@juxeii
Copy link
Author

juxeii commented Mar 16, 2022

I am wondering how CLion does this, since AFAIK they also use clang. There, the Go to Definition works as intuitevly expected.

@wangyu-
Copy link

wangyu- commented Aug 24, 2022

I have encountered similiar problems.

Thanks for @HighCommander4 's explanation, I have found the reason and known how to a workaround it.

Assuming you've selected the range BandList in the forward direction, such that your cursor is between the t and >, it's this cursor position that's sent.

Clangd then needs to decide whether to use the > or the t for targeting. It tries the character to the right of the cursor first, i.e. the >, which is associated with the class template, so it navigates to the class template.

For me, the "go to definition" doesn't work correctly since I have a habit of double clicking on the BandList, then the cursor is automatically placed at the end of BandList. For my case, the workaround is just to put the cursor in the middle of BandList and don't double click.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants