Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Add Python runnable for `__name__ in ("__main__",)` pattern (#58911)

Torbjørn Lium6a37cc1173b3
diff --git a/crates/grammars/src/python/runnables.scm b/crates/grammars/src/python/runnables.scm
index 3480d4a8101..05c5abd34e7 100644
--- a/crates/grammars/src/python/runnables.scm
+++ b/crates/grammars/src/python/runnables.scm
@@ -106,3 +106,15 @@
(#eq? @_lhs "__name__")
(#match? @_rhs "^[\"']__main__[\"']$")
(#set! tag python-module-main-method)))
+
+; module main method (membership test variant)
+(module
+ (if_statement
+ condition: (comparison_operator
+ (identifier) @run @_lhs
+ operators: "in"
+ (tuple
+ (string) @_member
+ (#match? @_member "^[\"']__main__[\"']$")))
+ (#eq? @_lhs "__name__")
+ (#set! tag python-module-main-method)))