feat!: expose byte spans for module paths and versions - #46
Open
pixel365 wants to merge 4 commits into
Open
Conversation
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.
|
| Topic | Details | |||
|---|---|---|---|---|
| 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)
Latest Contributors(0)
| |||
| 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)
Latest Contributors(0)
|
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Parse with a locating stream so every module path and version keeps the byte offset range it was read from.
ModuleandModuleReplacementnow carrypath_spanandversion_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::newandModuleReplacement::newbuild values with empty spans for that case.BREAKING CHANGE:
ModuleandModuleReplacementgained public span fields, so they can no longer be built with a struct literal or matched with an exhaustive pattern without them. UseModule::new/ModuleReplacement::new, or add..to the pattern.