Skip to content

Read one plain source.Package after the load - #148

Merged
crhntr merged 1 commit into
mainfrom
split/3-source-package
Sep 16, 2026
Merged

crhntr merged 1 commit into
mainfrom
split/3-source-package

Conversation

@crhntr

@crhntr crhntr commented Sep 14, 2026

Copy link
Copy Markdown
Member

Adds internal/source, a plain-data source.Package, which internal/load hydrates from a command's configuration. muxt, generate and analysis read only that. Imports on source.Package is temporary; the next PR removes it.

Part 3 of 8, stacked on #147. Replaces #145.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UjkpA4fvZ7xQAsY65Beprp

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

internal/analysis/check.go has an unresolved moderate issue affecting definition source spans.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR introduces source.Package as a plain-data boundary and updates loading, generation, analysis, routing, and CLI wiring to use hydrated source data.

Changes:

  • Adds source models and hydration helpers.
  • Refactors Muxt, generation, and analysis to consume hydrated packages.
  • Updates tests, CLI wiring, and architecture documentation.
File summaries
File Summary
internal/source/source.go Defines plain source package, variable, definition, and call data.
internal/muxt/unmarshal.go Uses source package imports for type detection. Nit: group third-party imports before internal imports.
internal/muxt/name_error_test.go Adapts name-position testing.
internal/muxt/definition.go Resolves definitions from source variables.
internal/muxt/definition_test.go Updates definition tests.
internal/muxt/definition_internal_test.go Updates internal definition tests. Nit: separate third-party and internal imports.
internal/muxt/call.go Resolves calls from source.Package.
internal/muxt/call_test.go Updates call resolution tests. Nit: separate third-party and internal imports.
internal/muxt/call_internal_test.go Updates internal call tests.
internal/load/templates_test.go Tests source hydration and directory handling.
internal/load/source.go Hydrates loaded packages into source data.
internal/load/package.go Adds directory-based package lookup.
internal/load/hydrate.go Hydrates command-specific configurations.
internal/generate/validation_test.go Simplifies generator test setup.
internal/generate/template_route_path.go Reads encoding types from source imports.
internal/generate/routes.go Generates routes from source packages.
internal/generate/groups.go Groups source template variables.
internal/generate/file.go Stores source package data in generated files.
internal/generate/file_test.go Updates file and import tests.
internal/cli/commands.go Wires CLI commands through hydration.
internal/astgen/gen.go Simplifies the import manager interface.
internal/asteval/parse.go Uses typed function maps.
internal/analysis/template_calls.go Analyzes hydrated template calls.
internal/analysis/template_callers.go Analyzes hydrated template callers.
internal/analysis/routes.go Lists routes from source packages.
internal/analysis/check.go Checks hydrated template data. Moderate: newGlobal leaves check.Global.Definitions nil, discarding stored source spans.
CLAUDE.md Documents the new architecture.
Review details

Suppressed comments (2)

internal/muxt/definition_internal_test.go:12

  • Please add the blank line separating third-party imports from internal/... imports, as established by the neighboring Muxt tests. This newly added import currently leaves the two groups merged.
	"github.com/typelate/muxt/internal/source"

internal/muxt/unmarshal.go:13

  • Keep third-party imports together before the blank line for internal packages. This change places internal/source between github.com/typelate/dom and golang.org/x/net/html, unlike the established grouping in internal/generate/routes.go:17-22.
	"github.com/typelate/dom"
	"github.com/typelate/muxt/internal/source"
	"golang.org/x/net/html"
	"golang.org/x/net/html/atom"
  • Files reviewed: 27/27 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/analysis/check.go
Comment thread internal/muxt/call_test.go Outdated
@crhntr
crhntr force-pushed the split/2-generation-fixes branch from 9633986 to ec1fa6c Compare September 16, 2026 01:36
@crhntr
crhntr force-pushed the split/3-source-package branch from d59de39 to 38a38d8 Compare September 16, 2026 01:36
@crhntr
crhntr force-pushed the split/2-generation-fixes branch from ec1fa6c to e8aca9e Compare September 16, 2026 06:07
@crhntr
crhntr force-pushed the split/3-source-package branch from 38a38d8 to db40f24 Compare September 16, 2026 06:07
Base automatically changed from split/2-generation-fixes to main September 16, 2026 06:20
@crhntr
crhntr force-pushed the split/3-source-package branch from db40f24 to 52afbac Compare September 16, 2026 06:22
@crhntr
crhntr requested a lite review from Copilot September 16, 2026 06:23
Comment thread internal/cli/commands.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

Only minor import-grouping nits remain, with no blocking issues.

Review details

Suppressed comments (2)

internal/analysis/template_callers.go:14

  • Please keep the new internal import in the established import group: third-party imports are followed by a blank line before internal/... imports. The current block places internal/source directly after github.com/typelate/check, unlike the grouping used throughout the repository.
	"github.com/typelate/check"
	"github.com/typelate/muxt/internal/source"
)

internal/analysis/template_calls.go:14

  • Please keep the new internal import in the established import group: third-party imports are followed by a blank line before internal/... imports. The current block places internal/source directly after github.com/typelate/check, unlike the grouping used throughout the repository.
	"github.com/typelate/check"
	"github.com/typelate/muxt/internal/source"
)
  • Files reviewed: 27/27 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread internal/muxt/unmarshal.go
@crhntr
crhntr force-pushed the split/3-source-package branch 2 times, most recently from edb59b9 to 49552c3 Compare September 16, 2026 06:42
Every stage below the command line took []*packages.Package and dug
through it for what it needed: a *types.Package to find the templates
package's functions, a FileSet for positions, a search through the
imports for net/http or encoding, and check.Templates for the template
set, its definitions and the ExecuteTemplate calls on it. So nothing could
run without a module on disk and the go command.

internal/source now holds what they read, as plain data: a Package with
its FileSet, its types, the packages it imports by path, and its templates
variables. A Variable holds its template set, its functions, its
definitions by template name, and its ExecuteTemplate calls, each with a
position, the template name and the type of dot. No function fields, no
interfaces, nothing that needs a loader.

Imports, with Import and SearchImports, is how resolution finds net/http
and encoding for now; the next change replaces it with a checker and
removes it.

- load.Package reads a load into a source.Package, failing at the first
  variable that does not evaluate. load.GenerateSource and
  load.RoutesSource hydrate generate's and the route listing's
  configurations, and still report a missing package, then a missing
  receiver, before any variable. Reporting a variable's failure when it is
  loaded, rather than when a stage reaches it, only changes which error is
  reported when two variables fail differently, and that muxt check stops
  before checking any variable when one named after it fails to load.
  Packages are found by directory, so a directory named like a Go file
  still holds the package.

- muxt.Definitions takes a source.Variable and muxt.ResolveCall a
  source.Package, so muxt no longer links go/packages or typelate/check.

- generate.TemplateRoutesFiles takes the package and the receiver, and
  generate no longer links go/packages.

- analysis.Check and the template listings take the package, and build
  their check.Global from its data. The listings' configurations carry
  every templates variable, rather than being filled in once per loop
  pass.

The mutation run still reads load.Templates; a later change moves it.
Every generated file and report in the integration suite is unchanged.

Assisted-by: Claude:claude-opus-5 gofumpt
@crhntr
crhntr force-pushed the split/3-source-package branch from 49552c3 to 3b51c46 Compare September 16, 2026 06:58
@crhntr
crhntr merged commit ca9663b into main Sep 16, 2026
2 checks passed
@crhntr
crhntr deleted the split/3-source-package branch September 16, 2026 07:18
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