basic support for cython based on tree sitter#2231
basic support for cython based on tree sitter#2231asukaminato0721 wants to merge 5 commits intofacebook:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR introduces initial Cython support to Pyrefly, including basic syntax highlighting, parse error diagnostics, and LSP completions for Cython files.
Changes:
- Extend the core parser pipeline to detect Cython modules by extension and use tree-sitter-cython to surface parse errors as
ErrorKind::ParseErrorwith a "Cython parse error" header. - Add a
cythonmodule that uses tree-sitter-cython to build a lightweight symbol index and provide attribute and keyword completions for.pyx/.pxd/.pxifiles, wired into the LSP completion path. - Update the VS Code extension to register a
cythonlanguage ID, TextMate grammar, and language configuration, and add tests covering Cython parse diagnostics and completion behavior.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
pyrefly/lib/test/util.rs |
Extends TestEnv::add_with_path to accept Cython-style extensions so tests can create .pyx/.pxd/.pxi in-memory modules. |
pyrefly/lib/test/lsp/diagnostic.rs |
Adds a test ensuring invalid Cython code in a .pyx file produces a ParseError diagnostic with the "Cython parse error" header. |
pyrefly/lib/test/lsp/completion.rs |
Adds tests validating Cython attribute completion for structs/extension types and generic Cython keyword completion. |
pyrefly/lib/state/steps.rs |
Updates the AST step to pass ModuleInfo into module_parse, enabling per-module decisions like Cython detection. |
pyrefly/lib/state/lsp.rs |
Short-circuits completion for Cython modules to use the new cython::completion_items while preserving comment-range suppression and existing completion sorting/deduplication. |
pyrefly/lib/module/parse.rs |
Changes module_parse to accept ModuleInfo, detect Cython modules, emit tree-sitter-based syntax errors, and otherwise defer to the existing Python parser. |
pyrefly/lib/lib.rs |
Registers the new cython module in the crate’s module tree. |
pyrefly/lib/cython.rs |
Implements Cython detection by filename, tree-sitter-based syntax error range collection, and a tree-sitter-backed index for providing attribute and keyword completion items. |
pyrefly/Cargo.toml |
Adds tree-sitter and tree-sitter-cython dependencies required by the new Cython support. |
lsp/syntaxes/cython.tmLanguage.json |
Adds a TextMate grammar for basic Cython syntax highlighting (comments, strings, numbers, decorators, Cython types/keywords, and Python keywords). |
lsp/src/extension.ts |
Extends the language client document selector to include cython for file, untitled, and in-memory schemes so the server runs on Cython documents. |
lsp/package.json |
Declares a cython language with Cython file extensions, associates it with the Cython grammar and language configuration, and activates the extension on onLanguage:cython. |
lsp/language-configuration/cython.json |
Adds VS Code language configuration for Cython (comments, brackets, auto-closing pairs, and folding). |
Cargo.lock |
Updates lockfile to include tree-sitter and tree-sitter-cython (and their transitive deps) and reflect minor dependency version bumps. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ac3bd38 to
d820aca
Compare
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
|
Hey Asuka, thanks for making this, it's really cool to see this as a proof of concept! We've decided we want to hold off on this until after V1, since we're not exactly sure how we want to handle this yet, and we'd rather focus on other priorities. I'm going to close this PR for now to remove it from our reviewer queue. Once we hit V1, we can come back to looking at this with more intent to land :) |


Summary
a test of #2097 , in case someone want to try it out :)
syntax highlight, error diagnose, auto completion.
Test Plan
add related test.