-
-
Notifications
You must be signed in to change notification settings - Fork 280
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
add primitive document symbol support #848
Conversation
1cdf23f
to
d198750
Compare
OK, I admit there is a big problem with my approach: I didn't convert the templ URI to the Go URI, yet somehow it worked. It seems gopls is good at parsing partial results and skip over invalid block, therefore all the non templ elements are all returned. I then parsed and added the templ elements, namely |
Is this ready to be reviewed @jackielii ? |
I tested this on https://github.com/joerdav/shopping-list/blob/main/app/listsweb/list.templ And I got the following symbols:
I expected to also see the go functions there |
I spotted the TODO, oops! Thanks for the PR by the way, it's looking to be almost there! |
I've been using it, works most of the time. But because it uses gopls to parse the templ files directly. It has quite a few broken cases. I'll redo it using the proper way by converting to go files and find mapping symbols. |
Legend. 😀 |
@a-h @joerdav I have implemented the said approach: use go source to find the symbols and map them back to templ source ranges. There are two issues I couldn't figure out:
doesn't map to the actual templ source. However, in the actual run, it returns the "DocumentSymbol" and range is correct.
This is my relevant nvim config just in case it's useful to others: {
"neovim/nvim-lspconfig",
init = function()
vim.filetype.add({ extension = { templ = "templ" } })
vim.api.nvim_create_autocmd("FileType", {
pattern = "templ",
callback = function()
vim.b.autoformat = true
-- vim.o.commentstring = "// %s"
end,
})
end,
opts = {
servers = {
htmx = {
filetypes = { "html", "templ" },
},
html = {
filetypes = { "html", "htm", "templ" },
-- filetypes = { "html", "htm" },
},
templ = {
cmd = { "/Users/jackieli/go/bin/templ", "lsp", "-log", "/tmp/templ.log" },
-- cmd = { "templ", "lsp" },
},
-- emmet_ls = {
-- filetypes = { "html", "htm", "htmx", "templ" },
-- },
},
setup = {
html = function(_, opts)
-- remove html documentSymbol and just use templ's document symbol
LazyVim.lsp.on_attach(function(client, buffer)
local ft = vim.api.nvim_get_option_value("filetype", { buf = buffer })
if ft == "templ" then
client.server_capabilities.documentSymbolProvider = false
end
end, "html")
end,
},
},
},
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution!! I've tested this out and it works exactly as I would expect it.
Thanks a lot for seeing this through to completion. Much appreciated. |
try to fix #347
Currently it deals with Go symbols + parser.HTMLTemplate
TODOs: