-
-
Notifications
You must be signed in to change notification settings - Fork 286
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
bug: go to definition causes error in Neovim v0.10.x #893
Comments
I'm still using Neovim v0.9.5. I'll have to try out Neovim v0.10.1 and see if I get the same issue. I spotted some emojis in the text. Does the problem go away if there are no emojis? Emojis are multi-byte characters, so they cause a lot of "fun". The reason I ask is that LSP positions were recently updated in the LSP spec: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocuments to now support UTF-8 encoding positions. I did a bit of work on positions in May (#712) around multi-byte characters throwing off LSP positions, so there's some good tests in there around it. It could be that the LSP code in Neovim is now trying to do some sort of negotiation as to what position to use, and is getting confused about text position, since it works fine in Neovim v0.9.5. The fix might be to populate the correct parts of the LSP client / server neogitation to tell Neovim to use UTF-8 for positions (I think that's what VS Code does). If you feel like having a crack at solving the issue... I'd start by enabling logging in the editor, see https://templ.guide/commands-and-tools/ide-support#enable-lsp-logging - that way, you can see exactly what is being sent to the LSP. There's even a web server which shows you the mapping between the input templ file and the generated code etc. However, the issue might also be in Neovim's LSP code. |
First of all, thank you for your feedback. Unfortunately, downgrading to 0.9.5 or deleting the emojis has not helped so far. |
Well, it's good to rule things out. If you are able to create the smallest possible reproduction repo, that would be useful. Then I can try to load the repo on my setup, and see if I can reproduce it. It could also be an issue in some other plugins that you're running. Here's my setup and scripts in case something jumps out at you: https://github.com/a-h/dotfiles/blob/master/.config/nixpkgs/nvim.nix The issue with Neovim config is that people have loads of stuff running. So, starting from a minimal config and building up can also help with identifying where the issue is coming from. |
So, this is what I have right now.
Unfortunately, still the same problem. Honestly, I don't know what else to try! |
I noticed this issue this morning, and have been doing some digging, I think there is an off-by-2 due to: // Code generated by templ - DO NOT EDIT.
package templ
//lint:file-ignore SA4006 This context is only used if a nested component is present.
import "github.com/a-h/templ" in neovim i can see the go file starts // Code generated by templ - DO NOT EDIT.
// templ: version: v0.2.747
package templ
//lint:file-ignore SA4006 This context is only used if a nested component is present.
import "github.com/a-h/templ" we seem to be missing the blank line and the version line (lines 2 and 3) in the lsps understanding EDIT; that said, behaviour persists with |
Thanks for investigating. If you enable the templ LSP web server, you can look at the mapping between templ files and the Go code that's being used by the LSP. There's even a side-by-side view of templ code to Go code, with highlighting when you mouseover go code. |
Thanks @a-h yes, the webview looks perfect, so either its a neovim bug, or the lsp is passing something that neovim isn't expecting This comes from this code here: here is the content of the { {
["end"] = <1>{
character = 10,
line = 4
},
location = {
range = {
["end"] = <table 1>,
start = <2>{
character = 6,
line = 4
}
},
uri = "file:///home/tris/code/fileclass/templ/Home.templ"
},
start = <table 2>
}, {
["end"] = <3>{
character = 40,
line = 106
},
location = {
range = {
["end"] = <table 3>,
start = <4>{
character = 36,
line = 106
}
},
uri = "file:///home/tris/code/fileclass/templ/Home.templ"
},
start = <table 4>
} } Line 106 is out of range in Home.templ, and isn't relevant in the generated go file either, so its something to do with the way that neovim is mapping the line/uri references I think. I will take another look after lunch Additionally from the templ lsp log the mapping looks correct
so something is getting messed up in the translation into neovim |
scratch that, the issue is if your templ definition is on line 5. which is common with a single import, minimal reproduction: package templ
import "fmt"
templ Hello(name string) {
{ fmt.Sprintf("Hello %s", name) }
} even wierder, this works package templ
import "fmt"
//this works
templ Hello(name string) {
{ fmt.Sprintf("Hello %s", name) }
}
even more minimal reproduction package templ
//comment1
//comment2
templ Hello(name string) {
<h1>Hello, { name }!</h1>
} why does templ lsp hate line 5? |
Interesting. Maybe it's a result of the recent change to auto-fixup imports. Maybe the line is getting removed. |
We have a good reproduction of a similar issue (maybe even the same?) in #911 |
The problem disappeared with the nightly version! |
Description
When using the "Go to Definition" feature in Neovim with templ components, an error occurs specifically for the
@atoms.Input
component. This error doesn't happen for other components or when the file containing theInput
component is already open. Importantly, this issue does not occur in Visual Studio Code, suggesting it might be specific to the Neovim integration.Code Example
WaitlistForm component:
Input component:
Error Message
When trying to use "Go to Definition" on
@atoms.Input
, the following error occurs:Environment
Additional Information
@atoms.Input
component in Neovim.Input
component is already open in Neovim.Expected Behavior
"Go to Definition" should successfully navigate to the definition of the
Input
component without throwing an error, as it does in Visual Studio Code.Questions
Any insights or suggestions for troubleshooting would be greatly appreciated. Thank you for your time and effort in addressing this issue.
The text was updated successfully, but these errors were encountered: