@@ -21,33 +21,47 @@ func ReadDefinition(ctx context.Context, client *lsp.Client, symbolName string)
2121 container := ""
2222
2323 // Skip symbols that we are not looking for. workspace/symbol may return
24- // a large number of fuzzy matches.
25- switch v := symbol .(type ) {
26- case * protocol.SymbolInformation :
27- // SymbolInformation results have richer data.
28- kind = fmt .Sprintf ("Kind: %s\n " , protocol .TableKindMap [v .Kind ])
29- if v .ContainerName != "" {
30- container = fmt .Sprintf ("Container Name: %s\n " , v .ContainerName )
24+ // a large number of fuzzy matches. This handles BaseSymbolInformation
25+ doesSymbolMatch := func (vKind protocol.SymbolKind , vContainerName string ) bool {
26+ thisName := symbol .GetName ()
27+
28+ kind = fmt .Sprintf ("Kind: %s\n " , protocol .TableKindMap [vKind ])
29+ if vContainerName != "" {
30+ container = fmt .Sprintf ("Container Name: %s\n " , vContainerName )
31+ }
32+
33+ if thisName == symbolName {
34+ return true
3135 }
3236
3337 // Handle different matching strategies based on the search term
3438 if strings .Contains (symbolName , "." ) {
35- // For qualified names like "Type.Method", require exact match
36- if symbol .GetName () != symbolName {
37- continue
39+ // For qualified names like "Type.Method", don't do fuzzy match
40+
41+ } else if vKind == protocol .Method {
42+ // For methods, only match if the method name matches exactly Type.symbolName or Type::symbolName or symbolName
43+ if strings .HasSuffix (thisName , "::" + symbolName ) || strings .HasSuffix (symbolName , "::" + thisName ) {
44+ return true
3845 }
39- } else {
40- // For unqualified names like "Method"
41- if v .Kind == protocol .Method {
42- // For methods, only match if the method name matches exactly Type.symbolName or Type::symbolName or symbolName
43- if ! strings .HasSuffix (symbol .GetName (), "::" + symbolName ) && ! strings .HasSuffix (symbol .GetName (), "." + symbolName ) && symbol .GetName () != symbolName {
44- continue
45- }
46- } else if symbol .GetName () != symbolName {
47- // For non-methods, exact match only
48- continue
46+
47+ if strings .HasSuffix (thisName , "." + symbolName ) || strings .HasSuffix (symbolName , "." + thisName ) {
48+ return true
4949 }
5050 }
51+
52+ return false
53+ }
54+
55+ switch v := symbol .(type ) {
56+ case * protocol.SymbolInformation :
57+ if ! doesSymbolMatch (v .Kind , v .ContainerName ) {
58+ continue
59+ }
60+
61+ case * protocol.WorkspaceSymbol :
62+ if ! doesSymbolMatch (v .Kind , v .ContainerName ) {
63+ continue
64+ }
5165 default :
5266 if symbol .GetName () != symbolName {
5367 continue
0 commit comments