Skip to content

feat!: expose byte spans for module paths and versions - #46

Merged
gruebel merged 5 commits into
baz-scm:mainfrom
pixel365:spans
Sep 12, 2026
Merged

gruebel merged 5 commits into
baz-scm:mainfrom
pixel365:spans

Conversation

@pixel365

Copy link
Copy Markdown
Contributor

Parse with a locating stream so every module path and version keeps the byte offset range it was read from. Module and ModuleReplacement now carry path_span and version_span, which makes the crate usable as a language server backend: diagnostics, inlay hints and code actions can map a dependency back to its exact position in the file.

Spans are ignored by PartialEq, so existing comparisons keep working unchanged; only struct-literal construction and exhaustive destructuring break. Module::new and ModuleReplacement::new build values with empty spans for that case.

BREAKING CHANGE: Module and ModuleReplacement gained public span fields, so they can no longer be built with a struct literal or matched with an exhaustive pattern without them. Use Module::new / ModuleReplacement::new, or add .. to the pattern.

Parse with a locating stream so every module path and version keeps the
byte offset range it was read from. `Module` and `ModuleReplacement` now
carry `path_span` and `version_span`, which makes the crate usable as a
language server backend: diagnostics, inlay hints and code actions can
map a dependency back to its exact position in the file.

Spans are ignored by `PartialEq`, so existing comparisons keep working
unchanged; only struct-literal construction and exhaustive destructuring
break. `Module::new` and `ModuleReplacement::new` build values with empty
spans for that case.

BREAKING CHANGE: `Module` and `ModuleReplacement` gained public span
fields, so they can no longer be built with a struct literal or matched
with an exhaustive pattern without them. Use `Module::new` /
`ModuleReplacement::new`, or add `..` to the pattern.
@baz-reviewer

baz-reviewer Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Baz Summary

Expose byte-range Span metadata for parsed module paths and versions, including module directives, dependencies, and replacements. Update the locating parser and public GoMod, Module, and ModuleReplacement components to preserve positions while keeping spans out of equality and providing constructors for spanless values.

Topics

TopicDetails
API Compatibility Preserve existing value-based comparisons and provide Module::new and ModuleReplacement::new for constructing values without source locations, while documenting the breaking API additions.
Modified files (2)
  • README.md
  • src/lib.rs
Latest Contributors(0)
UserCommitDate
Source Positions Add byte spans to module directives, require/exclude dependencies, and both sides of replacements so language-server features can map parsed values to source text.
Modified files (4)
  • README.md
  • src/lib.rs
  • src/parser.rs
  • tests/parse.rs
Latest Contributors(0)
UserCommitDate

Activate Merger to get a short verdict whether this PR is good to go or not

  • Your agent works better with a plan - try Planner

Review this PR on Baz

Customize your next review

Comment thread README.md
Comment thread src/parser.rs Outdated
Address review feedback: capture the top-level module path with
with_span() and expose it as GoMod::module_span, so the module
declaration can be targeted the same way as dependencies. PartialEq for
GoMod ignores the new field, consistent with Module.

Also document the replace-side spans and both constructors in the README.
Comment thread src/parser.rs
Comment thread src/lib.rs
The module directive was parsed with take_till(1.., CRLF), so anything
after the path — an end-of-line comment or trailing spaces — ended up in
GoMod::module and, since the previous commit, in GoMod::module_span. A
language server would then highlight the comment as part of the module
path.

Tokenize the path with take_till(1.., WHITESPACES) and consume the rest
of the line separately, mirroring how the require, tool and ignore
parsers already do it. Note that space0 before the optional comment is
required: without it `module example.com/m   ` fails to parse, because
the next directive lookahead stops on the leading space.

As a side effect an end-of-line comment on the module directive is now
discarded instead of being appended to the path, which is the existing
behaviour for require, tool and ignore.
@baz-reviewer baz-reviewer Bot added the baz approved Baz-reviewer has approved this PR label Aug 27, 2026

@gruebel gruebel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@pixel365 thanks for the contribution, looks pretty solid 🍻

@gruebel
gruebel merged commit 74d8b89 into baz-scm:main Sep 12, 2026
9 checks passed
@pixel365
pixel365 deleted the spans branch September 12, 2026 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

baz approved Baz-reviewer has approved this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants