| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package golang |
| 6 |
|
| 7 |
import ( |
| 8 |
"context" |
| 9 |
"fmt" |
| 10 |
"slices" |
| 11 |
|
| 12 |
"golang.org/x/tools/gopls/internal/cache" |
| 13 |
"golang.org/x/tools/gopls/internal/cache/symbols" |
| 14 |
"golang.org/x/tools/gopls/internal/protocol" |
| 15 |
"golang.org/x/tools/gopls/internal/settings" |
| 16 |
) |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
type InteractiveWorkspaceSymbolEnumConfig struct { |
| 23 |
Kinds []protocol.SymbolKind |
| 24 |
} |
| 25 |
|
| 26 |
func ListWorkspaceSymbol(ctx context.Context, snapshots []*cache.Snapshot, param *protocol.InteractiveListEnumParams) ([]protocol.FormEnumEntry, error) { |
| 27 |
var config InteractiveWorkspaceSymbolEnumConfig |
| 28 |
if err := protocol.UnmarshalJSON(param.Config, &config); err != nil { |
| 29 |
return nil, fmt.Errorf("unmarshalling InteractiveListEnumParams.Config: %v", err) |
| 30 |
} |
| 31 |
|
| 32 |
symbols, err := WorkspaceSymbols(ctx, snapshots, param.Query, |
| 33 |
WorkspaceSymbolsOptions{ |
| 34 |
|
| 35 |
Matcher: settings.SymbolFastFuzzy, |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
Style: settings.FullyQualifiedSymbols, |
| 40 |
Filter: SymbolFilter(func(sym symbols.Symbol) bool { |
| 41 |
return slices.Contains(config.Kinds, sym.Kind) |
| 42 |
}), |
| 43 |
}, |
| 44 |
) |
| 45 |
if err != nil { |
| 46 |
return nil, err |
| 47 |
} |
| 48 |
|
| 49 |
entries := make([]protocol.FormEnumEntry, 0, len(symbols)) |
| 50 |
for _, s := range symbols { |
| 51 |
entries = append(entries, protocol.FormEnumEntry{ |
| 52 |
Value: s.Name, |
| 53 |
Description: fmt.Sprintf("[%s] %s", s.Kind, s.Name), |
| 54 |
}) |
| 55 |
} |
| 56 |
return entries, nil |
| 57 |
} |