weilbith / nvim-lsp-smag

Seamless integration of language server locations into NeoVim
MIT License
76 stars 5 forks source link

If LSP doesn't return tags attempt to get tags from the tag file #7

Closed nabaco closed 1 year ago

nabaco commented 2 years ago

At times I'm working on C projects where I don't have a compile_commands.json, and thus the LSP doesn't fully work on the file. But I do have tags file present, and I want Ctrl-] to work with them too. So I've added logic to use the tags file if LSP didn't return any symbol.

weilbith commented 2 years ago

Hey. I'm very sorry for the incredible long delay.

First of all, I would like to ask you to just return nil for this case and do not work on the tags yourself. It is just not necessary as NeoVim will do it itself when nil gets returned. Atm it doesn't work as you expect because it returns an empty list. Second I'm thinking if this can be tweaked/configured. I'm not 100% sure if this is always the intended behavior. Especially because it will always trigger an actual tag search when the language server(s) provide no location (which can be correct). So I wonder if it would be more precise to check if the necessary location providers are available. If it does and the response is empty, accept that. If not, go ahead and use tags. Do you think this would help here? In worst case you could explicitly setup your language client so it disabled certain location provider you know of that they don't work properly. If that should not be possible, I would at least add a configuration variable to enable the fallback to tags. So the current behavior remains as it for all users and everyone like you can configure it the way you need it.

Looking forward to your feedback.

nabaco commented 1 year ago

Fixed the return value, it indeed works as expected that way. I'm not sure what you mean by "check the location provider" - can you elaborate on that please? I will look into adding an option for opting into this behaviour.

nabaco commented 1 year ago

Added a global option for my change. Did some further testing and I noticed that when I don't have compile_commands.json clangd returns incorrect locations for tags instead of an empty list, so my change doesn't really help here. But when I turn off the LSP client (:LspStop) then my change kicks in and works perfectly. Though maybe in such cases we need to check if there are any LSP Clients attached to the buffer, and if not return nil? Is that what you meant by "check the location provider"?

weilbith commented 1 year ago

Hey, sorry that I haven't responded. 🙈 I like the current state. Do you think we can merge it right now or would you like to add more due to your recent problem?

nabaco commented 1 year ago

I'm fine with merging now. If I'll have further fixes, I'll raise another PR.