feat(lsp): add workspace symbol search
Assisted-by: MiMo V2.5 Pro
This commit is contained in:
@@ -452,6 +452,50 @@ func (s *Server) documentHighlights(p documentHighlightParams) []DocumentHighlig
|
||||
return out
|
||||
}
|
||||
|
||||
// workspaceSymbols searches all open documents for symbols matching the query.
|
||||
func (s *Server) workspaceSymbols(p workspaceSymbolParams) []WorkspaceSymbol {
|
||||
if p.Query == "" {
|
||||
return nil
|
||||
}
|
||||
query := strings.ToLower(p.Query)
|
||||
var out []WorkspaceSymbol
|
||||
for uri, text := range s.docs {
|
||||
f, _ := parser.Parse(uriPath(uri), text)
|
||||
if f == nil {
|
||||
continue
|
||||
}
|
||||
for _, d := range f.Decls {
|
||||
switch dd := d.(type) {
|
||||
case *ast.Text:
|
||||
if strings.Contains(strings.ToLower(dd.Name.Name), query) {
|
||||
out = append(out, WorkspaceSymbol{
|
||||
Name: dd.Name.Name,
|
||||
Kind: symFunction,
|
||||
Location: Location{URI: uri, Range: symRange(dd.Name)},
|
||||
})
|
||||
}
|
||||
case *ast.Globl:
|
||||
if dd.Name != nil && strings.Contains(strings.ToLower(dd.Name.Name), query) {
|
||||
out = append(out, WorkspaceSymbol{
|
||||
Name: dd.Name.Name,
|
||||
Kind: symConstant,
|
||||
Location: Location{URI: uri, Range: symRange(dd.Name)},
|
||||
})
|
||||
}
|
||||
case *ast.Data:
|
||||
if dd.Name != nil && strings.Contains(strings.ToLower(dd.Name.Name), query) {
|
||||
out = append(out, WorkspaceSymbol{
|
||||
Name: dd.Name.Name,
|
||||
Kind: symConstant,
|
||||
Location: Location{URI: uri, Range: symRange(dd.Name)},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// documentSymbols returns functions and their labels, plus global symbols.
|
||||
func (s *Server) documentSymbols(p documentSymbolParams) []DocumentSymbol {
|
||||
text := s.docs[p.TextDocument.URI]
|
||||
|
||||
Reference in New Issue
Block a user