diff --git a/data/playground/python/statements.py b/data/playground/python/statements.py new file mode 100644 index 0000000000..d98c0b04af --- /dev/null +++ b/data/playground/python/statements.py @@ -0,0 +1,36 @@ +import sys + + +def statements(): + print(sys.path[0]) # comment 1 + print("hello") # comment 2 + + # the below statement has additional spaces after it + val = 1 == 2 + if val is True: + return + + # also the below has non-empty indentation + + c = range(10) + c.append(100) + x = 1 + x /= 2 + for i in range(10): + if i == 0: + continue + print(i) + break + + age = 120 + if age > 90: + print("You are too old to party, granny.") + elif age < 0: + print("You're yet to be born") + elif age >= 18: + print("You are allowed to party") + else: + print("You're too young to party") + + +statements() diff --git a/data/playground/python/strings.py b/data/playground/python/strings.py new file mode 100644 index 0000000000..98e07fd2b7 --- /dev/null +++ b/data/playground/python/strings.py @@ -0,0 +1,8 @@ +value = 3 + +a = "single quote string" +b = "double quote string" +c = """triple single quote string""" +d = """triple double quote string""" +e = r"literal string" +f = f"format string {value}" diff --git a/packages/cursorless-engine/src/languages/getTextFragmentExtractor.ts b/packages/cursorless-engine/src/languages/getTextFragmentExtractor.ts index 3e5ed7440a..07d9035a1b 100644 --- a/packages/cursorless-engine/src/languages/getTextFragmentExtractor.ts +++ b/packages/cursorless-engine/src/languages/getTextFragmentExtractor.ts @@ -159,7 +159,6 @@ const textFragmentExtractors: Record< "php", phpStringTextFragmentExtractor, ), - python: constructDefaultTextFragmentExtractor("python"), ruby: constructDefaultTextFragmentExtractor( "ruby", rubyStringTextFragmentExtractor, diff --git a/packages/cursorless-engine/src/languages/python.ts b/packages/cursorless-engine/src/languages/python.ts index d4d59d335f..d20bea22f5 100644 --- a/packages/cursorless-engine/src/languages/python.ts +++ b/packages/cursorless-engine/src/languages/python.ts @@ -45,7 +45,6 @@ function itemNodeFinder( const nodeMatchers: Partial< Record > = { - string: "string", collectionItem: cascadingMatcher( matcher( itemNodeFinder("import_from_statement", "dotted_name", true), @@ -61,7 +60,6 @@ const nodeMatchers: Partial< anonymousFunction: "lambda?.lambda", functionCall: "call", functionCallee: "call[function]", - comment: "comment", condition: cascadingMatcher( conditionMatcher("*[condition]"), diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeString2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeString2.yml new file mode 100644 index 0000000000..5255d44a5d --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeString2.yml @@ -0,0 +1,24 @@ +languageId: python +command: + version: 1 + spokenForm: take string + action: setSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: string} +spokenFormError: Scope type 'string' +initialState: + documentContents: | + + value = """hello world""" + selections: + - anchor: {line: 1, character: 17} + active: {line: 1, character: 17} + marks: {} +finalState: + documentContents: | + + value = """hello world""" + selections: + - anchor: {line: 1, character: 8} + active: {line: 1, character: 25} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeString3.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeString3.yml new file mode 100644 index 0000000000..2e95571eea --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeString3.yml @@ -0,0 +1,24 @@ +languageId: python +command: + version: 1 + spokenForm: take string + action: setSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: string} +spokenFormError: Scope type 'string' +initialState: + documentContents: | + + value = r"hello world" + selections: + - anchor: {line: 1, character: 16} + active: {line: 1, character: 16} + marks: {} +finalState: + documentContents: | + + value = r"hello world" + selections: + - anchor: {line: 1, character: 8} + active: {line: 1, character: 22} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeString4.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeString4.yml new file mode 100644 index 0000000000..d562f3523a --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/python/takeString4.yml @@ -0,0 +1,26 @@ +languageId: python +command: + version: 1 + spokenForm: take string + action: setSelection + targets: + - type: primitive + modifier: {type: containingScope, scopeType: string} +spokenFormError: Scope type 'string' +initialState: + documentContents: | + + w = "world" + value = f"hello {w}" + selections: + - anchor: {line: 2, character: 16} + active: {line: 2, character: 16} + marks: {} +finalState: + documentContents: | + + w = "world" + value = f"hello {w}" + selections: + - anchor: {line: 2, character: 8} + active: {line: 2, character: 20} diff --git a/queries/python.scm b/queries/python.scm index 8cb243b4cf..7566194e9a 100644 --- a/queries/python.scm +++ b/queries/python.scm @@ -27,6 +27,13 @@ (with_statement) ] @statement +(comment) @comment @textFragment + +(string + _ @textFragment.start.endOf + _ @textFragment.end.startOf +) @string + [ (dictionary) (dictionary_comprehension)