Skip to content

Commit

Permalink
fix(go_indexer): detect top-level when using file-level scopes (#5817)
Browse files Browse the repository at this point in the history
  • Loading branch information
schroederc committed Aug 29, 2023
1 parent 2566e9c commit afdcec6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions kythe/go/indexer/BUILD
Expand Up @@ -69,6 +69,7 @@ go_indexer_test(
has_marked_source = True,
import_path = "builtin",
resolve_code_facts = True,
use_file_as_top_level_scope = True,
)

go_indexer_test(
Expand Down
2 changes: 1 addition & 1 deletion kythe/go/indexer/emit.go
Expand Up @@ -1224,7 +1224,7 @@ func (e *emitter) writeBinding(id *ast.Ident, kind string, parent *spb.VName) *s
return nil
}
target := e.pi.ObjectVName(obj)
if e.pi.ImportPath == "builtin" && parent != nil && parent.GetSignature() == "package" {
if e.pi.ImportPath == "builtin" && parent != nil && (parent.GetSignature() == "package" || parent.GetSignature() == "") {
// Special-case top-level builtin bindings: https://pkg.go.dev/builtin
target = govname.Builtin(id.String())
kind = "tbuiltin"
Expand Down
3 changes: 3 additions & 0 deletions kythe/go/indexer/testdata/builtin.go
@@ -1,9 +1,12 @@
package builtin

//- _? defines/binding BoolBuiltin
//- BoolBuiltin=vname("bool#builtin", "golang.org", "", "", "go").node/kind tbuiltin
//- BoolBuiltin.code/rendered/signature "bool"
//- _? defines/binding IntBuiltin
//- IntBuiltin=vname("int#builtin", "golang.org", "", "", "go").node/kind tbuiltin
//- IntBuiltin.code/rendered/signature "int"

//- _? defines/binding ErrorBuiltin
//- ErrorBuiltin=vname("error#builtin", "golang.org", "", "", "go").node/kind tbuiltin
//- ErrorBuiltin.code/rendered/signature "error"

0 comments on commit afdcec6

Please sign in to comment.