Skip to content

basic support for cython based on tree sitter#2231

Closed
asukaminato0721 wants to merge 5 commits intofacebook:mainfrom
asukaminato0721:cython-test
Closed

basic support for cython based on tree sitter#2231
asukaminato0721 wants to merge 5 commits intofacebook:mainfrom
asukaminato0721:cython-test

Conversation

@asukaminato0721
Copy link
Contributor

@asukaminato0721 asukaminato0721 commented Jan 26, 2026

Summary

a test of #2097 , in case someone want to try it out :)

syntax highlight, error diagnose, auto completion.

Test Plan

add related test.

@meta-cla meta-cla bot added the cla signed label Jan 26, 2026
@asukaminato0721 asukaminato0721 changed the title basic highlight support for cython. basic support for cython based on tree sitter Jan 26, 2026
@github-actions

This comment has been minimized.

@asukaminato0721
Copy link
Contributor Author

image

@asukaminato0721 asukaminato0721 marked this pull request as ready for review January 26, 2026 17:09
Copilot AI review requested due to automatic review settings January 26, 2026 17:09
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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::ParseError with a "Cython parse error" header.
  • Add a cython module that uses tree-sitter-cython to build a lightweight symbol index and provide attribute and keyword completions for .pyx/.pxd/.pxi files, wired into the LSP completion path.
  • Update the VS Code extension to register a cython language 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.

@github-actions

This comment has been minimized.

@asukaminato0721
Copy link
Contributor Author

image

@github-actions

This comment has been minimized.

@github-actions
Copy link

github-actions bot commented Feb 5, 2026

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@connernilsen
Copy link
Contributor

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants