Skip to content

Commit 278f930

Browse files
UnboundVariableUnboundVariable
andauthored
[ty] First cut at semantic token provider (#19108)
This PR implements a basic semantic token provider for ty's language server. This allows for more accurate semantic highlighting / coloring within editors that support this LSP functionality. Here are screen shots that show how code appears in VS Code using the "rainbow" theme both before and after this change. ![461737617-15630625-d4a9-4ec5-9886-77b00eb7a41a](https://github.com/user-attachments/assets/f963b55b-3195-41d1-ba38-ac2e7508d5f5) ![461737624-d6dcf5f0-7b9b-47de-a410-e202c63e2058](https://github.com/user-attachments/assets/111ca2c5-bb4f-4c8a-a0b5-6c1b2b6f246b) The token types and modifier tags in this implementation largely mirror those used in Microsoft's default language server for Python. The implementation supports two LSP interfaces. The first provides semantic tokens for an entire document, and the second returns semantic tokens for a requested range within a document. The PR includes unit tests. It also includes comments that document known limitations and areas for future improvements. --------- Co-authored-by: UnboundVariable <[email protected]>
1 parent 4dd2c03 commit 278f930

File tree

13 files changed

+2221
-3
lines changed

13 files changed

+2221
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ty_ide/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ repository = { workspace = true }
1111
license = { workspace = true }
1212

1313
[dependencies]
14+
bitflags = { workspace = true }
1415
ruff_db = { workspace = true }
1516
ruff_python_ast = { workspace = true }
1617
ruff_python_parser = { workspace = true }

crates/ty_ide/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ mod goto;
55
mod hover;
66
mod inlay_hints;
77
mod markup;
8+
mod semantic_tokens;
89

910
pub use completion::completion;
1011
pub use db::Db;
1112
pub use goto::goto_type_definition;
1213
pub use hover::hover;
1314
pub use inlay_hints::inlay_hints;
1415
pub use markup::MarkupKind;
16+
pub use semantic_tokens::{
17+
SemanticToken, SemanticTokenModifier, SemanticTokenType, SemanticTokens, semantic_tokens,
18+
};
1519

1620
use ruff_db::files::{File, FileRange};
1721
use ruff_text_size::{Ranged, TextRange};

0 commit comments

Comments
 (0)