-
-
Notifications
You must be signed in to change notification settings - Fork 225
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
lsp: Support goToDefinition from a Go file to a templ file #387
Comments
Yes, that would be much more useful! If you're in a templ/cmd/templ/lspcmd/proxy/server.go Lines 507 to 512 in c674f64
But currently, if you start from a It may also possible for the templ LSP to capture |
I know you can have multiple LSPs attached to a file, but I wonder what would happen if you had 2 trying to respond to a jump to definition request. |
I asked the gopls maintainers. Maybe they know a hook which templ could implement: golang/go#65001 |
We have the following issue to implement the line directive #415, and then I think it's a case of closing this ticket and helping the gopls team implement golang/go#65001 |
@joerdav thank you for your work! This is great! |
Thank @af-md ! |
Here's a quick and dirty fix for anyone using neovim. It doesn't go directly to the location of the definition in the file, but at least it opens the correct file. local go_to_definition = function()
if vim.bo.filetype == "go" then
vim.lsp.buf.definition({
on_list = function(options)
if options == nil or options.items == nil or #options.items == 0 then
return
end
local targetFile = options.items[1].filename
local prefix = string.match(targetFile, "(.-)_templ%.go$")
if prefix then
options.items[1].filename = prefix .. ".templ"
end
vim.fn.setqflist({}, ' ', options)
vim.api.nvim_command('cfirst')
end
})
else
vim.lsp.buf.definition()
end
end and then in your key map vim.keymap.set("n", "gd", go_to_definition) Note that the check for being in a go buffer will run every time you try to go to definition. You probably would want to add this modification only if you are using templ a lot and should remember to remove it once the actual fix is implemented. |
If I ctrl-click on
page()
then ...then I get to the autogenerated Go code:
It would be great if I could get to the templ-file instead:
The text was updated successfully, but these errors were encountered: