-
-
Notifications
You must be signed in to change notification settings - Fork 88
Improve condition
support for Python and Rust
#1147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pokey
merged 13 commits into
main
from
pokey/rust-support-if-component-of-case-statements
Dec 22, 2022
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0253e9e
[rust] Support `if` component of `case` statements
pokey f3a8ea4
Merge branch 'main' into pokey/rust-support-if-component-of-case-stat…
pokey 2c6d0dd
Change Rust impl to use `condition`
pokey cea34e0
Support `condition` for match / comprehensions
pokey f8e2059
Support `condition` for Python ternaries
pokey 191ba52
Fixed test
pokey 0768150
Fix CI
pokey 982c156
Merge branch 'main' into pokey/rust-support-if-component-of-case-stat…
AndreasArvidsson 1dec556
Merge branch 'main' into pokey/rust-support-if-component-of-case-stat…
pokey 8e58569
Improve condition support
pokey 7ea824c
Add `includeUnnamedChildren` flag to `childRangeSelector`
pokey 68e020a
Support condition in older tree-sitter-rust
pokey b2c1474
Merge branch 'main' into pokey/rust-support-if-component-of-case-stat…
pokey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/test/suite/fixtures/recorded/languages/python/clearCondition.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
languageId: python | ||
command: | ||
spokenForm: clear condition | ||
version: 3 | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: condition} | ||
usePrePhraseSnapshot: true | ||
action: {name: clearAndSetSelection} | ||
initialState: | ||
documentContents: aaa if bbb else ccc | ||
selections: | ||
- anchor: {line: 0, character: 16} | ||
active: {line: 0, character: 16} | ||
marks: {} | ||
finalState: | ||
documentContents: aaa if else ccc | ||
selections: | ||
- anchor: {line: 0, character: 7} | ||
active: {line: 0, character: 7} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: condition}}]}] |
23 changes: 23 additions & 0 deletions
23
src/test/suite/fixtures/recorded/languages/python/clearCondition2.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
languageId: python | ||
command: | ||
spokenForm: clear condition | ||
version: 3 | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: condition} | ||
usePrePhraseSnapshot: true | ||
action: {name: clearAndSetSelection} | ||
initialState: | ||
documentContents: "[aaa for aaa in bbb if ccc]" | ||
selections: | ||
- anchor: {line: 0, character: 1} | ||
active: {line: 0, character: 1} | ||
marks: {} | ||
finalState: | ||
documentContents: "[aaa for aaa in bbb if ]" | ||
selections: | ||
- anchor: {line: 0, character: 23} | ||
active: {line: 0, character: 23} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: condition}}]}] |
23 changes: 23 additions & 0 deletions
23
src/test/suite/fixtures/recorded/languages/python/clearCondition3.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
languageId: python | ||
command: | ||
spokenForm: clear condition | ||
version: 3 | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: condition} | ||
usePrePhraseSnapshot: true | ||
action: {name: clearAndSetSelection} | ||
initialState: | ||
documentContents: (aaa for aaa in bbb if ccc) | ||
selections: | ||
- anchor: {line: 0, character: 1} | ||
active: {line: 0, character: 1} | ||
marks: {} | ||
finalState: | ||
documentContents: (aaa for aaa in bbb if ) | ||
selections: | ||
- anchor: {line: 0, character: 23} | ||
active: {line: 0, character: 23} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: condition}}]}] |
23 changes: 23 additions & 0 deletions
23
src/test/suite/fixtures/recorded/languages/python/clearCondition4.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
languageId: python | ||
command: | ||
spokenForm: clear condition | ||
version: 3 | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: condition} | ||
usePrePhraseSnapshot: false | ||
action: {name: clearAndSetSelection} | ||
initialState: | ||
documentContents: "{aaa for aaa in bbb if ccc}" | ||
selections: | ||
- anchor: {line: 0, character: 1} | ||
active: {line: 0, character: 1} | ||
marks: {} | ||
finalState: | ||
documentContents: "{aaa for aaa in bbb if }" | ||
selections: | ||
- anchor: {line: 0, character: 23} | ||
active: {line: 0, character: 23} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: condition}}]}] |
23 changes: 23 additions & 0 deletions
23
src/test/suite/fixtures/recorded/languages/python/clearCondition5.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
languageId: python | ||
command: | ||
spokenForm: clear condition | ||
version: 3 | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: condition} | ||
usePrePhraseSnapshot: false | ||
action: {name: clearAndSetSelection} | ||
initialState: | ||
documentContents: "{aaa: aaa for aaa in bbb if ccc}" | ||
selections: | ||
- anchor: {line: 0, character: 1} | ||
active: {line: 0, character: 1} | ||
marks: {} | ||
finalState: | ||
documentContents: "{aaa: aaa for aaa in bbb if }" | ||
selections: | ||
- anchor: {line: 0, character: 28} | ||
active: {line: 0, character: 28} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: condition}}]}] |
29 changes: 29 additions & 0 deletions
29
src/test/suite/fixtures/recorded/languages/python/clearCondition6.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
languageId: python | ||
command: | ||
spokenForm: clear condition | ||
version: 3 | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: condition} | ||
usePrePhraseSnapshot: true | ||
action: {name: clearAndSetSelection} | ||
initialState: | ||
documentContents: |- | ||
match 0: | ||
case a if a > 1: | ||
pass | ||
selections: | ||
- anchor: {line: 2, character: 8} | ||
active: {line: 2, character: 8} | ||
marks: {} | ||
finalState: | ||
documentContents: |- | ||
match 0: | ||
case a if : | ||
pass | ||
selections: | ||
- anchor: {line: 1, character: 14} | ||
active: {line: 1, character: 14} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: condition}}]}] |
23 changes: 23 additions & 0 deletions
23
src/test/suite/fixtures/recorded/languages/python/ditchCondition.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
languageId: python | ||
command: | ||
spokenForm: ditch condition | ||
version: 3 | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: condition} | ||
usePrePhraseSnapshot: true | ||
action: {name: remove} | ||
initialState: | ||
documentContents: "[aaa for aaa in bbb if ccc]" | ||
selections: | ||
- anchor: {line: 0, character: 1} | ||
active: {line: 0, character: 1} | ||
marks: {} | ||
finalState: | ||
documentContents: "[aaa for aaa in bbb ]" | ||
selections: | ||
- anchor: {line: 0, character: 1} | ||
active: {line: 0, character: 1} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: condition}}]}] |
29 changes: 29 additions & 0 deletions
29
src/test/suite/fixtures/recorded/languages/python/ditchCondition2.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
languageId: python | ||
command: | ||
spokenForm: ditch condition | ||
version: 3 | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: condition} | ||
usePrePhraseSnapshot: true | ||
action: {name: remove} | ||
initialState: | ||
documentContents: |- | ||
match 0: | ||
case a if a > 1: | ||
pass | ||
selections: | ||
- anchor: {line: 2, character: 8} | ||
active: {line: 2, character: 8} | ||
marks: {} | ||
finalState: | ||
documentContents: |- | ||
match 0: | ||
case a : | ||
pass | ||
selections: | ||
- anchor: {line: 2, character: 8} | ||
active: {line: 2, character: 8} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: condition}}]}] |
31 changes: 31 additions & 0 deletions
31
src/test/suite/fixtures/recorded/languages/rust/chuckCondition.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
languageId: rust | ||
command: | ||
spokenForm: chuck condition | ||
version: 2 | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: condition} | ||
usePrePhraseSnapshot: true | ||
action: {name: remove} | ||
initialState: | ||
documentContents: | | ||
match user { | ||
User { first_name: "John" } => {}, | ||
User { first_name } if first_name.starts_with("P") => {} | ||
} | ||
selections: | ||
- anchor: {line: 2, character: 27} | ||
active: {line: 2, character: 54} | ||
marks: {} | ||
finalState: | ||
documentContents: | | ||
match user { | ||
User { first_name: "John" } => {}, | ||
User { first_name } => {} | ||
} | ||
selections: | ||
- anchor: {line: 2, character: 23} | ||
active: {line: 2, character: 23} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: ifStatement}}]}] |
31 changes: 31 additions & 0 deletions
31
src/test/suite/fixtures/recorded/languages/rust/clearCondition.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
languageId: rust | ||
command: | ||
spokenForm: clear condition | ||
version: 3 | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: condition} | ||
usePrePhraseSnapshot: true | ||
action: {name: clearAndSetSelection} | ||
initialState: | ||
documentContents: |- | ||
match user { | ||
User { first_name: "John" } => {}, | ||
User { first_name } if first_name.starts_with("P") => {} | ||
} | ||
selections: | ||
- anchor: {line: 2, character: 57} | ||
active: {line: 2, character: 57} | ||
marks: {} | ||
finalState: | ||
documentContents: |- | ||
match user { | ||
User { first_name: "John" } => {}, | ||
User { first_name } if => {} | ||
} | ||
selections: | ||
- anchor: {line: 2, character: 25} | ||
active: {line: 2, character: 25} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: condition}}]}] |
33 changes: 33 additions & 0 deletions
33
src/test/suite/fixtures/recorded/languages/rust/clearCondition2.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
languageId: rust | ||
command: | ||
version: 3 | ||
spokenForm: clear condition | ||
action: {name: clearAndSetSelection} | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: condition} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: |- | ||
if n < 0 { | ||
print!("{} is negative", n); | ||
} else if n > 0 { | ||
print!("{} is positive", n); | ||
} | ||
selections: | ||
- anchor: {line: 1, character: 2} | ||
active: {line: 1, character: 2} | ||
marks: {} | ||
finalState: | ||
documentContents: |- | ||
if { | ||
print!("{} is negative", n); | ||
} else if n > 0 { | ||
print!("{} is positive", n); | ||
} | ||
selections: | ||
- anchor: {line: 0, character: 3} | ||
active: {line: 0, character: 3} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: condition}}]}] |
33 changes: 33 additions & 0 deletions
33
src/test/suite/fixtures/recorded/languages/rust/clearCondition3.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
languageId: rust | ||
command: | ||
version: 3 | ||
spokenForm: clear condition | ||
action: {name: clearAndSetSelection} | ||
targets: | ||
- type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: condition} | ||
usePrePhraseSnapshot: false | ||
initialState: | ||
documentContents: |- | ||
if n < 0 { | ||
print!("{} is negative", n); | ||
} else if n > 0 { | ||
print!("{} is positive", n); | ||
} | ||
selections: | ||
- anchor: {line: 3, character: 2} | ||
active: {line: 3, character: 2} | ||
marks: {} | ||
finalState: | ||
documentContents: |- | ||
if n < 0 { | ||
print!("{} is negative", n); | ||
} else if { | ||
print!("{} is positive", n); | ||
} | ||
selections: | ||
- anchor: {line: 2, character: 10} | ||
active: {line: 2, character: 10} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: condition}}]}] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.