Skip to content

Conversation

@AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented May 29, 2025

Summary

Two Parser structs in the ty_test crate have offset() and skip_whitespace methods that are identical in their implementations. These methods feel like they could live just as well on the ruff_python_trivia crate's Cursor struct, which would reduce code duplication. (Edit: following code review, this PR now only adds the offset method to the Cursor struct.)

The short-term motivation for doing this is that I found myself needing them yet again for another parsing task in #18057 -- but it seems like a reasonable thing to do anyway, so I'm splitting it out into a standalone PR.

Test Plan

cargo test -p ty_test

@AlexWaygood AlexWaygood added the internal An internal refactor or improvement label May 29, 2025
@github-actions
Copy link
Contributor

github-actions bot commented May 29, 2025

mypy_primer results

No ecosystem changes detected ✅

@github-actions
Copy link
Contributor

github-actions bot commented May 29, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@AlexWaygood AlexWaygood changed the title Move common parsing methods to the Cursor struct Add offset method to ruff_python_trivia::Cursor' May 29, 2025
@AlexWaygood AlexWaygood changed the title Add offset method to ruff_python_trivia::Cursor' Add offset method to ruff_python_trivia::Cursor May 29, 2025
@AlexWaygood AlexWaygood requested a review from MichaReiser May 29, 2025 14:46
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

ty

@AlexWaygood AlexWaygood merged commit 7df79cf into main May 29, 2025
35 checks passed
@AlexWaygood AlexWaygood deleted the alex/common-cursor-methods branch May 29, 2025 15:08
dcreager added a commit that referenced this pull request May 29, 2025
* main:
  Add `offset` method to `ruff_python_trivia::Cursor` (#18371)
  ty_ide: improve completions by using scopes
  ruff_python_parser: add `Tokens::before` method
  [ty] Split `Type::KnownInstance` into two type variants (#18350)
  Bump 0.11.12 (#18369)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal An internal refactor or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants