-
-
Notifications
You must be signed in to change notification settings - Fork 297
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 textDocument/documentSymbol #347
Comments
I agree, this would be a convenient improvement 🙂 |
This feature is driven by the following LSP capability: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_documentSymbol Implementing this should unlock this feature for both vscode and other clients supporting this capability (nvim). |
I took a look at how to implement this. The feature is supposed to list useful stuff in the file - variables etc., and then you can navigate the file using those symbols. But at the moment, the types for templ's type HTMLTemplate struct {
+ Position Range
Expression Expression
Children []Node
} Then, populate it during parsing like this: var template = parse.Func(func(pi *parse.Input) (r HTMLTemplate, ok bool, err error) {
// templ FuncName(p Person, other Other) {
+ r.Position.From = NewPosition(int64(pi.Index()), uint32(pi.Position().Line), uint32(pi.Position().Col))
var te templateExpression
if te, ok, err = templateExpressionParser.Parse(pi); err != nil || !ok {
return
}
r.Expression = te.Expression
+ r.Position.To = NewPosition(int64(pi.Index()), uint32(pi.Position().Line), uint32(pi.Position().Col)) Next, the LSP proxy (in Finally, when DocumentSymbol is called, need to call the Go LSP first, then do the rest. Something like this. func (p *Server) DocumentSymbol(ctx context.Context, params *lsp.DocumentSymbolParams) (result []interface{} /* []SymbolInformation | []DocumentSymbol */, err error) {
p.Log.Info("client -> server: DocumentSymbol")
defer p.Log.Info("client -> server: DocumentSymbol end")
//TODO: Convert the templ URI to a Go URI.
//result, err = p.Target.DocumentSymbol(ctx, params)
//if err != nil {
//return
//}
//TODO: Rewrite the positions that came back, and remove any items that are not in the source map cache.
//TODO: Grab the symbol data from the `*Server` symbol cache, and populate the results.
result = append(result, lsp.SymbolInformation{
Name: "templ",
Kind: lsp.SymbolKindFunction,
Tags: []lsp.SymbolTag{},
Deprecated: false,
Location: lsp.Location{},
ContainerName: "",
})
result = append(result, lsp.SymbolInformation{
Name: "css",
Kind: lsp.SymbolKindFunction,
Tags: []lsp.SymbolTag{},
Deprecated: false,
Location: lsp.Location{},
ContainerName: "",
})
result = append(result, lsp.SymbolInformation{
Name: "script",
Kind: lsp.SymbolKindFunction,
Tags: []lsp.SymbolTag{},
Deprecated: false,
Location: lsp.Location{},
ContainerName: "",
})
return
} If someone wants to have a crack at it, let me know. With tests etc. it's probably a day's work. |
Hi, I am missing a feature of the symbol list(the 'Ctrl+Shift+O' menu) in your vscode extension. The result could look like this:
![image](https://private-user-images.githubusercontent.com/30555041/291701086-905f97da-79f6-4c85-ac56-0d4fcbd5bca5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyMzczNjYsIm5iZiI6MTczOTIzNzA2NiwicGF0aCI6Ii8zMDU1NTA0MS8yOTE3MDEwODYtOTA1Zjk3ZGEtNzlmNi00Yzg1LWFjNTYtMGQ0ZmNiZDViY2E1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjExVDAxMjQyNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTNmNjZhNWIwZjVhOTU2MWEwMjc5YWM5Y2VkZTk1OTI3YzlmMGJmNDQzOWIwNTQ5OTEwODM1MWMxNTc5YjUzZDImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.zXqP0EKG7PlLT4M2dRu7IOHNCxPl43IRwQZ3jjNkzo4)
It would only have to contain the top-level
templ
,css
,script
andtype
declarations.The text was updated successfully, but these errors were encountered: