Refactor lexer logic#209
Merged
6cdh merged 6 commits intojeapostrophe:masterfrom Apr 14, 2026
Merged
Conversation
When the text range is empty (start = end), ignore the item.
- Make lexer lazy, only runs when needed - Use a sorted vector to store tokens - Fix the document symbol off by one bug API changes: - Remove doc-get-symbols - Remove doc-guess-token - Add doc-token-at which returns token at given positon - Add doc-token-prefix-at which retuns token prefix before given position
Collaborator
Author
|
The Resyntax CI failed because of a upstream problem: sorawee/pretty-expressive#5 EDIT: fixed |
dannypsnl
approved these changes
Apr 14, 2026
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.
This is the first PR of hover enhancement: #206 I guess I need 4 PRs in total for this better hover plan.
This PR:
start = end(empty range), means the identifier is not found in the source file, but exists in expanded syntax. The old behavior added it by giving a 1 length range. It no longer adds this type of items now.doc-hoverfunction.doclib/lexer.rkt, add a thread safe lazy cache abstraction for it.Docstruct now has a field to store a lazy cache of lexer snapshot. The lexer snapshot resets after each edit, and only runs in query functions when needed. So it's lazy. And it's safe as the lazy abstraction is semaphore-protected.doc-get-symbolsanddoc-guess-tokenAPI because they have inappropriate design.doc-get-symbolsreturn an interval map of symbol tokens, which is a full data. A good design should provide query-based interface, not return full data.doc-guess-tokenhas weird edge behavior not matching its name, and also too complex to describe in a sentence.doc-token-atAPI which really return token at the given position, or false if no token exists at the position.doc-token-prefix-atAPI which return the token content at the given position, but only the part before the given position.document-symbollogic. It's because the lexer returns 1-based indexed data. But all other places expect 0-based indexed data. It will make document-symbol slightly more useful. This bug won't appear because all lexer logic is at a single place now.For the lexer, each pass does a full tokenize process and store all tokens into a sorted vector. Each pass takes ~2ms for
doclib/doc.rkt. At most one pass runs if no more edits.I also explored other options for lexer:
data/interval-mapbecause it's almost 30x slower than build a sorted vector.