From fccb908178905af3ba59e332e15324a2ae0d7601 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 8 Jun 2023 13:23:03 +0100 Subject: [PATCH] Add `"access"` scope for python --- .../languages/python/clearAccessAir.yml | 28 ++++++ .../languages/python/clearAccessBat.yml | 28 ++++++ .../languages/python/clearAccessBat3.yml | 28 ++++++ .../languages/python/clearAccessBat5.yml | 30 +++++++ .../languages/python/clearAccessCap.yml | 28 ++++++ .../languages/python/clearAccessCap2.yml | 28 ++++++ .../languages/python/clearAccessCap3.yml | 28 ++++++ .../languages/python/clearAccessDrum.yml | 28 ++++++ .../languages/python/clearAccessDrum2.yml | 28 ++++++ .../languages/python/clearAccessEach.yml | 28 ++++++ .../languages/python/clearAccessEach2.yml | 28 ++++++ .../languages/python/clearAccessFine.yml | 28 ++++++ .../languages/python/clearEveryAccessAir.yml | 40 +++++++++ .../languages/python/takeEveryAccess.yml | 24 ++++++ .../languages/python/takeEveryAccessAir.yml | 34 ++++++++ .../languages/python/takeEveryAccessAir2.yml | 30 +++++++ .../languages/python/takeEveryAccessBat.yml | 34 ++++++++ .../languages/python/takeEveryAccessBat2.yml | 30 +++++++ .../languages/python/takeEveryAccessCap.yml | 34 ++++++++ .../languages/python/takeEveryAccessCap2.yml | 30 +++++++ .../languages/python/takeEveryAccessDrum.yml | 34 ++++++++ .../languages/python/takeEveryAccessDrum2.yml | 30 +++++++ .../languages/python/takeEveryAccessEach.yml | 34 ++++++++ .../languages/python/takeEveryAccessEach2.yml | 30 +++++++ queries/python.fieldAccess.scm | 85 +++++++++++++++++++ queries/python.scm | 2 + 26 files changed, 809 insertions(+) create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessAir.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessBat.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessBat3.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessBat5.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessCap.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessCap2.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessCap3.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessDrum.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessDrum2.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessEach.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessEach2.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessFine.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearEveryAccessAir.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccess.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessAir.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessAir2.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessBat.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessBat2.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessCap.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessCap2.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessDrum.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessDrum2.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessEach.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessEach2.yml create mode 100644 queries/python.fieldAccess.scm diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessAir.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessAir.yml new file mode 100644 index 0000000000..e438b890ce --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessAir.yml @@ -0,0 +1,28 @@ +languageId: python +command: + version: 5 + spokenForm: clear access air + action: {name: clearAndSetSelection} + targets: + - type: primitive + modifiers: + - type: containingScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: a} + usePrePhraseSnapshot: true +initialState: + documentContents: | + aaa().bbb.ccc().ddd + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.a: + start: {line: 0, character: 0} + end: {line: 0, character: 3} +finalState: + documentContents: | + .bbb.ccc().ddd + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessBat.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessBat.yml new file mode 100644 index 0000000000..000b0fd081 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessBat.yml @@ -0,0 +1,28 @@ +languageId: python +command: + version: 5 + spokenForm: clear access bat + action: {name: clearAndSetSelection} + targets: + - type: primitive + modifiers: + - type: containingScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: b} + usePrePhraseSnapshot: true +initialState: + documentContents: | + aaa().bbb.ccc().ddd + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.b: + start: {line: 0, character: 6} + end: {line: 0, character: 9} +finalState: + documentContents: | + aaa().ccc().ddd + selections: + - anchor: {line: 0, character: 5} + active: {line: 0, character: 5} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessBat3.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessBat3.yml new file mode 100644 index 0000000000..a4086b804a --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessBat3.yml @@ -0,0 +1,28 @@ +languageId: python +command: + version: 5 + spokenForm: clear access bat + action: {name: clearAndSetSelection} + targets: + - type: primitive + modifiers: + - type: containingScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: b} + usePrePhraseSnapshot: true +initialState: + documentContents: | + a[0].b[c.d] + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.b: + start: {line: 0, character: 5} + end: {line: 0, character: 6} +finalState: + documentContents: | + a[0] + selections: + - anchor: {line: 0, character: 4} + active: {line: 0, character: 4} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessBat5.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessBat5.yml new file mode 100644 index 0000000000..88458d0afa --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessBat5.yml @@ -0,0 +1,30 @@ +languageId: python +command: + version: 5 + spokenForm: clear access bat + action: {name: clearAndSetSelection} + targets: + - type: primitive + modifiers: + - type: containingScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: b} + usePrePhraseSnapshot: true +initialState: + documentContents: | + aaa.bbb( + ccc + 5 + ) + selections: + - anchor: {line: 3, character: 0} + active: {line: 3, character: 0} + marks: + default.b: + start: {line: 0, character: 4} + end: {line: 0, character: 7} +finalState: + documentContents: | + aaa + selections: + - anchor: {line: 0, character: 3} + active: {line: 0, character: 3} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessCap.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessCap.yml new file mode 100644 index 0000000000..2159dc0fb4 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessCap.yml @@ -0,0 +1,28 @@ +languageId: python +command: + version: 5 + spokenForm: clear access cap + action: {name: clearAndSetSelection} + targets: + - type: primitive + modifiers: + - type: containingScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: c} + usePrePhraseSnapshot: true +initialState: + documentContents: | + aaa().bbb.ccc().ddd + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.c: + start: {line: 0, character: 10} + end: {line: 0, character: 13} +finalState: + documentContents: | + aaa().bbb.ddd + selections: + - anchor: {line: 0, character: 9} + active: {line: 0, character: 9} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessCap2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessCap2.yml new file mode 100644 index 0000000000..6488f4d1b4 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessCap2.yml @@ -0,0 +1,28 @@ +languageId: python +command: + version: 5 + spokenForm: clear access cap + action: {name: clearAndSetSelection} + targets: + - type: primitive + modifiers: + - type: containingScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: c} + usePrePhraseSnapshot: true +initialState: + documentContents: | + aaa().bbb.ccc(eee.fff).ddd + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.c: + start: {line: 0, character: 10} + end: {line: 0, character: 13} +finalState: + documentContents: | + aaa().bbb.ddd + selections: + - anchor: {line: 0, character: 9} + active: {line: 0, character: 9} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessCap3.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessCap3.yml new file mode 100644 index 0000000000..3a686b2387 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessCap3.yml @@ -0,0 +1,28 @@ +languageId: python +command: + version: 5 + spokenForm: clear access cap + action: {name: clearAndSetSelection} + targets: + - type: primitive + modifiers: + - type: containingScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: c} + usePrePhraseSnapshot: true +initialState: + documentContents: | + a[0].b[c.d()] + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.c: + start: {line: 0, character: 7} + end: {line: 0, character: 8} +finalState: + documentContents: | + a[0].b[.d()] + selections: + - anchor: {line: 0, character: 7} + active: {line: 0, character: 7} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessDrum.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessDrum.yml new file mode 100644 index 0000000000..ae00c1d430 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessDrum.yml @@ -0,0 +1,28 @@ +languageId: python +command: + version: 5 + spokenForm: clear access drum + action: {name: clearAndSetSelection} + targets: + - type: primitive + modifiers: + - type: containingScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: d} + usePrePhraseSnapshot: true +initialState: + documentContents: | + aaa().bbb.ccc().ddd + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.d: + start: {line: 0, character: 16} + end: {line: 0, character: 19} +finalState: + documentContents: | + aaa().bbb.ccc() + selections: + - anchor: {line: 0, character: 15} + active: {line: 0, character: 15} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessDrum2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessDrum2.yml new file mode 100644 index 0000000000..60cd1d3cd9 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessDrum2.yml @@ -0,0 +1,28 @@ +languageId: python +command: + version: 5 + spokenForm: clear access drum + action: {name: clearAndSetSelection} + targets: + - type: primitive + modifiers: + - type: containingScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: d} + usePrePhraseSnapshot: true +initialState: + documentContents: | + a[0].b[c.d()] + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.d: + start: {line: 0, character: 9} + end: {line: 0, character: 10} +finalState: + documentContents: | + a[0].b[c] + selections: + - anchor: {line: 0, character: 8} + active: {line: 0, character: 8} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessEach.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessEach.yml new file mode 100644 index 0000000000..97ae12c48b --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessEach.yml @@ -0,0 +1,28 @@ +languageId: python +command: + version: 5 + spokenForm: clear access each + action: {name: clearAndSetSelection} + targets: + - type: primitive + modifiers: + - type: containingScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: e} + usePrePhraseSnapshot: true +initialState: + documentContents: | + aaa().bbb.ccc(eee).ddd + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.e: + start: {line: 0, character: 14} + end: {line: 0, character: 17} +finalState: + documentContents: | + aaa().bbb.ddd + selections: + - anchor: {line: 0, character: 9} + active: {line: 0, character: 9} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessEach2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessEach2.yml new file mode 100644 index 0000000000..42bb1743c1 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessEach2.yml @@ -0,0 +1,28 @@ +languageId: python +command: + version: 5 + spokenForm: clear access each + action: {name: clearAndSetSelection} + targets: + - type: primitive + modifiers: + - type: containingScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: e} + usePrePhraseSnapshot: true +initialState: + documentContents: | + aaa().bbb.ccc(eee.fff).ddd + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.e: + start: {line: 0, character: 14} + end: {line: 0, character: 17} +finalState: + documentContents: | + aaa().bbb.ccc(.fff).ddd + selections: + - anchor: {line: 0, character: 14} + active: {line: 0, character: 14} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessFine.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessFine.yml new file mode 100644 index 0000000000..61b554ac46 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearAccessFine.yml @@ -0,0 +1,28 @@ +languageId: python +command: + version: 5 + spokenForm: clear access fine + action: {name: clearAndSetSelection} + targets: + - type: primitive + modifiers: + - type: containingScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: f} + usePrePhraseSnapshot: true +initialState: + documentContents: | + aaa().bbb.ccc(eee.fff).ddd + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.f: + start: {line: 0, character: 18} + end: {line: 0, character: 21} +finalState: + documentContents: | + aaa().bbb.ccc(eee).ddd + selections: + - anchor: {line: 0, character: 17} + active: {line: 0, character: 17} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearEveryAccessAir.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearEveryAccessAir.yml new file mode 100644 index 0000000000..83d044559f --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/clearEveryAccessAir.yml @@ -0,0 +1,40 @@ +languageId: python +command: + version: 5 + spokenForm: clear every access air + action: {name: clearAndSetSelection} + targets: + - type: primitive + modifiers: + - type: everyScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: a} + usePrePhraseSnapshot: true +initialState: + documentContents: | + ( + aaa + .bbb + .ccc + ) + selections: + - anchor: {line: 5, character: 0} + active: {line: 5, character: 0} + marks: + default.a: + start: {line: 1, character: 4} + end: {line: 1, character: 7} +finalState: + documentContents: | + ( + + + + ) + selections: + - anchor: {line: 1, character: 4} + active: {line: 1, character: 4} + - anchor: {line: 2, character: 4} + active: {line: 2, character: 4} + - anchor: {line: 3, character: 4} + active: {line: 3, character: 4} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccess.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccess.yml new file mode 100644 index 0000000000..0bd0d631e2 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccess.yml @@ -0,0 +1,24 @@ +languageId: python +command: + version: 5 + spokenForm: take every access + action: {name: setSelection} + targets: + - type: primitive + modifiers: + - type: everyScope + scopeType: {type: fieldAccess} + usePrePhraseSnapshot: true +initialState: + documentContents: aaa.bbb() + ccc() + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + marks: {} +finalState: + documentContents: aaa.bbb() + ccc() + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 3} + - anchor: {line: 0, character: 3} + active: {line: 0, character: 9} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessAir.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessAir.yml new file mode 100644 index 0000000000..433d7cf596 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessAir.yml @@ -0,0 +1,34 @@ +languageId: python +command: + version: 5 + spokenForm: take every access air + action: {name: setSelection} + targets: + - type: primitive + modifiers: + - type: everyScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: a} + usePrePhraseSnapshot: true +initialState: + documentContents: | + a().b.c().d; + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.a: + start: {line: 0, character: 0} + end: {line: 0, character: 1} +finalState: + documentContents: | + a().b.c().d; + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 3} + - anchor: {line: 0, character: 3} + active: {line: 0, character: 5} + - anchor: {line: 0, character: 5} + active: {line: 0, character: 9} + - anchor: {line: 0, character: 9} + active: {line: 0, character: 11} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessAir2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessAir2.yml new file mode 100644 index 0000000000..70872b2a10 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessAir2.yml @@ -0,0 +1,30 @@ +languageId: python +command: + version: 5 + spokenForm: take every access air + action: {name: setSelection} + targets: + - type: primitive + modifiers: + - type: everyScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: a} + usePrePhraseSnapshot: true +initialState: + documentContents: | + a[0].b[1] + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.a: + start: {line: 0, character: 0} + end: {line: 0, character: 1} +finalState: + documentContents: | + a[0].b[1] + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 4} + - anchor: {line: 0, character: 4} + active: {line: 0, character: 9} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessBat.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessBat.yml new file mode 100644 index 0000000000..51e86523b4 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessBat.yml @@ -0,0 +1,34 @@ +languageId: python +command: + version: 5 + spokenForm: take every access bat + action: {name: setSelection} + targets: + - type: primitive + modifiers: + - type: everyScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: b} + usePrePhraseSnapshot: true +initialState: + documentContents: | + a().b.c().d; + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.b: + start: {line: 0, character: 4} + end: {line: 0, character: 5} +finalState: + documentContents: | + a().b.c().d; + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 3} + - anchor: {line: 0, character: 3} + active: {line: 0, character: 5} + - anchor: {line: 0, character: 5} + active: {line: 0, character: 9} + - anchor: {line: 0, character: 9} + active: {line: 0, character: 11} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessBat2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessBat2.yml new file mode 100644 index 0000000000..c257c97a63 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessBat2.yml @@ -0,0 +1,30 @@ +languageId: python +command: + version: 5 + spokenForm: take every access bat + action: {name: setSelection} + targets: + - type: primitive + modifiers: + - type: everyScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: b} + usePrePhraseSnapshot: true +initialState: + documentContents: | + a[0].b[1] + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.b: + start: {line: 0, character: 5} + end: {line: 0, character: 6} +finalState: + documentContents: | + a[0].b[1] + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 4} + - anchor: {line: 0, character: 4} + active: {line: 0, character: 9} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessCap.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessCap.yml new file mode 100644 index 0000000000..dbfab71949 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessCap.yml @@ -0,0 +1,34 @@ +languageId: python +command: + version: 5 + spokenForm: take every access cap + action: {name: setSelection} + targets: + - type: primitive + modifiers: + - type: everyScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: c} + usePrePhraseSnapshot: true +initialState: + documentContents: | + a().b.c().d; + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.c: + start: {line: 0, character: 6} + end: {line: 0, character: 7} +finalState: + documentContents: | + a().b.c().d; + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 3} + - anchor: {line: 0, character: 3} + active: {line: 0, character: 5} + - anchor: {line: 0, character: 5} + active: {line: 0, character: 9} + - anchor: {line: 0, character: 9} + active: {line: 0, character: 11} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessCap2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessCap2.yml new file mode 100644 index 0000000000..a87bf87227 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessCap2.yml @@ -0,0 +1,30 @@ +languageId: python +command: + version: 5 + spokenForm: take every access cap + action: {name: setSelection} + targets: + - type: primitive + modifiers: + - type: everyScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: c} + usePrePhraseSnapshot: true +initialState: + documentContents: | + a[0].b[c.d] + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.c: + start: {line: 0, character: 7} + end: {line: 0, character: 8} +finalState: + documentContents: | + a[0].b[c.d] + selections: + - anchor: {line: 0, character: 7} + active: {line: 0, character: 8} + - anchor: {line: 0, character: 8} + active: {line: 0, character: 10} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessDrum.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessDrum.yml new file mode 100644 index 0000000000..e3cae93aae --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessDrum.yml @@ -0,0 +1,34 @@ +languageId: python +command: + version: 5 + spokenForm: take every access drum + action: {name: setSelection} + targets: + - type: primitive + modifiers: + - type: everyScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: d} + usePrePhraseSnapshot: true +initialState: + documentContents: | + a().b.c().d; + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.d: + start: {line: 0, character: 10} + end: {line: 0, character: 11} +finalState: + documentContents: | + a().b.c().d; + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 3} + - anchor: {line: 0, character: 3} + active: {line: 0, character: 5} + - anchor: {line: 0, character: 5} + active: {line: 0, character: 9} + - anchor: {line: 0, character: 9} + active: {line: 0, character: 11} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessDrum2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessDrum2.yml new file mode 100644 index 0000000000..90bf4339a5 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessDrum2.yml @@ -0,0 +1,30 @@ +languageId: python +command: + version: 5 + spokenForm: take every access drum + action: {name: setSelection} + targets: + - type: primitive + modifiers: + - type: everyScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: d} + usePrePhraseSnapshot: true +initialState: + documentContents: | + a[0].b[c.d] + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.d: + start: {line: 0, character: 9} + end: {line: 0, character: 10} +finalState: + documentContents: | + a[0].b[c.d] + selections: + - anchor: {line: 0, character: 7} + active: {line: 0, character: 8} + - anchor: {line: 0, character: 8} + active: {line: 0, character: 10} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessEach.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessEach.yml new file mode 100644 index 0000000000..e015edffca --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessEach.yml @@ -0,0 +1,34 @@ +languageId: python +command: + version: 5 + spokenForm: take every access each + action: {name: setSelection} + targets: + - type: primitive + modifiers: + - type: everyScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: e} + usePrePhraseSnapshot: true +initialState: + documentContents: | + a().b.c(e).d; + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.e: + start: {line: 0, character: 8} + end: {line: 0, character: 9} +finalState: + documentContents: | + a().b.c(e).d; + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 3} + - anchor: {line: 0, character: 3} + active: {line: 0, character: 5} + - anchor: {line: 0, character: 5} + active: {line: 0, character: 10} + - anchor: {line: 0, character: 10} + active: {line: 0, character: 12} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessEach2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessEach2.yml new file mode 100644 index 0000000000..6ce1ee93b6 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeEveryAccessEach2.yml @@ -0,0 +1,30 @@ +languageId: python +command: + version: 5 + spokenForm: take every access each + action: {name: setSelection} + targets: + - type: primitive + modifiers: + - type: everyScope + scopeType: {type: fieldAccess} + mark: {type: decoratedSymbol, symbolColor: default, character: e} + usePrePhraseSnapshot: true +initialState: + documentContents: | + a().b.c(e.f).d; + selections: + - anchor: {line: 1, character: 0} + active: {line: 1, character: 0} + marks: + default.e: + start: {line: 0, character: 8} + end: {line: 0, character: 9} +finalState: + documentContents: | + a().b.c(e.f).d; + selections: + - anchor: {line: 0, character: 8} + active: {line: 0, character: 9} + - anchor: {line: 0, character: 9} + active: {line: 0, character: 11} diff --git a/queries/python.fieldAccess.scm b/queries/python.fieldAccess.scm new file mode 100644 index 0000000000..b6db35cf72 --- /dev/null +++ b/queries/python.fieldAccess.scm @@ -0,0 +1,85 @@ +;; foo.bar +;; ^^^ +( + (attribute + object: (_) @fieldAccess + ) + (#not-type? @fieldAccess call attribute subscript) +) + +;; foo().bar +;; ^^^^^ +( + (attribute + object: (call + function: (_) @dummy + ) @fieldAccess + ) + (#not-type? @dummy attribute) +) + +;; foo[0].bar +;; ^^^^^^ +( + (attribute + object: (subscript + value: (_) @dummy + ) @fieldAccess + ) + (#not-type? @dummy attribute) +) + +;; foo.bar +;; ^^^^ +( + (attribute + "." @fieldAccess.start + attribute: (_) @fieldAccess.end + ) @dummy + (#not-parent-type? @dummy call subscript) +) + +;; foo.bar() +;; ^^^^^^ +(call + function: (attribute + "." @fieldAccess.start + ) + arguments: (_) @fieldAccess.end +) + +;; foo.bar[0] +;; ^^^^^^^ +(subscript + value: (attribute + "." @fieldAccess.start + ) + "]" @fieldAccess.end +) + +;; foo[bar.baz] +;; ^^^^ +;; The reason we need this special treatment for subscript is that +;; the attribute inside the subscript of the subscript is a +;; direct child of the subscript, so will be ruled out by the +;; `foo.bar` pattern above. Note that this is not the case for `call`, +;; where the arguments get their own parent node, and are thus not direct children +;; of the call. +(subscript + subscript: (attribute + "." @fieldAccess.start + attribute: (_) @fieldAccess.end + ) +) + +;; Use the largest attribute, call, or subscript +;; in a chain of such ancestors as the iteration scope. +( + [(attribute) (call) (subscript)] @fieldAccess.iteration + (#not-parent-type? @fieldAccess.iteration attribute call subscript) +) + +;; Use the interior of the `[]` in a subscript as an iteration scope +(subscript + subscript: [(attribute) (call) (subscript)] @fieldAccess.iteration +) diff --git a/queries/python.scm b/queries/python.scm index 08c4b98bb9..6baeb6a3fe 100644 --- a/queries/python.scm +++ b/queries/python.scm @@ -1,3 +1,5 @@ +;; import python.fieldAccess.scm + ;; Generated by the following command: ;; > curl https://raw.githubusercontent.com/tree-sitter/tree-sitter-python/d6210ceab11e8d812d4ab59c07c81458ec6e5184/src/node-types.json \ ;; | jq '[.[] | select(.type == "_simple_statement" or .type == "_compound_statement") | .subtypes[].type]'