Debian Codegraph @

gopls/internal/golang/interactive.go

raw symbols SCIP
1 // Copyright 2026 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
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 // InteractiveWorkspaceSymbolEnumConfig defines the JSON configuration payload
19 // for an InteractiveListEnum request when the source is "workspaceSymbol".
20 // It is used to filter the search results to specific symbol types (e.g.,
21 // only Interfaces).
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 // Use FastFuzzy for low-latency interactive matching.
35 Matcher: settings.SymbolFastFuzzy,
36
37 // Use fully qualified names to ensure unique identification of
38 // the symbol. (i.e. "path/to/pkg.Iface")
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 }