Skip to content

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

Open
pixel365 wants to merge 4 commits into
baz-scm:mainfrom
pixel365:spans
Open

feat!: expose byte spans for module paths and versions#46
pixel365 wants to merge 4 commits into
baz-scm:mainfrom
pixel365:spans

Conversation

@pixel365

Copy link
Copy Markdown

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

Generated description

Expose byte-range Span locations while parsing module paths and versions through GoMod, Module, and ModuleReplacement, enabling language-server diagnostics and tooling to map dependencies to source text. Preserve path/version-based equality and provide constructors that initialize empty spans for manually built values.

Topics
TopicDetails
API compatibility Preserve existing equality behavior and update constructors, documentation, and tests for the new public span fields and breaking struct construction changes.
Modified files (2)
  • README.md
  • src/lib.rs
Latest Contributors(0)
UserCommitDate
Dependency positions Expose source byte spans for module directives, dependencies, exclusions, and replacements, including nested replacement modules and optional versions, while parsing through LocatingSlice.
Modified files (4)
  • README.md
  • src/lib.rs
  • src/parser.rs
  • tests/parse.rs
Latest Contributors(0)
UserCommitDate

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
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.

1 participant