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

add primitive document symbol support #848

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jackielii
Copy link
Contributor

@jackielii jackielii commented Jul 15, 2024

try to fix #347

Currently it deals with Go symbols + parser.HTMLTemplate

TODOs:

  1. deal with documentSymbol as well
  2. add other symbols (css, script)?
  3. add correct containerName?

@jackielii
Copy link
Contributor Author

jackielii commented Jul 15, 2024

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 parser.HTMLTemplate, making the result correct....

@joerdav
Copy link
Collaborator

joerdav commented Sep 3, 2024

Is this ready to be reviewed @jackielii ?

@joerdav
Copy link
Collaborator

joerdav commented Sep 3, 2024

I tested this on https://github.com/joerdav/shopping-list/blob/main/app/listsweb/list.templ

And I got the following symbols:

app/listsweb/list.templ|58 col 7| [Function] ListItems(list List, availableItems []Item)
app/listsweb/list.templ|96 col 7| [Function] ListPage(urlpath string, list List, availableRecipes []Recipe, availableItems []Item)
app/listsweb/list.templ|134 col 7| [Function] ListsPage(path string, lists []ListSummary)
app/listsweb/list.templ|18 col 7| [Function] ListRecipes( list List, availableRecipes []Recipe, )

I expected to also see the go functions there recipeInList and itemInList

@joerdav
Copy link
Collaborator

joerdav commented Sep 3, 2024

I spotted the TODO, oops! Thanks for the PR by the way, it's looking to be almost there!

@jackielii
Copy link
Contributor Author

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.

@a-h
Copy link
Owner

a-h commented Sep 3, 2024

Legend. 😀

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

Successfully merging this pull request may close these issues.

lsp: support textDocument/documentSymbol
3 participants