Skip to content

Add offset value to ParseToken #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shiro
Copy link

@shiro shiro commented Mar 18, 2025

Description

Adds an offset value to parsed tokens for easier post-processing by being able to find the strings in the source text.

I plan to integrate this into https://github.com/shikijs/shiki/blob/f8ef446af3f5f3910131b692e0c81ce032754ffa/packages/core/src/highlight/code-to-tokens-ansi.ts#L62 once it gets merged.

Changes

  • adds offset to ParseToken
  • updates readme
  • adds some comments that the TS LSP can show on "quick definition" popups in most IDEs

Copy link
Owner

@blake-mealey blake-mealey left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Added a comment

src/parser.ts Outdated
@@ -172,6 +178,7 @@ export function createAnsiSequenceParser() {
foreground,
background,
decorations: new Set(decorations),
offset: position,
Copy link
Owner

Choose a reason for hiding this comment

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

This will be the position of the current parse call, but not the beginning of the full input if it is being parsed in chunks. I think the offset should be maintained at the parser level

@blake-mealey
Copy link
Owner

Also please add some tests

@shiro shiro force-pushed the feature/add-offset-value branch from 40a3062 to 7b61c1f Compare March 24, 2025 03:49
@shiro shiro force-pushed the feature/add-offset-value branch from 7b61c1f to cb67ea6 Compare March 24, 2025 05:51
@shiro
Copy link
Author

shiro commented Mar 24, 2025

I think the offset should be maintained at the parser level

Agreed, updated the code.

Also please add some tests

Added a chunk test and updated other test snapshots, let me know if it's sufficient.

@shiro shiro requested a review from blake-mealey March 24, 2025 05:53
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