[ty] First cut at semantic token provider#19108
[ty] First cut at semantic token provider#19108UnboundVariable merged 31 commits intoastral-sh:mainfrom
Conversation
|
CodSpeed WallTime Performance ReportMerging #19108 will not alter performanceComparing Summary
|
carljm
left a comment
There was a problem hiding this comment.
Thanks for the PR! I'd prefer for Micha or Dhruv (who know the LSP and our plans in that area better) to review this; just one initial comment.
dhruvmanila
left a comment
There was a problem hiding this comment.
This is a great start, thank you for doing this!
I've been reviewing this for an hour and I need to take a lunch break but here are my initial comments. I'll look at the remaining parts after the lunch break
There was a problem hiding this comment.
Ok, my review is finally done, this is an awesome PR!
The test cases are extremely thorough, thank you for writing them!
I think the only required change would be to make sure that we convert the ty location values back to the LSP values in the common function for the semantic tokens handler. And, around the visitor implementation where some of the calls that might lead to duplicate tokens could be removed.
A lot of my review comments could be considered as suggestions so feel free to either apply them or discard them. It's totally fine if those are done as follow-up. I can also own them as follow-up to this PR if you prefer.
…None` means "entire document".
…er than `Option<SemanticTokens>`.
…g `tokens` as a public field.
|
@dhruvmanila, thanks for the thorough and insightful code review comments! I think I've addressed them all. |
|
This can be done in a sepreate PR, but it would be great to add semantic highlighting to the playground too. It should be "as easy as" implementing the necessary provider and registering them here: ruff/playground/ty/src/Editor/Editor.tsx Lines 143 to 180 in a663796 |
|
I'll leave it up to you if this PR should close astral-sh/ty#260 |
…d the multilineTokenSupport capability of the client.
|
…c_tokens * 'main' of https://github.com/astral-sh/ruff: (27 commits) [ty] First cut at semantic token provider (astral-sh#19108) [`flake8-simplify`] Make example error out-of-the-box (`SIM116`) (astral-sh#19111) [`flake8-use-pathlib`] Make example error out-of-the-box (`PTH210`) (astral-sh#19189) [`flake8-use-pathlib`] Add autofixes for `PTH203`, `PTH204`, `PTH205` (astral-sh#18922) [`flake8-type-checking`] Fix syntax error introduced by fix (`TC008`) (astral-sh#19150) [`flake8-pyi`] Make example error out-of-the-box (`PYI007`, `PYI008`) (astral-sh#19103) Update Rust crate indicatif to 0.18.0 (astral-sh#19165) [ty] Add separate CI job for memory usage stats (astral-sh#19134) [ty] Add documentation for server traits (astral-sh#19137) Rename to `SessionSnapshot`, move unwind assertion closer (astral-sh#19177) [`flake8-type-checking`] Make example error out-of-the-box (`TC001`) (astral-sh#19151) [ty] Bare `ClassVar` annotations (astral-sh#15768) [ty] Re-enable multithreaded pydantic benchmark (astral-sh#19176) [ty] Implement equivalence for protocols with method members (astral-sh#18659) [ty] Use RHS inferred type for bare `Final` symbols (astral-sh#19142) [ty] Support declaration-only attributes (astral-sh#19048) [ty] Sync vendored typeshed stubs (astral-sh#19174) Update dependency pyodide to ^0.28.0 (astral-sh#19164) Update NPM Development dependencies (astral-sh#19170) Update taiki-e/install-action action to v2.56.7 (astral-sh#19169) ...
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.
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.