Repository navigation
Fix UTF-16 positions in diagnostic ranges - #397
Open
dajiaohuang wants to merge 1 commit into
Open
dajiaohuang wants to merge 1 commit into
dajiaohuang wants to merge 1 commit into
Conversation
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.
Problem
Diagnostics currently use UTF-8 byte counts for LSP character positions. With the default UTF-16 position encoding, this puts underlines on the wrong characters after non-ASCII comments and can extend ranges past the end of a line.
For example, enable
keyword_forbidden_wire_regin.svlint.toml, initialize svls with the fixture directory asrootUriand working directory, then open:The stdio
textDocument/publishDiagnosticsresponse reports line 1, characters 15..19 forwire; the correct UTF-16 range is 11..15. A comment containing a non-BMP character has the same byte/code-unit mismatch.Change
Convert parser/linter byte offsets to UTF-16 columns. Convert both endpoints rather than adding byte lengths to a UTF-16 start column, including the parser-error range ending at the end of a line. Add regression tests for BMP/non-BMP comments, line transitions and Unicode range endpoints.
Validation
cargo install --path . --locked --root <isolated-install>cargo test --lockedandcargo test --release --locked: 2 tests passedgit diff --checkTested on Windows with rustc 1.98.1. Linux/macOS, GUI editor integrations and dynamic plugins were not tested.