Skip to content

Comments

feat(maker-cross-fil-types): ifacemaker type resolution across multi-file packages#112

Open
zdunecki wants to merge 4 commits intovburenin:masterfrom
zdunecki:feat/maker-cross-file-types
Open

feat(maker-cross-fil-types): ifacemaker type resolution across multi-file packages#112
zdunecki wants to merge 4 commits intovburenin:masterfrom
zdunecki:feat/maker-cross-file-types

Conversation

@zdunecki
Copy link

@zdunecki zdunecki commented Feb 12, 2026

Hi,

This PR allows to find embedded structs more deeply. For example if we import structs from two packages of same module and those have separted models and implementation in different files (__fixtures__/1.nested-modules/input).

Best,

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances ifacemaker's type resolution capability to discover embedded struct types across multiple files within the same package. Previously, ifacemaker only examined the explicitly provided input files, which caused issues when type declarations (like sqlc-generated models) were split across separate files from their method implementations. The solution scans all Go files in the same directories as the input files to build a complete picture of available types and embedding relationships.

Changes:

  • Modified Make() function to scan entire directories for type declarations and embedding graphs, not just explicitly provided files
  • Added fixture-based testing infrastructure with JSON configuration files
  • Introduced deduplication using a parsedFiles map to avoid processing the same file multiple times

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 5 comments.

File Description
maker/maker.go Core logic changes: added directory scanning, absolute path handling, and parseAndCollect closure to discover types across all Go files in same directories
ifacemaker_test.go New fixture-based testing infrastructure with fixtureConfig struct and TestFixtures function
go.mod / go.sum Added test dependencies (kr/pretty, rogpeppe/go-internal, check.v1)
fixtures/1.nested-modules/* Complete fixture demonstrating cross-file type resolution with pet store example spanning multiple packages

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

zdunecki and others added 3 commits February 13, 2026 00:49
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@gaby
Copy link
Collaborator

gaby commented Feb 13, 2026

@zdunecki The unit-tests are causing random failures related to the changes in maker.go

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +639 to +643
dir := filepath.Dir(absPath)
entries, err := os.ReadDir(dir)
if err != nil {
return []byte{}, err
}
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When multiple input files are in the same directory, this implementation will call os.ReadDir on that directory multiple times (once per input file in that directory). While the parsedFiles map prevents re-parsing the same file, the directory listing itself is repeated unnecessarily. Consider collecting unique directories first, or caching directory listings to reduce redundant filesystem operations.

Copilot uses AI. Check for mistakes.
Comment on lines +592 to +598
absPath := f
if !filepath.IsAbs(absPath) {
if p, err := filepath.Abs(absPath); err != nil {
log.Printf("maker: failed to convert %q to absolute path: %v", absPath, err)
} else {
absPath = p
}
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file deduplication using parsedFiles map may not work correctly if the same physical file is referenced through different paths (e.g., relative vs absolute, or through symlinks). Consider normalizing all paths to absolute paths before using them as map keys, and handle the error case where filepath.Abs fails more robustly (e.g., by returning an error rather than just logging and continuing with a potentially non-normalized path).

Copilot uses AI. Check for mistakes.
@zdunecki
Copy link
Author

@gaby I'll look what's going on with failures soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants