Skip to content

Commit

Permalink
feat(python): Scope lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpovel committed Jul 30, 2024
1 parent 107d87f commit 94894c0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,7 @@ Language scopes:
decorator)
- with: `with` blocks (in their entirety)
- try: `try` blocks (in their entirety)
- lambda: `lambda` statements (in their entirety)

--python-query <PYTHON_QUERY>
Scope Python code using a custom tree-sitter query.
Expand Down
3 changes: 3 additions & 0 deletions src/scoping/langs/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub enum PreparedPythonQuery {
With,
/// `try` blocks (in their entirety).
Try,
/// `lambda` statements (in their entirety).
Lambda,
}

impl From<PreparedPythonQuery> for TSQuery {
Expand Down Expand Up @@ -149,6 +151,7 @@ impl From<PreparedPythonQuery> for TSQuery {
}
PreparedPythonQuery::With => "(with_statement) @with",
PreparedPythonQuery::Try => "(try_statement) @try",
PreparedPythonQuery::Lambda => "(lambda) @lambda",
},
)
.expect("Prepared queries to be valid")
Expand Down
5 changes: 5 additions & 0 deletions tests/langs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ impl InScopeLinePart {
include_str!("python/base.py"),
Python::new(CodeQuery::Prepared(PreparedPythonQuery::Try)),
)]
#[case(
"base.py_lambda",
include_str!("python/base.py"),
Python::new(CodeQuery::Prepared(PreparedPythonQuery::Lambda)),
)]
#[case(
"base.ts_strings",
include_str!("typescript/base.ts"),
Expand Down
7 changes: 7 additions & 0 deletions tests/langs/snapshots/r#mod__langs__base.py_lambda.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: tests/langs/mod.rs
expression: inscope_parts
---
- n: 82
l: "square = lambda x: x * x\n"
m: " ^^^^^^^^^^^^^^^ "

0 comments on commit 94894c0

Please sign in to comment.