Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

#### Symbols, tests and the viewer

- **Go methods now record whether they are exported.** A method on a Go type (`func (w *writer) Close()`) was always indexed as unexported, whatever the case of its name; only plain functions carried the flag. Both the native kernel and the WebAssembly path now apply Go's rule — an uppercase first letter — to methods too, so a tool asking "can another package call this?" gets the right answer. Re-index after upgrading.

- **Files under an `e2e/` directory count as tests.** Their calls no longer appear as production callers in Steps, dead-code and test badges.

- **Production code under a `samples` or `examples` package path is no longer treated as test code.** A Kotlin or Java project whose package path runs through `com/google/samples/…` (Now in Android, for one) had nearly every file counted as a fixture, so the Map opened on `build-logic`, the entry points hid the app, and dead-code and test badges were wrong. Only the project layout above a `src/` folder decides now; the package path below it never does.
Expand Down
23 changes: 23 additions & 0 deletions __tests__/extraction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11671,6 +11671,29 @@ describe('C/C++ kernel-port preParse blanks (R7a)', () => {
expect(blankLoneMacroLines(bare)).toBe(bare);
});

it('Go: a method carries the exportedness of its name, like a function', async () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'codegraph-go-method-exported-'));
try {
fs.writeFileSync(
path.join(dir, 'log.go'),
'package log\n\ntype writer struct{}\n\nfunc (w *writer) Close() error { return nil }\n\nfunc (w *writer) flush() {}\n\nfunc Open() *writer { return &writer{} }\n\nfunc helper() {}\n'
);
const cg = await CodeGraph.init(dir, { index: true });
try {
const flag = (name: string) =>
cg.getNodesByKind('method').concat(cg.getNodesByKind('function')).find((n) => n.name === name)!.isExported;
expect(flag('Close')).toBe(true);
expect(flag('flush')).toBe(false);
expect(flag('Open')).toBe(true);
expect(flag('helper')).toBe(false);
} finally {
cg.close();
}
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
});

it('blankCStatementMacroCalls blanks indented iterator macros, keeps the block', async () => {
const { blankCStatementMacroCalls } = await import('../src/extraction/languages/c-cpp');
const src = [
Expand Down
5 changes: 4 additions & 1 deletion codegraph-kernel/src/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,10 @@ impl<'t> Walker<'t> {
signature: self.signature_of(node),
return_type: self.return_type_of(node),
qualified_name: receiver_type.as_ref().map(|r| format!("{r}::{name}")),
..Extra::default() // extractMethod passes no isExported
// methodsAreTopLevel: a Go method is a top-level declaration, so
// extractMethod gives it the function's exportedness (name case).
is_exported: Some(self.is_exported(node)),
..Extra::default()
};
let Some(row) = self.create_node("method", &name, node, extra) else { return };

Expand Down
10 changes: 10 additions & 0 deletions src/extraction/tree-sitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1799,10 +1799,20 @@ export class TreeSitterExtractor {
const isAsync = this.extractor.isAsync?.(node);
const isStatic = this.extractor.isStatic?.(node);
const returnType = this.extractor.getReturnType?.(node, this.source);
// A method that is a top-level declaration (Go: `func (r *T) Name()`) has
// the same exportedness rule as a function — the name's case — and a
// consumer asking "can another package name this?" needs it on methods
// too. Class members keep the flag unset: their reachability is the
// class's, and the languages whose isExported walks the parent chain
// (JS/TS) would otherwise re-mark every member of an exported class.
const isExported = this.extractor.methodsAreTopLevel
? this.extractor.isExported?.(node, this.source)
: undefined;
const extraProps: Partial<Node> = {
docstring,
signature,
visibility,
isExported,
isAsync,
isStatic,
returnType,
Expand Down