Skip to content

Commit a6ddf16

Browse files
committed
server: provide list all symbols in package
1 parent 8f46625 commit a6ddf16

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

pkg/analyzer/package.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ func (p *Package) SymbolByChar(chr string) []*CompletionItem {
5050
return append(p.Functions.Match(chr), result...)
5151
}
5252

53+
func (p *Package) AllSymbols() []*CompletionItem {
54+
out := make([]*CompletionItem, 0, p.Values.Len()+p.Functions.Len())
55+
out = append(out, p.Functions.Symbols...)
56+
out = append(out, p.Values.Symbols...)
57+
return out
58+
}
59+
5360
func (p *Package) GetCompletionItem() *CompletionItem {
5461
return &CompletionItem{
5562
Label: p.Name,

pkg/analyzer/sym_index.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ type SymbolIndex struct {
66
charMap map[string][]*CompletionItem
77
}
88

9+
func (si *SymbolIndex) Len() int {
10+
return len(si.Symbols)
11+
}
12+
913
func emptySymbolIndex() SymbolIndex {
1014
return SymbolIndex{
1115
Symbols: []*CompletionItem{},

pkg/langserver/server.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ func (s *Service) lookupBuiltin(val string) (*SuggestionsResponse, error) {
8383
}
8484

8585
func (s *Service) provideSuggestion(req SuggestionRequest) (*SuggestionsResponse, error) {
86-
if req.Value == "" {
87-
return nil, fmt.Errorf("empty suggestion request value, nothing to provide")
88-
}
89-
9086
// Provide package suggestions (if requested)
9187
if req.PackageName != "" {
9288
pkg, ok := s.index.PackageByName(req.PackageName)
@@ -98,11 +94,22 @@ func (s *Service) provideSuggestion(req SuggestionRequest) (*SuggestionsResponse
9894
return nil, fmt.Errorf("failed to analyze package %q: %s", req.PackageName, err)
9995
}
10096

97+
var symbols []*analyzer.CompletionItem
98+
if req.Value != "" {
99+
symbols = pkg.SymbolByChar(req.Value)
100+
} else {
101+
symbols = pkg.AllSymbols()
102+
}
103+
101104
return &SuggestionsResponse{
102-
Suggestions: pkg.SymbolByChar(req.Value),
105+
Suggestions: symbols,
103106
}, nil
104107
}
105108

109+
if req.Value == "" {
110+
return nil, fmt.Errorf("empty suggestion request value, nothing to provide")
111+
}
112+
106113
return s.lookupBuiltin(req.Value)
107114
}
108115

0 commit comments

Comments
 (0)