Skip to content

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
Copy link

Diff from mypy_primer, showing the effect of this PR on open source code:

openlibrary (https://github.com/internetarchive/openlibrary)
+ ERROR openlibrary/plugins/openlibrary/lists.py:811:43-813:18: Cannot set item in `dict[str, list[dict[Unknown, Unknown]]]` [unsupported-operation]
+ ERROR openlibrary/plugins/openlibrary/lists.py:818:40-88: Cannot set item in `dict[str, list[dict[Unknown, Unknown]]]` [unsupported-operation]
+ ERROR openlibrary/plugins/openlibrary/lists.py:823:42-825:18: Cannot set item in `dict[str, list[dict[Unknown, Unknown]]]` [unsupported-operation]
+ ERROR openlibrary/plugins/upstream/tests/test_merge_authors.py:142:12-52: Object of class `NoneType` has no attribute `key` [missing-attribute]
+ ::error file=openlibrary/plugins/openlibrary/lists.py,line=811,col=43,endLine=813,endColumn=18,title=Pyrefly unsupported-operation::Cannot set item in `dict[str, list[dict[Unknown, Unknown]]]`%0A  Argument `list[Thing | Unknown]` is not assignable to parameter `value` with type `list[dict[Unknown, Unknown]]` in function `dict.__setitem__`
+ ::error file=openlibrary/plugins/openlibrary/lists.py,line=818,col=40,endLine=818,endColumn=88,title=Pyrefly unsupported-operation::Cannot set item in `dict[str, list[dict[Unknown, Unknown]]]`%0A  Argument `list[Thing | Unknown]` is not assignable to parameter `value` with type `list[dict[Unknown, Unknown]]` in function `dict.__setitem__`
+ ::error file=openlibrary/plugins/openlibrary/lists.py,line=823,col=42,endLine=825,endColumn=18,title=Pyrefly unsupported-operation::Cannot set item in `dict[str, list[dict[Unknown, Unknown]]]`%0A  Argument `list[Thing | Unknown]` is not assignable to parameter `value` with type `list[dict[Unknown, Unknown]]` in function `dict.__setitem__`
- ::error file=openlibrary/plugins/upstream/tests/test_merge_authors.py,line=37,col=9,endLine=37,endColumn=12,title=Pyrefly bad-override::Class member `MockSite.get` overrides parent class `Site` in an inconsistent manner%0A  `MockSite.get` has type `BoundMethod[MockSite, (self: MockSite, key: Unknown) -> Unknown]`, which is not assignable to `BoundMethod[MockSite, (self: MockSite, key: Unknown, revision: Unknown | None = None, lazy: bool | Unknown = False) -> Unknown | None]`, the type of `Site.get`
+ ::error file=openlibrary/plugins/upstream/tests/test_merge_authors.py,line=37,col=9,endLine=37,endColumn=12,title=Pyrefly bad-override::Class member `MockSite.get` overrides parent class `Site` in an inconsistent manner%0A  `MockSite.get` has type `BoundMethod[MockSite, (self: MockSite, key: Unknown) -> Thing | Unknown]`, which is not assignable to `BoundMethod[MockSite, (self: MockSite, key: Unknown, revision: Unknown | None = None, lazy: bool | Unknown = False) -> Thing | Unknown | None]`, the type of `Site.get`
+ ::error file=openlibrary/plugins/upstream/tests/test_merge_authors.py,line=142,col=12,endLine=142,endColumn=52,title=Pyrefly missing-attribute::Object of class `NoneType` has no attribute `key`

@asukaminato0721
Copy link
Contributor Author

image

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.

1 participant