python: Add task for running modules (#26462)
Closes #26460 I am new to contributing to Zed (and pretty new to Rust in general). I'm not too familiar with code style, guidelines etc. so please feel free to suggest changes/improvements. This PR adds a run icon to Python files that have a "main" function: ```python if __name__ == "__main__": ... ``` In addition to the gutter icon, there is now also an extra task in the command palette "run module". Release Notes: - Added detection for runnable Python modules - Added Python-specific task to run a Python file as a module from inside the project's scope --------- Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
This commit is contained in:
parent
152432f1d9
commit
1574a3a2fd
2 changed files with 51 additions and 1 deletions
|
@ -82,3 +82,19 @@
|
|||
)
|
||||
)
|
||||
)
|
||||
|
||||
; module main method
|
||||
(
|
||||
(module
|
||||
(if_statement
|
||||
condition: (comparison_operator
|
||||
(identifier) @run @_lhs
|
||||
operators: "=="
|
||||
(string) @_rhs
|
||||
)
|
||||
(#eq? @_lhs "__name__")
|
||||
(#match? @_rhs "^[\"']__main__[\"']$")
|
||||
(#set! tag python-module-main-method)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue