From 99aa975c028d2c4bd7894b9b05f9b34b67c76add Mon Sep 17 00:00:00 2001 From: fidgetingbits Date: Thu, 1 Feb 2024 13:18:21 +0800 Subject: [PATCH 01/18] Re-adding lua changes after rebase with upstream/main --- data/playground/lua/lua.lua | 125 ++++++++ .../getLanguageScopeSupport.ts | 3 + packages/common/src/scopeSupportFacets/lua.ts | 11 + .../languages/lua/bringArgAirAfterBat.yml | 50 ++++ .../recorded/languages/lua/changeArg.yml | 29 ++ .../recorded/languages/lua/changeArg2.yml | 25 ++ .../recorded/languages/lua/changeBranch.yml | 36 +++ .../recorded/languages/lua/changeBranch2.yml | 36 +++ .../recorded/languages/lua/changeBranch3.yml | 36 +++ .../recorded/languages/lua/changeCall.yml | 25 ++ .../recorded/languages/lua/changeCallee.yml | 25 ++ .../languages/lua/changeCharInsideMap.yml | 33 +++ .../recorded/languages/lua/changeComment.yml | 25 ++ .../recorded/languages/lua/changeComment2.yml | 27 ++ .../languages/lua/changeCondition.yml | 23 ++ .../languages/lua/changeCondition2.yml | 33 +++ .../languages/lua/changeCondition3.yml | 33 +++ .../recorded/languages/lua/changeFunk.yml | 26 ++ .../recorded/languages/lua/changeFunkName.yml | 29 ++ .../recorded/languages/lua/changeIfState.yml | 30 ++ .../languages/lua/changeInsideBranchPit.yml | 42 +++ .../lua/changeInsideBranchQuench.yml | 42 +++ .../languages/lua/changeInsideBranchRed.yml | 42 +++ .../languages/lua/changeInsideFunk.yml | 34 +++ .../languages/lua/changeInsideLambda.yml | 37 +++ .../languages/lua/changeInsideList.yml | 26 ++ .../recorded/languages/lua/changeItem.yml | 23 ++ .../recorded/languages/lua/changeKey.yml | 41 +++ .../recorded/languages/lua/changeLambda.yml | 34 +++ .../recorded/languages/lua/changeList.yml | 41 +++ .../recorded/languages/lua/changeMap.yml | 23 ++ .../recorded/languages/lua/changeName.yml | 23 ++ .../recorded/languages/lua/changeName2.yml | 23 ++ .../recorded/languages/lua/changeRound.yml | 25 ++ .../recorded/languages/lua/changeState.yml | 25 ++ .../recorded/languages/lua/changeState2.yml | 37 +++ .../recorded/languages/lua/changeState3.yml | 34 +++ .../recorded/languages/lua/changeState4.yml | 37 +++ .../recorded/languages/lua/changeString.yml | 25 ++ .../recorded/languages/lua/changeValue.yml | 23 ++ .../recorded/languages/lua/changeValue2.yml | 38 +++ .../recorded/languages/lua/changeValue3.yml | 41 +++ .../recorded/languages/lua/changeValue4.yml | 34 +++ .../recorded/languages/lua/changeValue5.yml | 23 ++ .../recorded/languages/lua/chuckArg.yml | 37 +++ .../recorded/languages/lua/chuckArg2.yml | 37 +++ .../recorded/languages/lua/chuckItem.yml | 23 ++ .../recorded/languages/lua/chuckItem2.yml | 37 +++ .../recorded/languages/lua/chuckItem3.yml | 23 ++ .../recorded/languages/lua/chuckKey.yml | 29 ++ .../recorded/languages/lua/chuckName.yml | 25 ++ .../recorded/languages/lua/chuckName2.yml | 25 ++ .../recorded/languages/lua/chuckName3.yml | 23 ++ .../recorded/languages/lua/chuckName4.yml | 23 ++ .../recorded/languages/lua/chuckValue.yml | 23 ++ .../scopes/lua/value.assignment.scope | 0 queries/lua.scm | 277 ++++++++++++++++++ 57 files changed, 2015 insertions(+) create mode 100644 data/playground/lua/lua.lua create mode 100644 packages/common/src/scopeSupportFacets/lua.ts create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/bringArgAirAfterBat.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeArg.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeArg2.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch2.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch3.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCall.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCallee.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCharInsideMap.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeComment.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeComment2.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCondition.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCondition2.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCondition3.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeFunk.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeFunkName.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeIfState.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchPit.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchQuench.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchRed.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideFunk.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideLambda.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideList.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeItem.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeKey.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeLambda.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeList.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeMap.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeName.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeName2.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeRound.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeState.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeState2.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeState3.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeState4.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeString.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeValue.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeValue2.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeValue3.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeValue4.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeValue5.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckArg.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckArg2.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckItem.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckItem2.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckItem3.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckKey.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckName.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckName2.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckName3.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckName4.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckValue.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.assignment.scope create mode 100644 queries/lua.scm diff --git a/data/playground/lua/lua.lua b/data/playground/lua/lua.lua new file mode 100644 index 0000000000..cf18bd7cfe --- /dev/null +++ b/data/playground/lua/lua.lua @@ -0,0 +1,125 @@ + +-- This is a single-line comment + +--[[ + This is a multi-line comment. + It spans multiple lines. +--]] + +-- Variables +local a = 42 +local b, c = "Hello", "World" + +-- Data Types +local number = 3.14 +local boolean = true +local string = "Lua is awesome!" +local table = {1, 2, 3} +local nilValue = nil + +-- Conditional Constructs +local x = 10 +local y = 20 + +-- if-then-else +if x < y then + print("x is less than y") +elseif x > y then + print("x is greater than y") +else + print("x is equal to y") +end + +-- ternary conditional (short if-then-else) +local max = x > y and x or y +print("The maximum value is: " .. max) + +-- Functions +function add(x, b) + return x + y +end + +local sum = add(5, 7) +print("Sum:", sum) + +-- Tables +local person = { + name = "John", + age = 30, + hobbies = {"reading", "gaming", "programming"}, + address = { + street = "123 Main St", + city = "Example City" + } +} + +-- String manipulation +local concatString = "Hello " .. "World" + +-- Metatables and metatable operations +local mt = { + __add = function(a, b) return a + b end, + __sub = function(a, b) return a - b end +} + +setmetatable(a, mt) + +-- Closures +function makeCounter() + local count = 0 + return function() + count = count + 1 + return count + end +end + +local counter = makeCounter() + +-- Coroutines +local co = coroutine.create(function() + for i = 1, 3 do + print("Coroutine", i) + coroutine.yield() + end +end) + +-- Error handling +local success, result = pcall(function() + error("This is an error") +end) + +if not success then + print("Error:", result) +end + +-- Loop Constructs +-- while loop +local i = 1 +i = 2 +while i <= 5 do + print("While loop iteration: " .. i) + i = i + 1 +end + +-- repeat-until loop +i = 1 +repeat + print("Repeat-Until loop iteration: " .. i) + i = i + 1 +until i > 5 + +-- for loop +for j = 1, 5 do + print("For loop iteration: " .. j) +end + +-- numeric for loop with step +for k = 10, 1, -1 do + print("Numeric for loop with step: " .. k) +end + +-- for-in loop (iterating over a table) +local fruits = { "apple", "banana", "cherry" } +for key, value in pairs(fruits) do + print("For-In loop: " .. key .. " = " .. value) +end diff --git a/packages/common/src/scopeSupportFacets/getLanguageScopeSupport.ts b/packages/common/src/scopeSupportFacets/getLanguageScopeSupport.ts index 76f57d6216..618a9b3dc4 100644 --- a/packages/common/src/scopeSupportFacets/getLanguageScopeSupport.ts +++ b/packages/common/src/scopeSupportFacets/getLanguageScopeSupport.ts @@ -3,6 +3,7 @@ import { javaScopeSupport } from "./java"; import { javascriptScopeSupport } from "./javascript"; import { jsonScopeSupport } from "./json"; import { pythonScopeSupport } from "./python"; +import { luaScopeSupport } from "./lua"; import { LanguageScopeSupportFacetMap } from "./scopeSupportFacets.types"; import { talonScopeSupport } from "./talon"; import { typescriptScopeSupport } from "./typescript"; @@ -25,6 +26,8 @@ export function getLanguageScopeSupport( return talonScopeSupport; case "typescript": return typescriptScopeSupport; + case "lua": + return luaScopeSupport; } throw Error(`Unsupported language: '${languageId}'`); } diff --git a/packages/common/src/scopeSupportFacets/lua.ts b/packages/common/src/scopeSupportFacets/lua.ts new file mode 100644 index 0000000000..73365d2852 --- /dev/null +++ b/packages/common/src/scopeSupportFacets/lua.ts @@ -0,0 +1,11 @@ +import { + LanguageScopeSupportFacetMap, + ScopeSupportFacetLevel, +} from "./scopeSupportFacets.types"; + +const { supported, notApplicable } = ScopeSupportFacetLevel; + +export const luaScopeSupport: LanguageScopeSupportFacetMap = { + "key.attribute": notApplicable, + tags: notApplicable, +}; diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/bringArgAirAfterBat.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/bringArgAirAfterBat.yml new file mode 100644 index 0000000000..d55446ad05 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/bringArgAirAfterBat.yml @@ -0,0 +1,50 @@ +languageId: lua +command: + version: 6 + spokenForm: bring arg air after bat + action: + name: replaceWithTarget + source: + type: primitive + mark: {type: decoratedSymbol, symbolColor: default, character: a} + modifiers: + - type: containingScope + scopeType: {type: argumentOrParameter} + destination: + type: primitive + insertionMode: after + target: + type: primitive + mark: {type: decoratedSymbol, symbolColor: default, character: b} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + function makeCounter(a, b) + local count = 0 + return function() + count = count + 1 + return count + end + end + selections: + - anchor: {line: 0, character: 21} + active: {line: 0, character: 21} + marks: + default.a: + start: {line: 0, character: 21} + end: {line: 0, character: 22} + default.b: + start: {line: 0, character: 24} + end: {line: 0, character: 25} +finalState: + documentContents: |- + function makeCounter(a, b, a) + local count = 0 + return function() + count = count + 1 + return count + end + end + selections: + - anchor: {line: 0, character: 21} + active: {line: 0, character: 21} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeArg.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeArg.yml new file mode 100644 index 0000000000..af707cdb31 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeArg.yml @@ -0,0 +1,29 @@ +languageId: lua +command: + version: 6 + spokenForm: change arg + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: argumentOrParameter} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + function add(x, b) + return x + y + end + selections: + - anchor: {line: 0, character: 13} + active: {line: 0, character: 13} + marks: {} +finalState: + documentContents: |- + function add(, b) + return x + y + end + selections: + - anchor: {line: 0, character: 13} + active: {line: 0, character: 13} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeArg2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeArg2.yml new file mode 100644 index 0000000000..ddf39a380b --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeArg2.yml @@ -0,0 +1,25 @@ +languageId: lua +command: + version: 6 + spokenForm: change arg + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: argumentOrParameter} + usePrePhraseSnapshot: true +initialState: + documentContents: | + local sum = add(5, 7) + selections: + - anchor: {line: 0, character: 16} + active: {line: 0, character: 16} + marks: {} +finalState: + documentContents: | + local sum = add(, 7) + selections: + - anchor: {line: 0, character: 16} + active: {line: 0, character: 16} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch.yml new file mode 100644 index 0000000000..97d2089bec --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch.yml @@ -0,0 +1,36 @@ +languageId: lua +command: + version: 6 + spokenForm: change branch + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: branch} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + if a > 10 then + print("a is greater than 10") + elseif a < 10 then + print("a is less than 10") + else + print("a is equal to 10") + end + selections: + - anchor: {line: 2, character: 4} + active: {line: 2, character: 4} + marks: {} +finalState: + documentContents: |- + if a > 10 then + print("a is greater than 10") + + else + print("a is equal to 10") + end + selections: + - anchor: {line: 2, character: 0} + active: {line: 2, character: 0} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch2.yml new file mode 100644 index 0000000000..344d19afa4 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch2.yml @@ -0,0 +1,36 @@ +languageId: lua +command: + version: 6 + spokenForm: change branch + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: branch} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + if a > 10 then + print("a is greater than 10") + elseif a < 10 then + print("a is less than 10") + else + print("a is equal to 10") + end + selections: + - anchor: {line: 5, character: 4} + active: {line: 5, character: 4} + marks: {} +finalState: + documentContents: |- + if a > 10 then + print("a is greater than 10") + elseif a < 10 then + print("a is less than 10") + + end + selections: + - anchor: {line: 4, character: 0} + active: {line: 4, character: 0} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch3.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch3.yml new file mode 100644 index 0000000000..2abd7e9b1d --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch3.yml @@ -0,0 +1,36 @@ +languageId: lua +command: + version: 6 + spokenForm: change branch + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: branch} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + if a > 10 then + print("a is greater than 10") + elseif a < 10 then + print("a is less than 10") + else + print("a is equal to 10") + end + selections: + - anchor: {line: 1, character: 4} + active: {line: 1, character: 4} + marks: {} +finalState: + documentContents: |- + + elseif a < 10 then + print("a is less than 10") + else + print("a is equal to 10") + end + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCall.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCall.yml new file mode 100644 index 0000000000..a8520aa736 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCall.yml @@ -0,0 +1,25 @@ +languageId: lua +command: + version: 6 + spokenForm: change call + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: functionCall} + usePrePhraseSnapshot: true +initialState: + documentContents: | + print("a is greater than 10") + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + marks: {} +finalState: + documentContents: |+ + + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCallee.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCallee.yml new file mode 100644 index 0000000000..2c5a73bf8a --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCallee.yml @@ -0,0 +1,25 @@ +languageId: lua +command: + version: 6 + spokenForm: change callee + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: functionCallee} + usePrePhraseSnapshot: true +initialState: + documentContents: | + print("a is greater than 10") + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + marks: {} +finalState: + documentContents: | + ("a is greater than 10") + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCharInsideMap.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCharInsideMap.yml new file mode 100644 index 0000000000..28d7688dca --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCharInsideMap.yml @@ -0,0 +1,33 @@ +languageId: lua +command: + version: 6 + spokenForm: change char inside map + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: character} + - {type: interiorOnly} + - type: containingScope + scopeType: {type: map} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + foo = { + bar = "a", + baz = "b" + } + selections: + - anchor: {line: 2, character: 9} + active: {line: 2, character: 9} + marks: {} +finalState: + documentContents: |- + foo = { + + } + selections: + - anchor: {line: 1, character: 4} + active: {line: 1, character: 4} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeComment.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeComment.yml new file mode 100644 index 0000000000..6b3eedecff --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeComment.yml @@ -0,0 +1,25 @@ +languageId: lua +command: + version: 6 + spokenForm: change comment + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: comment} + usePrePhraseSnapshot: true +initialState: + documentContents: | + -- This is a single-line comment + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + marks: {} +finalState: + documentContents: |+ + + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeComment2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeComment2.yml new file mode 100644 index 0000000000..a4b799ca7a --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeComment2.yml @@ -0,0 +1,27 @@ +languageId: lua +command: + version: 6 + spokenForm: change comment + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: comment} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + --[[ + This is a multi-line comment. + It spans multiple lines. + --]] + selections: + - anchor: {line: 2, character: 4} + active: {line: 2, character: 4} + marks: {} +finalState: + documentContents: "" + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCondition.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCondition.yml new file mode 100644 index 0000000000..61d0b7a0f2 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCondition.yml @@ -0,0 +1,23 @@ +languageId: lua +command: + version: 6 + spokenForm: change condition + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: condition} + usePrePhraseSnapshot: true +initialState: + documentContents: local max = x > y and x or y + selections: + - anchor: {line: 0, character: 12} + active: {line: 0, character: 12} + marks: {} +finalState: + documentContents: local max = and x or y + selections: + - anchor: {line: 0, character: 12} + active: {line: 0, character: 12} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCondition2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCondition2.yml new file mode 100644 index 0000000000..fea6b7a7d2 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCondition2.yml @@ -0,0 +1,33 @@ +languageId: lua +command: + version: 6 + spokenForm: change condition + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: condition} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + local i = 1 + while i <= 5 do + print("While loop iteration: " .. i) + i = i + 1 + end + selections: + - anchor: {line: 1, character: 7} + active: {line: 1, character: 7} + marks: {} +finalState: + documentContents: |- + local i = 1 + while do + print("While loop iteration: " .. i) + i = i + 1 + end + selections: + - anchor: {line: 1, character: 6} + active: {line: 1, character: 6} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCondition3.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCondition3.yml new file mode 100644 index 0000000000..5211c20dba --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCondition3.yml @@ -0,0 +1,33 @@ +languageId: lua +command: + version: 6 + spokenForm: change condition + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: condition} + usePrePhraseSnapshot: true +initialState: + documentContents: | + i = 1 + repeat + print("Repeat-Until loop iteration: " .. i) + i = i + 1 + until i > 5 + selections: + - anchor: {line: 4, character: 6} + active: {line: 4, character: 6} + marks: {} +finalState: + documentContents: | + i = 1 + repeat + print("Repeat-Until loop iteration: " .. i) + i = i + 1 + until + selections: + - anchor: {line: 4, character: 6} + active: {line: 4, character: 6} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeFunk.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeFunk.yml new file mode 100644 index 0000000000..3c61d6d9cc --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeFunk.yml @@ -0,0 +1,26 @@ +languageId: lua +command: + version: 6 + spokenForm: change funk + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: namedFunction} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + function add(x, b) + return x + y + end + selections: + - anchor: {line: 1, character: 7} + active: {line: 1, character: 7} + marks: {} +finalState: + documentContents: "" + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeFunkName.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeFunkName.yml new file mode 100644 index 0000000000..3682b8b651 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeFunkName.yml @@ -0,0 +1,29 @@ +languageId: lua +command: + version: 6 + spokenForm: change funk name + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: functionName} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + function add(x, b) + return x + y + end + selections: + - anchor: {line: 1, character: 7} + active: {line: 1, character: 7} + marks: {} +finalState: + documentContents: |- + function (x, b) + return x + y + end + selections: + - anchor: {line: 0, character: 9} + active: {line: 0, character: 9} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeIfState.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeIfState.yml new file mode 100644 index 0000000000..e1d1d4b8c2 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeIfState.yml @@ -0,0 +1,30 @@ +languageId: lua +command: + version: 6 + spokenForm: change if state + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: ifStatement} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + if a > 10 then + print("a is greater than 10") + elseif a < 10 then + print("a is less than 10") + else + print("a is equal to 10") + end + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} + marks: {} +finalState: + documentContents: "" + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchPit.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchPit.yml new file mode 100644 index 0000000000..63e8662a46 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchPit.yml @@ -0,0 +1,42 @@ +languageId: lua +command: + version: 6 + spokenForm: change inside branch pit + action: + name: clearAndSetSelection + target: + type: primitive + mark: {type: decoratedSymbol, symbolColor: default, character: p} + modifiers: + - {type: interiorOnly} + - type: containingScope + scopeType: {type: branch} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + if x < y then + print("x is less than y") + elseif x > y then + print("x is greater than y") + else + print("x is equal to y") + end + selections: + - anchor: {line: 0, character: 6} + active: {line: 0, character: 6} + marks: + default.p: + start: {line: 1, character: 4} + end: {line: 1, character: 9} +finalState: + documentContents: |- + if x < y then + + elseif x > y then + print("x is greater than y") + else + print("x is equal to y") + end + selections: + - anchor: {line: 1, character: 4} + active: {line: 1, character: 4} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchQuench.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchQuench.yml new file mode 100644 index 0000000000..ddac3e9ec0 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchQuench.yml @@ -0,0 +1,42 @@ +languageId: lua +command: + version: 6 + spokenForm: change inside branch quench + action: + name: clearAndSetSelection + target: + type: primitive + mark: {type: decoratedSymbol, symbolColor: default, character: q} + modifiers: + - {type: interiorOnly} + - type: containingScope + scopeType: {type: branch} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + if x < y then + print("x is less than y") + elseif x > y then + print("x is greater than y") + else + print("x is equal to y") + end + selections: + - anchor: {line: 0, character: 6} + active: {line: 0, character: 6} + marks: + default.q: + start: {line: 5, character: 16} + end: {line: 5, character: 21} +finalState: + documentContents: |- + if x < y then + print("x is less than y") + elseif x > y then + print("x is greater than y") + else + + end + selections: + - anchor: {line: 5, character: 4} + active: {line: 5, character: 4} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchRed.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchRed.yml new file mode 100644 index 0000000000..18470e015b --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchRed.yml @@ -0,0 +1,42 @@ +languageId: lua +command: + version: 6 + spokenForm: change inside branch red + action: + name: clearAndSetSelection + target: + type: primitive + mark: {type: decoratedSymbol, symbolColor: default, character: r} + modifiers: + - {type: interiorOnly} + - type: containingScope + scopeType: {type: branch} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + if x < y then + print("x is less than y") + elseif x > y then + print("x is greater than y") + else + print("x is equal to y") + end + selections: + - anchor: {line: 0, character: 6} + active: {line: 0, character: 6} + marks: + default.r: + start: {line: 3, character: 4} + end: {line: 3, character: 9} +finalState: + documentContents: |- + if x < y then + print("x is less than y") + elseif x > y then + + else + print("x is equal to y") + end + selections: + - anchor: {line: 3, character: 4} + active: {line: 3, character: 4} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideFunk.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideFunk.yml new file mode 100644 index 0000000000..dd84f6ca05 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideFunk.yml @@ -0,0 +1,34 @@ +languageId: lua +command: + version: 6 + spokenForm: change inside funk + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - {type: interiorOnly} + - type: containingScope + scopeType: {type: namedFunction} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + function makeCounter() + local count = 0 + return function() + count = count + 1 + return count + end + end + selections: + - anchor: {line: 1, character: 19} + active: {line: 1, character: 19} + marks: {} +finalState: + documentContents: |- + function makeCounter() + + end + selections: + - anchor: {line: 1, character: 4} + active: {line: 1, character: 4} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideLambda.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideLambda.yml new file mode 100644 index 0000000000..86c83ab5af --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideLambda.yml @@ -0,0 +1,37 @@ +languageId: lua +command: + version: 6 + spokenForm: change inside lambda + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - {type: interiorOnly} + - type: containingScope + scopeType: {type: anonymousFunction} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + function makeCounter() + local count = 0 + return function() + count = count + 1 + return count + end + end + selections: + - anchor: {line: 3, character: 19} + active: {line: 3, character: 19} + marks: {} +finalState: + documentContents: |- + function makeCounter() + local count = 0 + return function() + + end + end + selections: + - anchor: {line: 3, character: 8} + active: {line: 3, character: 8} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideList.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideList.yml new file mode 100644 index 0000000000..06802e045d --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideList.yml @@ -0,0 +1,26 @@ +languageId: lua +command: + version: 6 + spokenForm: change inside list + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - {type: interiorOnly} + - type: containingScope + scopeType: {type: list} + usePrePhraseSnapshot: true +initialState: + documentContents: | + foo = {"a", "b", "c"}, + selections: + - anchor: {line: 0, character: 9} + active: {line: 0, character: 9} + marks: {} +finalState: + documentContents: | + foo = {}, + selections: + - anchor: {line: 0, character: 7} + active: {line: 0, character: 7} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeItem.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeItem.yml new file mode 100644 index 0000000000..849765d0c9 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeItem.yml @@ -0,0 +1,23 @@ +languageId: lua +command: + version: 6 + spokenForm: change item + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: collectionItem} + usePrePhraseSnapshot: true +initialState: + documentContents: local table = {1, 2, 3} + selections: + - anchor: {line: 0, character: 18} + active: {line: 0, character: 18} + marks: {} +finalState: + documentContents: local table = {1, , 3} + selections: + - anchor: {line: 0, character: 18} + active: {line: 0, character: 18} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeKey.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeKey.yml new file mode 100644 index 0000000000..ad80c87ae4 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeKey.yml @@ -0,0 +1,41 @@ +languageId: lua +command: + version: 6 + spokenForm: change key + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: collectionKey} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + local person = { + name = "John", + age = 30, + hobbies = {"reading", "gaming", "programming"}, + address = { + street = "123 Main St", + city = "Example City" + } + } + selections: + - anchor: {line: 2, character: 6} + active: {line: 2, character: 6} + marks: {} +finalState: + documentContents: |- + local person = { + name = "John", + = 30, + hobbies = {"reading", "gaming", "programming"}, + address = { + street = "123 Main St", + city = "Example City" + } + } + selections: + - anchor: {line: 2, character: 4} + active: {line: 2, character: 4} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeLambda.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeLambda.yml new file mode 100644 index 0000000000..f86b34630e --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeLambda.yml @@ -0,0 +1,34 @@ +languageId: lua +command: + version: 6 + spokenForm: change lambda + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: anonymousFunction} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + function makeCounter() + local count = 0 + return function() + count = count + 1 + return count + end + end + selections: + - anchor: {line: 3, character: 12} + active: {line: 3, character: 12} + marks: {} +finalState: + documentContents: |- + function makeCounter() + local count = 0 + return + end + selections: + - anchor: {line: 2, character: 11} + active: {line: 2, character: 11} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeList.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeList.yml new file mode 100644 index 0000000000..277c830a92 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeList.yml @@ -0,0 +1,41 @@ +languageId: lua +command: + version: 6 + spokenForm: change list + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: list} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + local person = { + name = "John", + age = 30, + hobbies = {"reading", "gaming", "programming"}, + address = { + street = "123 Main St", + city = "Example City" + } + } + selections: + - anchor: {line: 3, character: 17} + active: {line: 3, character: 17} + marks: {} +finalState: + documentContents: |- + local person = { + name = "John", + age = 30, + hobbies = , + address = { + street = "123 Main St", + city = "Example City" + } + } + selections: + - anchor: {line: 3, character: 14} + active: {line: 3, character: 14} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeMap.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeMap.yml new file mode 100644 index 0000000000..66b6f46dc5 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeMap.yml @@ -0,0 +1,23 @@ +languageId: lua +command: + version: 6 + spokenForm: change map + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: map} + usePrePhraseSnapshot: true +initialState: + documentContents: local table = {1, 2, 3} + selections: + - anchor: {line: 0, character: 18} + active: {line: 0, character: 18} + marks: {} +finalState: + documentContents: "local table = " + selections: + - anchor: {line: 0, character: 14} + active: {line: 0, character: 14} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeName.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeName.yml new file mode 100644 index 0000000000..1906e84703 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeName.yml @@ -0,0 +1,23 @@ +languageId: lua +command: + version: 6 + spokenForm: change name + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: name} + usePrePhraseSnapshot: true +initialState: + documentContents: local a = 42 + selections: + - anchor: {line: 0, character: 12} + active: {line: 0, character: 12} + marks: {} +finalState: + documentContents: local = 42 + selections: + - anchor: {line: 0, character: 6} + active: {line: 0, character: 6} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeName2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeName2.yml new file mode 100644 index 0000000000..59a7975d92 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeName2.yml @@ -0,0 +1,23 @@ +languageId: lua +command: + version: 6 + spokenForm: change name + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: name} + usePrePhraseSnapshot: true +initialState: + documentContents: local i = 1 + selections: + - anchor: {line: 0, character: 2} + active: {line: 0, character: 2} + marks: {} +finalState: + documentContents: local = 1 + selections: + - anchor: {line: 0, character: 6} + active: {line: 0, character: 6} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeRound.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeRound.yml new file mode 100644 index 0000000000..8af4bd4791 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeRound.yml @@ -0,0 +1,25 @@ +languageId: lua +command: + version: 6 + spokenForm: change round + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: surroundingPair, delimiter: parentheses} + usePrePhraseSnapshot: true +initialState: + documentContents: | + local string = "Lua is (awesome)!" + selections: + - anchor: {line: 0, character: 30} + active: {line: 0, character: 30} + marks: {} +finalState: + documentContents: | + local string = "Lua is !" + selections: + - anchor: {line: 0, character: 23} + active: {line: 0, character: 23} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeState.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeState.yml new file mode 100644 index 0000000000..d5a25add4d --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeState.yml @@ -0,0 +1,25 @@ +languageId: lua +command: + version: 6 + spokenForm: change state + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: statement} + usePrePhraseSnapshot: true +initialState: + documentContents: | + local sum = add(5, 7) + selections: + - anchor: {line: 0, character: 6} + active: {line: 0, character: 6} + marks: {} +finalState: + documentContents: |+ + + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeState2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeState2.yml new file mode 100644 index 0000000000..3e0de207f5 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeState2.yml @@ -0,0 +1,37 @@ +languageId: lua +command: + version: 6 + spokenForm: change state + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: statement} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + function makeCounter() + local count = 0 + return function() + count = count + 1 + return count + end + end + selections: + - anchor: {line: 1, character: 12} + active: {line: 1, character: 12} + marks: {} +finalState: + documentContents: |- + function makeCounter() + + return function() + count = count + 1 + return count + end + end + selections: + - anchor: {line: 1, character: 4} + active: {line: 1, character: 4} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeState3.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeState3.yml new file mode 100644 index 0000000000..3ec98a9cdc --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeState3.yml @@ -0,0 +1,34 @@ +languageId: lua +command: + version: 6 + spokenForm: change state + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: statement} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + function makeCounter() + local count = 0 + return function() + count = count + 1 + return count + end + end + selections: + - anchor: {line: 2, character: 8} + active: {line: 2, character: 8} + marks: {} +finalState: + documentContents: |- + function makeCounter() + local count = 0 + + end + selections: + - anchor: {line: 2, character: 4} + active: {line: 2, character: 4} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeState4.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeState4.yml new file mode 100644 index 0000000000..9ade8e188a --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeState4.yml @@ -0,0 +1,37 @@ +languageId: lua +command: + version: 6 + spokenForm: change state + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: statement} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + function makeCounter() + local count = 0 + return function() + count = count + 1 + return count + end + end + selections: + - anchor: {line: 3, character: 11} + active: {line: 3, character: 11} + marks: {} +finalState: + documentContents: |- + function makeCounter() + local count = 0 + return function() + + return count + end + end + selections: + - anchor: {line: 3, character: 8} + active: {line: 3, character: 8} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeString.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeString.yml new file mode 100644 index 0000000000..ead7c7d2a4 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeString.yml @@ -0,0 +1,25 @@ +languageId: lua +command: + version: 6 + spokenForm: change string + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: surroundingPair, delimiter: string} + usePrePhraseSnapshot: true +initialState: + documentContents: | + local string = "Lua is awesome!" + selections: + - anchor: {line: 0, character: 19} + active: {line: 0, character: 19} + marks: {} +finalState: + documentContents: | + local string = + selections: + - anchor: {line: 0, character: 15} + active: {line: 0, character: 15} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeValue.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeValue.yml new file mode 100644 index 0000000000..8e26cf7f6c --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeValue.yml @@ -0,0 +1,23 @@ +languageId: lua +command: + version: 6 + spokenForm: change value + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: value} + usePrePhraseSnapshot: true +initialState: + documentContents: local a = 42 + selections: + - anchor: {line: 0, character: 12} + active: {line: 0, character: 12} + marks: {} +finalState: + documentContents: "local a = " + selections: + - anchor: {line: 0, character: 10} + active: {line: 0, character: 10} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeValue2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeValue2.yml new file mode 100644 index 0000000000..062f8d5390 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeValue2.yml @@ -0,0 +1,38 @@ +languageId: lua +command: + version: 6 + spokenForm: change value + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: value} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + local person = { + name = "John", + age = 30, + hobbies = {"reading", "gaming", "programming"}, + address = { + street = "123 Main St", + city = "Example City" + } + } + selections: + - anchor: {line: 4, character: 10} + active: {line: 4, character: 10} + marks: {} +finalState: + documentContents: |- + local person = { + name = "John", + age = 30, + hobbies = {"reading", "gaming", "programming"}, + address = + } + selections: + - anchor: {line: 4, character: 14} + active: {line: 4, character: 14} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeValue3.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeValue3.yml new file mode 100644 index 0000000000..d2ebe53dd0 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeValue3.yml @@ -0,0 +1,41 @@ +languageId: lua +command: + version: 6 + spokenForm: change value + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: value} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + local person = { + name = "John", + age = 30, + hobbies = {"reading", "gaming", "programming"}, + address = { + street = "123 Main St", + city = "Example City" + } + } + selections: + - anchor: {line: 5, character: 11} + active: {line: 5, character: 11} + marks: {} +finalState: + documentContents: |- + local person = { + name = "John", + age = 30, + hobbies = {"reading", "gaming", "programming"}, + address = { + street = , + city = "Example City" + } + } + selections: + - anchor: {line: 5, character: 17} + active: {line: 5, character: 17} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeValue4.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeValue4.yml new file mode 100644 index 0000000000..aede3b01d9 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeValue4.yml @@ -0,0 +1,34 @@ +languageId: lua +command: + version: 6 + spokenForm: change value + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: value} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + function makeCounter() + local count = 0 + return function() + count = count + 1 + return count + end + end + selections: + - anchor: {line: 2, character: 8} + active: {line: 2, character: 8} + marks: {} +finalState: + documentContents: |- + function makeCounter() + local count = 0 + return + end + selections: + - anchor: {line: 2, character: 11} + active: {line: 2, character: 11} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeValue5.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeValue5.yml new file mode 100644 index 0000000000..dcbe2ce46e --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeValue5.yml @@ -0,0 +1,23 @@ +languageId: lua +command: + version: 6 + spokenForm: change value + action: + name: clearAndSetSelection + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: value} + usePrePhraseSnapshot: true +initialState: + documentContents: local i = 1 + selections: + - anchor: {line: 0, character: 2} + active: {line: 0, character: 2} + marks: {} +finalState: + documentContents: "local i = " + selections: + - anchor: {line: 0, character: 10} + active: {line: 0, character: 10} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckArg.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckArg.yml new file mode 100644 index 0000000000..78f9721c88 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckArg.yml @@ -0,0 +1,37 @@ +languageId: lua +command: + version: 6 + spokenForm: chuck arg + action: + name: remove + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: argumentOrParameter} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + function makeCounter(a, b) + local count = 0 + return function() + count = count + 1 + return count + end + end + selections: + - anchor: {line: 0, character: 22} + active: {line: 0, character: 22} + marks: {} +finalState: + documentContents: |- + function makeCounter(b) + local count = 0 + return function() + count = count + 1 + return count + end + end + selections: + - anchor: {line: 0, character: 21} + active: {line: 0, character: 21} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckArg2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckArg2.yml new file mode 100644 index 0000000000..27f9f6542b --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckArg2.yml @@ -0,0 +1,37 @@ +languageId: lua +command: + version: 6 + spokenForm: chuck arg + action: + name: remove + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: argumentOrParameter} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + function makeCounter(a) + local count = 0 + return function() + count = count + 1 + return count + end + end + selections: + - anchor: {line: 0, character: 22} + active: {line: 0, character: 22} + marks: {} +finalState: + documentContents: |- + function makeCounter() + local count = 0 + return function() + count = count + 1 + return count + end + end + selections: + - anchor: {line: 0, character: 21} + active: {line: 0, character: 21} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckItem.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckItem.yml new file mode 100644 index 0000000000..2b37895abf --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckItem.yml @@ -0,0 +1,23 @@ +languageId: lua +command: + version: 6 + spokenForm: chuck item + action: + name: remove + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: collectionItem} + usePrePhraseSnapshot: true +initialState: + documentContents: local table = {1, 2, 3} + selections: + - anchor: {line: 0, character: 18} + active: {line: 0, character: 18} + marks: {} +finalState: + documentContents: local table = {1, 3} + selections: + - anchor: {line: 0, character: 18} + active: {line: 0, character: 18} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckItem2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckItem2.yml new file mode 100644 index 0000000000..773ad85061 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckItem2.yml @@ -0,0 +1,37 @@ +languageId: lua +command: + version: 6 + spokenForm: chuck item + action: + name: remove + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: collectionItem} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + local person = { + name = "John", + age = 30, + hobbies = {"reading", "gaming", "programming"}, + address = { + street = "123 Main St", + city = "Example City" + } + } + selections: + - anchor: {line: 4, character: 6} + active: {line: 4, character: 6} + marks: {} +finalState: + documentContents: |- + local person = { + name = "John", + age = 30, + hobbies = {"reading", "gaming", "programming"} + } + selections: + - anchor: {line: 3, character: 50} + active: {line: 3, character: 50} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckItem3.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckItem3.yml new file mode 100644 index 0000000000..9b415c190b --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckItem3.yml @@ -0,0 +1,23 @@ +languageId: lua +command: + version: 6 + spokenForm: chuck item + action: + name: remove + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: collectionItem} + usePrePhraseSnapshot: true +initialState: + documentContents: hobbies = {"reading"} + selections: + - anchor: {line: 0, character: 19} + active: {line: 0, character: 19} + marks: {} +finalState: + documentContents: hobbies = {} + selections: + - anchor: {line: 0, character: 11} + active: {line: 0, character: 11} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckKey.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckKey.yml new file mode 100644 index 0000000000..d9c7b87b81 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckKey.yml @@ -0,0 +1,29 @@ +languageId: lua +command: + version: 6 + spokenForm: chuck key + action: + name: remove + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: collectionKey} + usePrePhraseSnapshot: true +initialState: + documentContents: |- + local person = { + name = "John", + } + selections: + - anchor: {line: 1, character: 8} + active: {line: 1, character: 8} + marks: {} +finalState: + documentContents: |- + local person = { + "John", + } + selections: + - anchor: {line: 1, character: 4} + active: {line: 1, character: 4} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckName.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckName.yml new file mode 100644 index 0000000000..5c17921b12 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckName.yml @@ -0,0 +1,25 @@ +languageId: lua +command: + version: 6 + spokenForm: chuck name + action: + name: remove + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: name} + usePrePhraseSnapshot: true +initialState: + documentContents: | + local a = 42 + selections: + - anchor: {line: 0, character: 3} + active: {line: 0, character: 3} + marks: {} +finalState: + documentContents: | + 42 + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckName2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckName2.yml new file mode 100644 index 0000000000..7d796ad01e --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckName2.yml @@ -0,0 +1,25 @@ +languageId: lua +command: + version: 6 + spokenForm: chuck name + action: + name: remove + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: name} + usePrePhraseSnapshot: true +initialState: + documentContents: | + a = 42 + selections: + - anchor: {line: 0, character: 6} + active: {line: 0, character: 6} + marks: {} +finalState: + documentContents: | + 42 + selections: + - anchor: {line: 0, character: 2} + active: {line: 0, character: 2} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckName3.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckName3.yml new file mode 100644 index 0000000000..bd70cdc83d --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckName3.yml @@ -0,0 +1,23 @@ +languageId: lua +command: + version: 6 + spokenForm: chuck name + action: + name: remove + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: name} + usePrePhraseSnapshot: true +initialState: + documentContents: local a,b = "Hello", "World" + selections: + - anchor: {line: 0, character: 28} + active: {line: 0, character: 28} + marks: {} +finalState: + documentContents: "\"Hello\", \"World\"" + selections: + - anchor: {line: 0, character: 16} + active: {line: 0, character: 16} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckName4.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckName4.yml new file mode 100644 index 0000000000..9bd9b6ba0e --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckName4.yml @@ -0,0 +1,23 @@ +languageId: lua +command: + version: 6 + spokenForm: chuck name + action: + name: remove + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: name} + usePrePhraseSnapshot: true +initialState: + documentContents: a,b = "Hello", "World" + selections: + - anchor: {line: 0, character: 22} + active: {line: 0, character: 22} + marks: {} +finalState: + documentContents: "\"Hello\", \"World\"" + selections: + - anchor: {line: 0, character: 16} + active: {line: 0, character: 16} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckValue.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckValue.yml new file mode 100644 index 0000000000..25c9d49f2a --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/chuckValue.yml @@ -0,0 +1,23 @@ +languageId: lua +command: + version: 6 + spokenForm: chuck value + action: + name: remove + target: + type: primitive + modifiers: + - type: containingScope + scopeType: {type: value} + usePrePhraseSnapshot: true +initialState: + documentContents: local table = {1, 2, 3} + selections: + - anchor: {line: 0, character: 23} + active: {line: 0, character: 23} + marks: {} +finalState: + documentContents: local table + selections: + - anchor: {line: 0, character: 11} + active: {line: 0, character: 11} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.assignment.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.assignment.scope new file mode 100644 index 0000000000..e69de29bb2 diff --git a/queries/lua.scm b/queries/lua.scm new file mode 100644 index 0000000000..b76f514040 --- /dev/null +++ b/queries/lua.scm @@ -0,0 +1,277 @@ +;; Statements +[ + (variable_declaration) + (break_statement) + (do_statement) + (empty_statement) + (for_statement) + (goto_statement) + (if_statement) + (label_statement) + (repeat_statement) + (return_statement) + (while_statement) +] @statement + +;; Only treat function declarions and calls as statements if they +;; aren't part of assignments, etc +( + [ + (function_declaration) + (function_call) + ] @statement + (#not-parent-type? @statement expression_list) +) +[ + (block) + (chunk) +] @statement.iteration @namedFunction.iteration @functionCall.iteration + +;; Duplicate with above, due to 3 label node limit +[ + (block) + (chunk) +] @ifStatement.iteration @value.iteration + +;; Capture assignment only if without variable prefix +;;!! count = count + 1 +;;! ^^^^^^^^^^^^^^^^^ +( + (assignment_statement) @statement + (#not-parent-type? @statement variable_declaration) +) + +;; Conditionals +;;!! if x < y then +;;! ---^^^^^----- +;;! ---xxxxxx---- +;;!! end +;;! --- +(if_statement + _ @condition.domain.start.startOf + condition: (_) @condition + consequence: (_) + !alternative + "end" @condition.domain.end.endOf +) + +;;!! if x < y then +;;! ---^^^^^----- +;;! ---xxxxxx---- +;;!! elseif x < y then +(if_statement + _ @_.domain.start.startOf + condition: (_) @condition + consequence: (_) @_.domain.end.endOf + alternative: (_) +) + +;;!! elseif x < y then +;;! -------^^^^^----- +;;! -------xxxxxx---- +(elseif_statement + condition: (_) @condition +) @_.domain + +;;!! +(if_statement + "if" @branch.start + consequence: (_) @branch.end @branch.interior +) @ifStatement @branch.iteration @condition.iteration + +;;!! if x < y then +;;!! print("x smaller") +;;!! else +;;! ^^^^ +;;!! print("x bigger") +;;! ^^^^^^^^^^^^^^^^^ +;;!! end +[ + (elseif_statement + consequence: (_) @branch.interior + ) + (else_statement + body: (_) @branch.interior + ) +] @branch @_.domain + +;; Lists and maps +(table_constructor + "{" @_.interior.start.endOf @value.iteration.start.endOf + (field + name: (_) + ) + "}" @_.interior.end.startOf @value.iteration.end.startOf +) @map @collectionKey.iteration +;;!! a = { foo = "bar" } +;;! ^^^-------- +;;! xxxxxx----- +(field + name: (_) @collectionKey @_.trailing.start.endOf + value: (_) @_.trailing.end.startOf +) @_.domain +;;!! a = { foo = "bar" } +;;! ------^^^^^ +;;! ---xxxxxxxx +(field + name: (_) @_.leading.start.endOf + value: (_) @value @_.leading.end.startOf +) @_.domain +;; In lua everything is a map, but a map that omits keys for entries +;; is similar enough to a list to warrant having that scope. +;;!! a = { "1", "2", "3" } +;;! ^^^^^^^^^^^^^^^^^ +(table_constructor + "{" @_.interior.start.endOf + (field + !name + ) + "}" @_.interior.end.startOf +) @list + +;; Strings + +(comment) @comment @textFragment +(string) @string +(string_content) @textFragment + +;; Functions + +;; callee: +;;!! local sum = add(5, 7) +;;! ^^^------ +;; call: +;;!! local sum = add(5, 7) +;;! ^^^^^^^^^ +(function_call + name: (_) @functionCallee +) @_.domain @functionCall + +;;!!local sum = add(5, 7) +;;! ^--- +;;! xxx- +(arguments + "(" @_.iteration.start.endOf + (_)? @_.leading.start.endOf + . + (_) @argumentOrParameter @_.leading.end.startOf @_.trailing.start.endOf + . + (_)? @_.trailing.end.startOf + ")" @_.iteration.end.startOf + (#insertion-delimiter! @argumentOrParameter ", ") +) +;;!!function add(5, 7) +;;! ^--- +;;! xxx- +(parameters + "(" @_.iteration.start.endOf + (_)? @_.leading.start.endOf + . + (_) @argumentOrParameter @_.leading.end.startOf @_.trailing.start.endOf + . + (_)? @_.trailing.end.startOf + ")" @_.iteration.end.startOf + (#insertion-delimiter! @argumentOrParameter ", ") +) + +;; funk name: +;;!! function add(x, b) return x + y end +;;! ---------^^^----------------------- +;; inside funk: +;;!! function add(x, b) return x + y end +;;! -------------------^^^^^^^^^^^^---- +;;! funk: +;;!! function add(x, b) return x + y end +;;! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +(function_declaration + name: (_) @functionName + body: (_)? @namedFunction.interior @ifStatement.iteration @item.iteration +) @_.domain @namedFunction + +;; inside lambda: +;;!! __add = function(a, b) return a + b end +;;! ---------------^^^^^^^^^^^^---- +;; lambda: +;;!! __add = function(a, b) return a + b end +;;! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +(function_definition + !name + body: (_)? @anonymousFunction.interior @ifStatement.iteration +) @_.domain @anonymousFunction + +;; Names and values + +;; Handle variable assignments +;;!! a = 42 +;;! ^----- +;;! xxxx-- +( + (assignment_statement + (variable_list) @name + (#allow-multiple! @name) + . + "=" + . + (_) @_.leading.end.startOf + ) @dummy @_.leading.start.startOf @_.domain + (#not-parent-type? @dummy variable_declaration) +) +;; Handle variable declarations +;;!! local a = 42 +;;! ------^----- +;;! xxxxxxxxxx-- +(_ + local_declaration: (variable_declaration + "local" @_.leading.start.startOf + . + (assignment_statement + (variable_list) @name + (#allow-multiple! @name) + . + "=" + (_) @_.leading.end.startOf + ) + ) @_.domain +) + +;; Handle assignment values +;;!! a = 42 +;;! ----------^^ +;;! -------xxxxx +( + (assignment_statement + (_) @_.leading.start.endOf + . + (expression_list + value: (_) + ) @value @_.leading.end.startOf + ) @dummy @_.domain + (#not-parent-type? @dummy variable_declaration) +) + +;; Handle variable declaration values +;;!! local a = 42 +;;! ----------^^ +;;! -------xxxxx +(_ + local_declaration: (variable_declaration + (assignment_statement + (_) @_.leading.start.endOf + . + (expression_list + value: (_) + ) @value @_.leading.end.startOf + ) + ) @_.domain +) + +;;!! return a + b +;;! -------^^^^^ +;;! ------xxxxxx +(return_statement + (_) @value +) @_.domain + +;; Structures and object access + +;; (method_index_expression) @private.fieldAccess From 68d180de8f6371937fa2d9e421289b788bd915d6 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 1 Feb 2024 14:47:38 +0000 Subject: [PATCH 02/18] cleanup name / value --- queries/lua.scm | 55 ++++++++++++++++--------------------------------- 1 file changed, 18 insertions(+), 37 deletions(-) diff --git a/queries/lua.scm b/queries/lua.scm index b76f514040..9cba124391 100644 --- a/queries/lua.scm +++ b/queries/lua.scm @@ -208,43 +208,29 @@ ( (assignment_statement (variable_list) @name - (#allow-multiple! @name) - . - "=" - . - (_) @_.leading.end.startOf - ) @dummy @_.leading.start.startOf @_.domain + (_) @_.trailing.startOf + ) @dummy @_.domain (#not-parent-type? @dummy variable_declaration) ) ;; Handle variable declarations ;;!! local a = 42 ;;! ------^----- ;;! xxxxxxxxxx-- -(_ - local_declaration: (variable_declaration - "local" @_.leading.start.startOf - . - (assignment_statement - (variable_list) @name - (#allow-multiple! @name) - . - "=" - (_) @_.leading.end.startOf - ) - ) @_.domain -) +local_declaration: (variable_declaration + (assignment_statement + (variable_list) @name + (_) @_.removal.end.startOf + ) +) @_.domain @_.removal.start.startOf ;; Handle assignment values ;;!! a = 42 -;;! ----------^^ -;;! -------xxxxx +;;! ----^^ +;;! -xxxxx ( (assignment_statement - (_) @_.leading.start.endOf - . - (expression_list - value: (_) - ) @value @_.leading.end.startOf + (_) @_.leading.endOf + (expression_list) @value ) @dummy @_.domain (#not-parent-type? @dummy variable_declaration) ) @@ -253,17 +239,12 @@ ;;!! local a = 42 ;;! ----------^^ ;;! -------xxxxx -(_ - local_declaration: (variable_declaration - (assignment_statement - (_) @_.leading.start.endOf - . - (expression_list - value: (_) - ) @value @_.leading.end.startOf - ) - ) @_.domain -) +local_declaration: (variable_declaration + (assignment_statement + (_) @_.leading.endOf + (expression_list) @value + ) +) @_.domain ;;!! return a + b ;;! -------^^^^^ From 6695b0b878a041ea5c91a10ad4357424666155a9 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 1 Feb 2024 15:01:11 +0000 Subject: [PATCH 03/18] Update tests --- packages/common/src/scopeSupportFacets/lua.ts | 4 ++++ .../scopeSupportFacetInfos.ts | 13 ++++++++++ .../scopeSupportFacets.types.ts | 3 +++ .../recorded/languages/lua/changeMap.yml | 6 +---- .../fixtures/scopes/lua/name.assignment.scope | 20 ++++++++++++++++ .../fixtures/scopes/lua/name.variable.scope | 24 +++++++++++++++++++ .../scopes/lua/value.assignment.scope | 20 ++++++++++++++++ .../fixtures/scopes/lua/value.variable.scope | 24 +++++++++++++++++++ 8 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/name.assignment.scope create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/name.variable.scope create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.variable.scope diff --git a/packages/common/src/scopeSupportFacets/lua.ts b/packages/common/src/scopeSupportFacets/lua.ts index 73365d2852..2a4499c06b 100644 --- a/packages/common/src/scopeSupportFacets/lua.ts +++ b/packages/common/src/scopeSupportFacets/lua.ts @@ -8,4 +8,8 @@ const { supported, notApplicable } = ScopeSupportFacetLevel; export const luaScopeSupport: LanguageScopeSupportFacetMap = { "key.attribute": notApplicable, tags: notApplicable, + "name.assignment": supported, + "name.variable": supported, + "value.assignment": supported, + "value.variable": supported, }; diff --git a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts index d47086df2c..4ae78a6c7e 100644 --- a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts +++ b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts @@ -223,6 +223,15 @@ export const scopeSupportFacetInfos: Record< description: "LHS of an assignment with pattern destructuring", scopeType: "name", }, + "name.variable": { + description: "Name (LHS) of a variable declaration", + scopeType: "name", + }, + "name.variable.pattern": { + description: + "Name (LHS) of a variable declaration with pattern destructuring", + scopeType: "name", + }, "name.foreach": { description: "Iteration variable name in a for each loop", scopeType: "name", @@ -269,6 +278,10 @@ export const scopeSupportFacetInfos: Record< description: "Value (RHS) of an assignment", scopeType: "value", }, + "value.variable": { + description: "Value (RHS) of a variable declaration", + scopeType: "name", + }, "value.mapPair": { description: "Value (RHS) of a key-value pair in a map", scopeType: "value", diff --git a/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts b/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts index 3adfe5c1ca..1729f23c1b 100644 --- a/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts +++ b/packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts @@ -59,6 +59,8 @@ const scopeSupportFacets = [ "name.assignment", "name.assignment.pattern", + "name.variable", + "name.variable.pattern", "name.foreach", "name.function", "name.class", @@ -71,6 +73,7 @@ const scopeSupportFacets = [ "key.mapPair.iteration", "value.assignment", + "value.variable", "value.mapPair", "value.mapPair.iteration", "value.attribute", diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeMap.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeMap.yml index 66b6f46dc5..d453f1ff21 100644 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeMap.yml +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeMap.yml @@ -16,8 +16,4 @@ initialState: - anchor: {line: 0, character: 18} active: {line: 0, character: 18} marks: {} -finalState: - documentContents: "local table = " - selections: - - anchor: {line: 0, character: 14} - active: {line: 0, character: 14} +thrownError: {name: NoContainingScopeError} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/name.assignment.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/name.assignment.scope new file mode 100644 index 0000000000..d9744b323b --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/name.assignment.scope @@ -0,0 +1,20 @@ +a, b = 1, 2 +--- + +[Content] = 0:0-0:4 +0| a, b = 1, 2 + >----< + +[Removal] = 0:0-0:7 +0| a, b = 1, 2 + >-------< + +[Trailing delimiter] = 0:4-0:7 +0| a, b = 1, 2 + >---< + +[Domain] = 0:0-0:11 +0| a, b = 1, 2 + >-----------< + +[Insertion delimiter] = " " diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/name.variable.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/name.variable.scope new file mode 100644 index 0000000000..d0bfdc8451 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/name.variable.scope @@ -0,0 +1,24 @@ +local a, b = 1, 2 +--- + +[Content] = 0:6-0:10 +0| local a, b = 1, 2 + >----< + +[Removal] = 0:0-0:13 +0| local a, b = 1, 2 + >-------------< + +[Leading delimiter] = 0:5-0:6 +0| local a, b = 1, 2 + >-< + +[Trailing delimiter] = 0:10-0:11 +0| local a, b = 1, 2 + >-< + +[Domain] = 0:0-0:17 +0| local a, b = 1, 2 + >-----------------< + +[Insertion delimiter] = " " diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.assignment.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.assignment.scope index e69de29bb2..30bf2902d2 100644 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.assignment.scope +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.assignment.scope @@ -0,0 +1,20 @@ +a, b = 1, 2 +--- + +[Content] = 0:7-0:11 +0| a, b = 1, 2 + >----< + +[Removal] = 0:4-0:11 +0| a, b = 1, 2 + >-------< + +[Leading delimiter] = 0:4-0:7 +0| a, b = 1, 2 + >---< + +[Domain] = 0:0-0:11 +0| a, b = 1, 2 + >-----------< + +[Insertion delimiter] = " " diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.variable.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.variable.scope new file mode 100644 index 0000000000..d0bfdc8451 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.variable.scope @@ -0,0 +1,24 @@ +local a, b = 1, 2 +--- + +[Content] = 0:6-0:10 +0| local a, b = 1, 2 + >----< + +[Removal] = 0:0-0:13 +0| local a, b = 1, 2 + >-------------< + +[Leading delimiter] = 0:5-0:6 +0| local a, b = 1, 2 + >-< + +[Trailing delimiter] = 0:10-0:11 +0| local a, b = 1, 2 + >-< + +[Domain] = 0:0-0:17 +0| local a, b = 1, 2 + >-----------------< + +[Insertion delimiter] = " " From c965b6f867b04920642f64a06b7e39edf8633657 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 1 Feb 2024 15:04:01 +0000 Subject: [PATCH 04/18] remove lint warnings --- packages/common/src/scopeSupportFacets/lua.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/common/src/scopeSupportFacets/lua.ts b/packages/common/src/scopeSupportFacets/lua.ts index 2a4499c06b..1d0cedf46d 100644 --- a/packages/common/src/scopeSupportFacets/lua.ts +++ b/packages/common/src/scopeSupportFacets/lua.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/naming-convention */ + import { LanguageScopeSupportFacetMap, ScopeSupportFacetLevel, From 9fe3deda4731308be347b7636b36eae8af0ff228 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 1 Feb 2024 15:07:48 +0000 Subject: [PATCH 05/18] better callee test --- packages/common/src/scopeSupportFacets/lua.ts | 1 + .../recorded/languages/lua/changeCallee.yml | 25 ------------------- .../fixtures/scopes/lua/functionCallee.scope | 13 ++++++++++ 3 files changed, 14 insertions(+), 25 deletions(-) delete mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCallee.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/functionCallee.scope diff --git a/packages/common/src/scopeSupportFacets/lua.ts b/packages/common/src/scopeSupportFacets/lua.ts index 1d0cedf46d..5201b07297 100644 --- a/packages/common/src/scopeSupportFacets/lua.ts +++ b/packages/common/src/scopeSupportFacets/lua.ts @@ -14,4 +14,5 @@ export const luaScopeSupport: LanguageScopeSupportFacetMap = { "name.variable": supported, "value.assignment": supported, "value.variable": supported, + functionCallee: supported, }; diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCallee.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCallee.yml deleted file mode 100644 index 2c5a73bf8a..0000000000 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCallee.yml +++ /dev/null @@ -1,25 +0,0 @@ -languageId: lua -command: - version: 6 - spokenForm: change callee - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: functionCallee} - usePrePhraseSnapshot: true -initialState: - documentContents: | - print("a is greater than 10") - selections: - - anchor: {line: 0, character: 0} - active: {line: 0, character: 0} - marks: {} -finalState: - documentContents: | - ("a is greater than 10") - selections: - - anchor: {line: 0, character: 0} - active: {line: 0, character: 0} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/functionCallee.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/functionCallee.scope new file mode 100644 index 0000000000..3e04ab9016 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/functionCallee.scope @@ -0,0 +1,13 @@ +print("a is greater than 10") +--- + +[Content] = +[Removal] = 0:0-0:5 +0| print("a is greater than 10") + >-----< + +[Domain] = 0:0-0:29 +0| print("a is greater than 10") + >-----------------------------< + +[Insertion delimiter] = " " From 80fc5db44b62051a10b42eb761884d8aa09fd6b8 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 1 Feb 2024 15:18:52 +0000 Subject: [PATCH 06/18] more test improvements --- packages/common/src/scopeSupportFacets/lua.ts | 1 + .../src/scopeProviders/getTargetRanges.ts | 13 ++++++-- .../languages/lua/changeCharInsideMap.yml | 33 ------------------- .../src/suite/fixtures/scopes/lua/map.scope | 24 ++++++++++++++ 4 files changed, 35 insertions(+), 36 deletions(-) delete mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCharInsideMap.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/map.scope diff --git a/packages/common/src/scopeSupportFacets/lua.ts b/packages/common/src/scopeSupportFacets/lua.ts index 5201b07297..73de339ca7 100644 --- a/packages/common/src/scopeSupportFacets/lua.ts +++ b/packages/common/src/scopeSupportFacets/lua.ts @@ -15,4 +15,5 @@ export const luaScopeSupport: LanguageScopeSupportFacetMap = { "value.assignment": supported, "value.variable": supported, functionCallee: supported, + map: supported, }; diff --git a/packages/cursorless-engine/src/scopeProviders/getTargetRanges.ts b/packages/cursorless-engine/src/scopeProviders/getTargetRanges.ts index 6e4a7f5a4b..1ae056e296 100644 --- a/packages/cursorless-engine/src/scopeProviders/getTargetRanges.ts +++ b/packages/cursorless-engine/src/scopeProviders/getTargetRanges.ts @@ -1,4 +1,5 @@ import { + NoContainingScopeError, TargetRanges, toCharacterRange, toLineRange, @@ -8,9 +9,12 @@ import { Target } from "../typings/target.types"; export function getTargetRanges(target: Target): TargetRanges { const interior = (() => { try { - target.getInteriorStrict().map(getTargetRanges); + return target.getInteriorStrict().map(getTargetRanges); } catch (error) { - return undefined; + if (error instanceof NoContainingScopeError) { + return undefined; + } + throw error; } })(); @@ -18,7 +22,10 @@ export function getTargetRanges(target: Target): TargetRanges { try { target.getBoundaryStrict().map(getTargetRanges); } catch (error) { - return undefined; + if (error instanceof NoContainingScopeError) { + return undefined; + } + throw error; } })(); diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCharInsideMap.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCharInsideMap.yml deleted file mode 100644 index 28d7688dca..0000000000 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCharInsideMap.yml +++ /dev/null @@ -1,33 +0,0 @@ -languageId: lua -command: - version: 6 - spokenForm: change char inside map - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: character} - - {type: interiorOnly} - - type: containingScope - scopeType: {type: map} - usePrePhraseSnapshot: true -initialState: - documentContents: |- - foo = { - bar = "a", - baz = "b" - } - selections: - - anchor: {line: 2, character: 9} - active: {line: 2, character: 9} - marks: {} -finalState: - documentContents: |- - foo = { - - } - selections: - - anchor: {line: 1, character: 4} - active: {line: 1, character: 4} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/map.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/map.scope new file mode 100644 index 0000000000..08d064cacf --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/map.scope @@ -0,0 +1,24 @@ +foo = { bar = "a", baz = "b" } +--- + +[Content] = +[Domain] = 0:6-0:30 +0| foo = { bar = "a", baz = "b" } + >------------------------< + +[Removal] = 0:5-0:30 +0| foo = { bar = "a", baz = "b" } + >-------------------------< + +[Leading delimiter] = 0:5-0:6 +0| foo = { bar = "a", baz = "b" } + >-< + +[Interior: Content] = 0:8-0:28 +0| foo = { bar = "a", baz = "b" } + >--------------------< +[Interior: Removal] = 0:7-0:29 +0| foo = { bar = "a", baz = "b" } + >----------------------< + +[Insertion delimiter] = " " From ce1a9e76f02519a7b27df50535931b9ce9b853d8 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 1 Feb 2024 15:19:27 +0000 Subject: [PATCH 07/18] more scope test fix --- .../cursorless-engine/src/scopeProviders/getTargetRanges.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cursorless-engine/src/scopeProviders/getTargetRanges.ts b/packages/cursorless-engine/src/scopeProviders/getTargetRanges.ts index 1ae056e296..2abc30136e 100644 --- a/packages/cursorless-engine/src/scopeProviders/getTargetRanges.ts +++ b/packages/cursorless-engine/src/scopeProviders/getTargetRanges.ts @@ -20,7 +20,7 @@ export function getTargetRanges(target: Target): TargetRanges { const boundary = (() => { try { - target.getBoundaryStrict().map(getTargetRanges); + return target.getBoundaryStrict().map(getTargetRanges); } catch (error) { if (error instanceof NoContainingScopeError) { return undefined; From 1ba0936e4552af8a0f49cabdac82e4340685b12b Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 1 Feb 2024 15:23:14 +0000 Subject: [PATCH 08/18] More test cleanup --- packages/common/src/scopeSupportFacets/lua.ts | 1 + .../recorded/languages/lua/changeBranch.yml | 36 ------------- .../recorded/languages/lua/changeBranch2.yml | 36 ------------- .../recorded/languages/lua/changeBranch3.yml | 36 ------------- .../languages/lua/changeInsideBranchPit.yml | 42 --------------- .../lua/changeInsideBranchQuench.yml | 42 --------------- .../languages/lua/changeInsideBranchRed.yml | 42 --------------- .../suite/fixtures/scopes/lua/branch.if.scope | 52 +++++++++++++++++++ 8 files changed, 53 insertions(+), 234 deletions(-) delete mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch.yml delete mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch2.yml delete mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch3.yml delete mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchPit.yml delete mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchQuench.yml delete mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchRed.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/branch.if.scope diff --git a/packages/common/src/scopeSupportFacets/lua.ts b/packages/common/src/scopeSupportFacets/lua.ts index 73de339ca7..f0a4de610a 100644 --- a/packages/common/src/scopeSupportFacets/lua.ts +++ b/packages/common/src/scopeSupportFacets/lua.ts @@ -16,4 +16,5 @@ export const luaScopeSupport: LanguageScopeSupportFacetMap = { "value.variable": supported, functionCallee: supported, map: supported, + "branch.if": supported, }; diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch.yml deleted file mode 100644 index 97d2089bec..0000000000 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch.yml +++ /dev/null @@ -1,36 +0,0 @@ -languageId: lua -command: - version: 6 - spokenForm: change branch - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: branch} - usePrePhraseSnapshot: true -initialState: - documentContents: |- - if a > 10 then - print("a is greater than 10") - elseif a < 10 then - print("a is less than 10") - else - print("a is equal to 10") - end - selections: - - anchor: {line: 2, character: 4} - active: {line: 2, character: 4} - marks: {} -finalState: - documentContents: |- - if a > 10 then - print("a is greater than 10") - - else - print("a is equal to 10") - end - selections: - - anchor: {line: 2, character: 0} - active: {line: 2, character: 0} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch2.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch2.yml deleted file mode 100644 index 344d19afa4..0000000000 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch2.yml +++ /dev/null @@ -1,36 +0,0 @@ -languageId: lua -command: - version: 6 - spokenForm: change branch - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: branch} - usePrePhraseSnapshot: true -initialState: - documentContents: |- - if a > 10 then - print("a is greater than 10") - elseif a < 10 then - print("a is less than 10") - else - print("a is equal to 10") - end - selections: - - anchor: {line: 5, character: 4} - active: {line: 5, character: 4} - marks: {} -finalState: - documentContents: |- - if a > 10 then - print("a is greater than 10") - elseif a < 10 then - print("a is less than 10") - - end - selections: - - anchor: {line: 4, character: 0} - active: {line: 4, character: 0} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch3.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch3.yml deleted file mode 100644 index 2abd7e9b1d..0000000000 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeBranch3.yml +++ /dev/null @@ -1,36 +0,0 @@ -languageId: lua -command: - version: 6 - spokenForm: change branch - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: branch} - usePrePhraseSnapshot: true -initialState: - documentContents: |- - if a > 10 then - print("a is greater than 10") - elseif a < 10 then - print("a is less than 10") - else - print("a is equal to 10") - end - selections: - - anchor: {line: 1, character: 4} - active: {line: 1, character: 4} - marks: {} -finalState: - documentContents: |- - - elseif a < 10 then - print("a is less than 10") - else - print("a is equal to 10") - end - selections: - - anchor: {line: 0, character: 0} - active: {line: 0, character: 0} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchPit.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchPit.yml deleted file mode 100644 index 63e8662a46..0000000000 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchPit.yml +++ /dev/null @@ -1,42 +0,0 @@ -languageId: lua -command: - version: 6 - spokenForm: change inside branch pit - action: - name: clearAndSetSelection - target: - type: primitive - mark: {type: decoratedSymbol, symbolColor: default, character: p} - modifiers: - - {type: interiorOnly} - - type: containingScope - scopeType: {type: branch} - usePrePhraseSnapshot: true -initialState: - documentContents: |- - if x < y then - print("x is less than y") - elseif x > y then - print("x is greater than y") - else - print("x is equal to y") - end - selections: - - anchor: {line: 0, character: 6} - active: {line: 0, character: 6} - marks: - default.p: - start: {line: 1, character: 4} - end: {line: 1, character: 9} -finalState: - documentContents: |- - if x < y then - - elseif x > y then - print("x is greater than y") - else - print("x is equal to y") - end - selections: - - anchor: {line: 1, character: 4} - active: {line: 1, character: 4} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchQuench.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchQuench.yml deleted file mode 100644 index ddac3e9ec0..0000000000 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchQuench.yml +++ /dev/null @@ -1,42 +0,0 @@ -languageId: lua -command: - version: 6 - spokenForm: change inside branch quench - action: - name: clearAndSetSelection - target: - type: primitive - mark: {type: decoratedSymbol, symbolColor: default, character: q} - modifiers: - - {type: interiorOnly} - - type: containingScope - scopeType: {type: branch} - usePrePhraseSnapshot: true -initialState: - documentContents: |- - if x < y then - print("x is less than y") - elseif x > y then - print("x is greater than y") - else - print("x is equal to y") - end - selections: - - anchor: {line: 0, character: 6} - active: {line: 0, character: 6} - marks: - default.q: - start: {line: 5, character: 16} - end: {line: 5, character: 21} -finalState: - documentContents: |- - if x < y then - print("x is less than y") - elseif x > y then - print("x is greater than y") - else - - end - selections: - - anchor: {line: 5, character: 4} - active: {line: 5, character: 4} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchRed.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchRed.yml deleted file mode 100644 index 18470e015b..0000000000 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideBranchRed.yml +++ /dev/null @@ -1,42 +0,0 @@ -languageId: lua -command: - version: 6 - spokenForm: change inside branch red - action: - name: clearAndSetSelection - target: - type: primitive - mark: {type: decoratedSymbol, symbolColor: default, character: r} - modifiers: - - {type: interiorOnly} - - type: containingScope - scopeType: {type: branch} - usePrePhraseSnapshot: true -initialState: - documentContents: |- - if x < y then - print("x is less than y") - elseif x > y then - print("x is greater than y") - else - print("x is equal to y") - end - selections: - - anchor: {line: 0, character: 6} - active: {line: 0, character: 6} - marks: - default.r: - start: {line: 3, character: 4} - end: {line: 3, character: 9} -finalState: - documentContents: |- - if x < y then - print("x is less than y") - elseif x > y then - - else - print("x is equal to y") - end - selections: - - anchor: {line: 3, character: 4} - active: {line: 3, character: 4} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/branch.if.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/branch.if.scope new file mode 100644 index 0000000000..cf80a40f00 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/branch.if.scope @@ -0,0 +1,52 @@ +if x < y then + print("x is less than y") +elseif x > y then + print("x is greater than y") +else + print("x is equal to y") +end +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:0-1:29 +0| if x < y then + >------------- +1| print("x is less than y") + -----------------------------< + +[#1 Interior] = 1:4-1:29 +1| print("x is less than y") + >-------------------------< + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Removal] = +[#2 Domain] = 2:0-3:32 +2| elseif x > y then + >----------------- +3| print("x is greater than y") + --------------------------------< + +[#2 Interior] = 3:4-3:32 +3| print("x is greater than y") + >----------------------------< + +[#2 Insertion delimiter] = "\n" + + +[#3 Content] = +[#3 Removal] = +[#3 Domain] = 4:0-5:28 +4| else + >---- +5| print("x is equal to y") + ----------------------------< + +[#3 Interior] = 5:4-5:28 +5| print("x is equal to y") + >------------------------< + +[#3 Insertion delimiter] = "\n" From a0b65293b967d09ac7cfc8b8a8058d8ac410d593 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 1 Feb 2024 15:26:04 +0000 Subject: [PATCH 09/18] more test cleanup --- packages/common/src/scopeSupportFacets/lua.ts | 1 + .../recorded/languages/lua/changeFunk.yml | 26 ------------ .../languages/lua/changeInsideFunk.yml | 34 ---------------- .../fixtures/scopes/lua/namedFunction.scope | 40 +++++++++++++++++++ 4 files changed, 41 insertions(+), 60 deletions(-) delete mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeFunk.yml delete mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideFunk.yml create mode 100644 packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/namedFunction.scope diff --git a/packages/common/src/scopeSupportFacets/lua.ts b/packages/common/src/scopeSupportFacets/lua.ts index f0a4de610a..17e2bd8d12 100644 --- a/packages/common/src/scopeSupportFacets/lua.ts +++ b/packages/common/src/scopeSupportFacets/lua.ts @@ -17,4 +17,5 @@ export const luaScopeSupport: LanguageScopeSupportFacetMap = { functionCallee: supported, map: supported, "branch.if": supported, + namedFunction: supported, }; diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeFunk.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeFunk.yml deleted file mode 100644 index 3c61d6d9cc..0000000000 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeFunk.yml +++ /dev/null @@ -1,26 +0,0 @@ -languageId: lua -command: - version: 6 - spokenForm: change funk - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - type: containingScope - scopeType: {type: namedFunction} - usePrePhraseSnapshot: true -initialState: - documentContents: |- - function add(x, b) - return x + y - end - selections: - - anchor: {line: 1, character: 7} - active: {line: 1, character: 7} - marks: {} -finalState: - documentContents: "" - selections: - - anchor: {line: 0, character: 0} - active: {line: 0, character: 0} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideFunk.yml b/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideFunk.yml deleted file mode 100644 index dd84f6ca05..0000000000 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeInsideFunk.yml +++ /dev/null @@ -1,34 +0,0 @@ -languageId: lua -command: - version: 6 - spokenForm: change inside funk - action: - name: clearAndSetSelection - target: - type: primitive - modifiers: - - {type: interiorOnly} - - type: containingScope - scopeType: {type: namedFunction} - usePrePhraseSnapshot: true -initialState: - documentContents: |- - function makeCounter() - local count = 0 - return function() - count = count + 1 - return count - end - end - selections: - - anchor: {line: 1, character: 19} - active: {line: 1, character: 19} - marks: {} -finalState: - documentContents: |- - function makeCounter() - - end - selections: - - anchor: {line: 1, character: 4} - active: {line: 1, character: 4} diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/namedFunction.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/namedFunction.scope new file mode 100644 index 0000000000..97bc3f8074 --- /dev/null +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/namedFunction.scope @@ -0,0 +1,40 @@ +function makeCounter() + local count = 0 + return function() + count = count + 1 + return count + end +end +--- + +[Content] = +[Removal] = +[Domain] = 0:0-6:3 +0| function makeCounter() + >---------------------- +1| local count = 0 + ------------------- +2| return function() + --------------------- +3| count = count + 1 + ------------------------- +4| return count + -------------------- +5| end + ------- +6| end + ---< + +[Interior] = 1:4-5:7 +1| local count = 0 + >--------------- +2| return function() + --------------------- +3| count = count + 1 + ------------------------- +4| return count + -------------------- +5| end + -------< + +[Insertion delimiter] = "\n\n" From 58627454e56dfa5ad4067c13c5c569f36b07549a Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 1 Feb 2024 15:30:29 +0000 Subject: [PATCH 10/18] fix --- queries/lua.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queries/lua.scm b/queries/lua.scm index 9cba124391..b31a210ede 100644 --- a/queries/lua.scm +++ b/queries/lua.scm @@ -31,7 +31,7 @@ [ (block) (chunk) -] @ifStatement.iteration @value.iteration +] @ifStatement.iteration @value.iteration @name.iteration ;; Capture assignment only if without variable prefix ;;!! count = count + 1 From 1b4fa029f0409bdfc5e66ea0d586564f4ed30805 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 1 Feb 2024 15:41:34 +0000 Subject: [PATCH 11/18] more cleanup --- queries/lua.scm | 58 ++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/queries/lua.scm b/queries/lua.scm index b31a210ede..2792939a9f 100644 --- a/queries/lua.scm +++ b/queries/lua.scm @@ -97,26 +97,23 @@ ;; Lists and maps (table_constructor - "{" @_.interior.start.endOf @value.iteration.start.endOf + "{" @_.interior.start.endOf @value.iteration.start.endOf @collectionKey.iteration.start.endOf (field name: (_) ) - "}" @_.interior.end.startOf @value.iteration.end.startOf -) @map @collectionKey.iteration + "}" @_.interior.end.startOf @value.iteration.end.startOf @collectionKey.iteration.end.startOf +) @map ;;!! a = { foo = "bar" } ;;! ^^^-------- ;;! xxxxxx----- -(field - name: (_) @collectionKey @_.trailing.start.endOf - value: (_) @_.trailing.end.startOf -) @_.domain ;;!! a = { foo = "bar" } ;;! ------^^^^^ ;;! ---xxxxxxxx (field - name: (_) @_.leading.start.endOf - value: (_) @value @_.leading.end.startOf + name: (_) @collectionKey @value.leading.endOf + value: (_) @value @collectionKey.trailing.startOf ) @_.domain + ;; In lua everything is a map, but a map that omits keys for entries ;; is similar enough to a list to warrant having that scope. ;;!! a = { "1", "2", "3" } @@ -151,27 +148,38 @@ ;;! ^--- ;;! xxx- (arguments - "(" @_.iteration.start.endOf - (_)? @_.leading.start.endOf + (_)? @_.leading.endOf . - (_) @argumentOrParameter @_.leading.end.startOf @_.trailing.start.endOf + (_) @argumentOrParameter . - (_)? @_.trailing.end.startOf - ")" @_.iteration.end.startOf - (#insertion-delimiter! @argumentOrParameter ", ") + (_)? @_.trailing.startOf + (#single-or-multi-line-delimiter! @argumentOrParameter @dummy ", " ",\n") +) + +;;!!local sum = add(5, 7) +;;! **** +(arguments + "(" @argumentOrParameter.iteration.start.endOf + ")" @argumentOrParameter.iteration.end.startOf ) + ;;!!function add(5, 7) ;;! ^--- ;;! xxx- (parameters - "(" @_.iteration.start.endOf - (_)? @_.leading.start.endOf + (_)? @_.leading.endOf . - (_) @argumentOrParameter @_.leading.end.startOf @_.trailing.start.endOf + (_) @argumentOrParameter . - (_)? @_.trailing.end.startOf - ")" @_.iteration.end.startOf - (#insertion-delimiter! @argumentOrParameter ", ") + (_)? @_.trailing.startOf + (#single-or-multi-line-delimiter! @argumentOrParameter @dummy ", " ",\n") +) + +;;!!function add(5, 7) +;;! **** +(parameters + "(" @argumentOrParameter.iteration.start.endOf + ")" @argumentOrParameter.iteration.end.startOf ) ;; funk name: @@ -185,8 +193,8 @@ ;;! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (function_declaration name: (_) @functionName - body: (_)? @namedFunction.interior @ifStatement.iteration @item.iteration -) @_.domain @namedFunction + body: (_)? @namedFunction.interior +) @functionName.domain @namedFunction ;; inside lambda: ;;!! __add = function(a, b) return a + b end @@ -196,8 +204,8 @@ ;;! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ (function_definition !name - body: (_)? @anonymousFunction.interior @ifStatement.iteration -) @_.domain @anonymousFunction + body: (_)? @_.interior +) @anonymousFunction ;; Names and values From 4a530564a21fb77e339d3ab08153558593ca5090 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 1 Feb 2024 15:43:18 +0000 Subject: [PATCH 12/18] more cleanup --- queries/lua.scm | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/queries/lua.scm b/queries/lua.scm index 2792939a9f..0988bfe39e 100644 --- a/queries/lua.scm +++ b/queries/lua.scm @@ -147,12 +147,14 @@ ;;!!local sum = add(5, 7) ;;! ^--- ;;! xxx- -(arguments - (_)? @_.leading.endOf - . - (_) @argumentOrParameter - . - (_)? @_.trailing.startOf +( + (arguments + (_)? @_.leading.endOf + . + (_) @argumentOrParameter + . + (_)? @_.trailing.startOf + ) @dummy (#single-or-multi-line-delimiter! @argumentOrParameter @dummy ", " ",\n") ) @@ -166,12 +168,14 @@ ;;!!function add(5, 7) ;;! ^--- ;;! xxx- -(parameters - (_)? @_.leading.endOf - . - (_) @argumentOrParameter - . - (_)? @_.trailing.startOf +( + (parameters + (_)? @_.leading.endOf + . + (_) @argumentOrParameter + . + (_)? @_.trailing.startOf + ) @dummy (#single-or-multi-line-delimiter! @argumentOrParameter @dummy ", " ",\n") ) From 14794c32060b115222d271d2d0c27f54ddf85814 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Thu, 1 Feb 2024 16:09:31 +0000 Subject: [PATCH 13/18] whoops --- .../scopeSupportFacets/scopeSupportFacetInfos.ts | 2 +- .../fixtures/scopes/lua/value.variable.scope | 16 ++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts index 4ae78a6c7e..7dcc5f6325 100644 --- a/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts +++ b/packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts @@ -280,7 +280,7 @@ export const scopeSupportFacetInfos: Record< }, "value.variable": { description: "Value (RHS) of a variable declaration", - scopeType: "name", + scopeType: "value", }, "value.mapPair": { description: "Value (RHS) of a key-value pair in a map", diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.variable.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.variable.scope index d0bfdc8451..f82a90ea1d 100644 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.variable.scope +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.variable.scope @@ -1,21 +1,17 @@ local a, b = 1, 2 --- -[Content] = 0:6-0:10 +[Content] = 0:13-0:17 0| local a, b = 1, 2 - >----< + >----< -[Removal] = 0:0-0:13 +[Removal] = 0:10-0:17 0| local a, b = 1, 2 - >-------------< + >-------< -[Leading delimiter] = 0:5-0:6 +[Leading delimiter] = 0:10-0:13 0| local a, b = 1, 2 - >-< - -[Trailing delimiter] = 0:10-0:11 -0| local a, b = 1, 2 - >-< + >---< [Domain] = 0:0-0:17 0| local a, b = 1, 2 From f680701df0f2b9883d9d6bc802f5a8c9b1d1da2c Mon Sep 17 00:00:00 2001 From: FidgetingBits Date: Tue, 5 Mar 2024 10:18:37 +0800 Subject: [PATCH 14/18] fix conditional test cases --- data/playground/lua/lua.lua | 72 ++++++++++++++++++++----------------- queries/lua.scm | 30 +++++++++++++++- 2 files changed, 68 insertions(+), 34 deletions(-) diff --git a/data/playground/lua/lua.lua b/data/playground/lua/lua.lua index cf18bd7cfe..7673cb7220 100644 --- a/data/playground/lua/lua.lua +++ b/data/playground/lua/lua.lua @@ -1,4 +1,3 @@ - -- This is a single-line comment --[[ @@ -14,7 +13,7 @@ local b, c = "Hello", "World" local number = 3.14 local boolean = true local string = "Lua is awesome!" -local table = {1, 2, 3} +local table = { 1, 2, 3 } local nilValue = nil -- Conditional Constructs @@ -23,11 +22,11 @@ local y = 20 -- if-then-else if x < y then - print("x is less than y") + print("x is less than y") elseif x > y then - print("x is greater than y") + print("x is greater than y") else - print("x is equal to y") + print("x is equal to y") end -- ternary conditional (short if-then-else) @@ -36,7 +35,7 @@ print("The maximum value is: " .. max) -- Functions function add(x, b) - return x + y + return x + y end local sum = add(5, 7) @@ -44,13 +43,13 @@ print("Sum:", sum) -- Tables local person = { - name = "John", - age = 30, - hobbies = {"reading", "gaming", "programming"}, - address = { - street = "123 Main St", - city = "Example City" - } + name = "John", + age = 30, + hobbies = { "reading", "gaming", "programming" }, + address = { + street = "123 Main St", + city = "Example City", + }, } -- String manipulation @@ -58,38 +57,42 @@ local concatString = "Hello " .. "World" -- Metatables and metatable operations local mt = { - __add = function(a, b) return a + b end, - __sub = function(a, b) return a - b end + __add = function(a, b) + return a + b + end, + __sub = function(a, b) + return a - b + end, } setmetatable(a, mt) -- Closures function makeCounter() - local count = 0 - return function() - count = count + 1 - return count - end + local count = 0 + return function() + count = count + 1 + return count + end end local counter = makeCounter() -- Coroutines local co = coroutine.create(function() - for i = 1, 3 do - print("Coroutine", i) - coroutine.yield() - end + for i = 1, 3 do + print("Coroutine", i) + coroutine.yield() + end end) -- Error handling local success, result = pcall(function() - error("This is an error") + error("This is an error") end) if not success then - print("Error:", result) + print("Error:", result) end -- Loop Constructs @@ -97,29 +100,32 @@ end local i = 1 i = 2 while i <= 5 do - print("While loop iteration: " .. i) - i = i + 1 + print("While loop iteration: " .. i) + i = i + 1 end -- repeat-until loop i = 1 repeat - print("Repeat-Until loop iteration: " .. i) - i = i + 1 + print("Repeat-Until loop iteration: " .. i) + i = i + 1 until i > 5 -- for loop for j = 1, 5 do - print("For loop iteration: " .. j) + print("For loop iteration: " .. j) end -- numeric for loop with step for k = 10, 1, -1 do - print("Numeric for loop with step: " .. k) + print("Numeric for loop with step: " .. k) end -- for-in loop (iterating over a table) local fruits = { "apple", "banana", "cherry" } for key, value in pairs(fruits) do - print("For-In loop: " .. key .. " = " .. value) + print("For-In loop: " .. key .. " = " .. value) end + +-- ternary +local max = x > y and x or y diff --git a/queries/lua.scm b/queries/lua.scm index 0988bfe39e..2ea31ef013 100644 --- a/queries/lua.scm +++ b/queries/lua.scm @@ -27,7 +27,7 @@ (chunk) ] @statement.iteration @namedFunction.iteration @functionCall.iteration -;; Duplicate with above, due to 3 label node limit +;; Duplicate above due to 3 label node limit [ (block) (chunk) @@ -95,6 +95,22 @@ ) ] @branch @_.domain +;;!! while i <= 5 do +;;! ^^^^^^ +;;! xxxxxx +(while_statement + condition: (_) @condition +) @_.domain + +;;!! repeat +;;!! ... +;;!! until i > 5 +;;! ^^^^^ +;;! xxxxx +(repeat_statement + condition: (_) @condition +) @_.domain + ;; Lists and maps (table_constructor "{" @_.interior.start.endOf @value.iteration.start.endOf @collectionKey.iteration.start.endOf @@ -265,6 +281,18 @@ local_declaration: (variable_declaration (_) @value ) @_.domain +;; match a ternary condition +;;!! local max = x > y and x or y +;;! ^^^^^ +;;! xxxxx +(binary_expression + left: (binary_expression + left: (binary_expression) @condition + . + "and" + ) +) + ;; Structures and object access ;; (method_index_expression) @private.fieldAccess From 06aae3bc5f02a79e135a924befa7628625bfea1b Mon Sep 17 00:00:00 2001 From: FidgetingBits Date: Tue, 12 Mar 2024 16:02:36 +0800 Subject: [PATCH 15/18] add lua dependency to see if it fixes tests --- packages/common/src/extensionDependencies.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/common/src/extensionDependencies.ts b/packages/common/src/extensionDependencies.ts index 5139c3b3a7..33bcce39e6 100644 --- a/packages/common/src/extensionDependencies.ts +++ b/packages/common/src/extensionDependencies.ts @@ -6,6 +6,7 @@ export const extensionDependencies = [ "scala-lang.scala", // scala "mrob95.vscode-talonscript", // talon "jrieken.vscode-tree-sitter-query", // scm + "sumneko.lua", // lua // Necessary for the `drink cell` and `pour cell` tests "ms-toolsai.jupyter", From 6a305db0daf9b027c5650ab4e4670d8058d78541 Mon Sep 17 00:00:00 2001 From: FidgetingBits Date: Sat, 16 Mar 2024 11:31:56 +0800 Subject: [PATCH 16/18] Revert "add lua dependency to see if it fixes tests" This reverts commit 06aae3bc5f02a79e135a924befa7628625bfea1b. --- packages/common/src/extensionDependencies.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/common/src/extensionDependencies.ts b/packages/common/src/extensionDependencies.ts index 33bcce39e6..5139c3b3a7 100644 --- a/packages/common/src/extensionDependencies.ts +++ b/packages/common/src/extensionDependencies.ts @@ -6,7 +6,6 @@ export const extensionDependencies = [ "scala-lang.scala", // scala "mrob95.vscode-talonscript", // talon "jrieken.vscode-tree-sitter-query", // scm - "sumneko.lua", // lua // Necessary for the `drink cell` and `pour cell` tests "ms-toolsai.jupyter", From e801c8553ec5d837f9d866df70c22a657a3d7128 Mon Sep 17 00:00:00 2001 From: FidgetingBits Date: Sun, 17 Mar 2024 17:54:02 +0800 Subject: [PATCH 17/18] switch @dummy to @_dummy to see if addresses errors, and to match other .scm files --- queries/lua.scm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/queries/lua.scm b/queries/lua.scm index 2ea31ef013..82d413e820 100644 --- a/queries/lua.scm +++ b/queries/lua.scm @@ -170,8 +170,8 @@ (_) @argumentOrParameter . (_)? @_.trailing.startOf - ) @dummy - (#single-or-multi-line-delimiter! @argumentOrParameter @dummy ", " ",\n") + ) @_dummy + (#single-or-multi-line-delimiter! @argumentOrParameter @_dummy ", " ",\n") ) ;;!!local sum = add(5, 7) @@ -191,8 +191,8 @@ (_) @argumentOrParameter . (_)? @_.trailing.startOf - ) @dummy - (#single-or-multi-line-delimiter! @argumentOrParameter @dummy ", " ",\n") + ) @_dummy + (#single-or-multi-line-delimiter! @argumentOrParameter @_dummy ", " ",\n") ) ;;!!function add(5, 7) @@ -237,8 +237,8 @@ (assignment_statement (variable_list) @name (_) @_.trailing.startOf - ) @dummy @_.domain - (#not-parent-type? @dummy variable_declaration) + ) @_dummy @_.domain + (#not-parent-type? @_dummy variable_declaration) ) ;; Handle variable declarations ;;!! local a = 42 @@ -259,8 +259,8 @@ local_declaration: (variable_declaration (assignment_statement (_) @_.leading.endOf (expression_list) @value - ) @dummy @_.domain - (#not-parent-type? @dummy variable_declaration) + ) @_dummy @_.domain + (#not-parent-type? @_dummy variable_declaration) ) ;; Handle variable declaration values From 62b0517e0fbcef0c49479b3f7bbcf6bf625e6433 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Tue, 19 Mar 2024 17:17:54 +0000 Subject: [PATCH 18/18] update scope test fixtures --- .../src/suite/fixtures/scopes/lua/branch.if.scope | 12 ++++++------ .../suite/fixtures/scopes/lua/functionCallee.scope | 4 ++-- .../src/suite/fixtures/scopes/lua/map.scope | 10 +++++----- .../suite/fixtures/scopes/lua/name.assignment.scope | 8 ++++---- .../suite/fixtures/scopes/lua/name.variable.scope | 10 +++++----- .../suite/fixtures/scopes/lua/namedFunction.scope | 12 ++---------- .../suite/fixtures/scopes/lua/value.assignment.scope | 8 ++++---- .../suite/fixtures/scopes/lua/value.variable.scope | 8 ++++---- 8 files changed, 32 insertions(+), 40 deletions(-) diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/branch.if.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/branch.if.scope index cf80a40f00..20e001180e 100644 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/branch.if.scope +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/branch.if.scope @@ -10,14 +10,14 @@ end [#1 Content] = [#1 Removal] = [#1 Domain] = 0:0-1:29 -0| if x < y then >------------- +0| if x < y then 1| print("x is less than y") -----------------------------< [#1 Interior] = 1:4-1:29 -1| print("x is less than y") >-------------------------< +1| print("x is less than y") [#1 Insertion delimiter] = "\n" @@ -25,14 +25,14 @@ end [#2 Content] = [#2 Removal] = [#2 Domain] = 2:0-3:32 -2| elseif x > y then >----------------- +2| elseif x > y then 3| print("x is greater than y") --------------------------------< [#2 Interior] = 3:4-3:32 -3| print("x is greater than y") >----------------------------< +3| print("x is greater than y") [#2 Insertion delimiter] = "\n" @@ -40,13 +40,13 @@ end [#3 Content] = [#3 Removal] = [#3 Domain] = 4:0-5:28 -4| else >---- +4| else 5| print("x is equal to y") ----------------------------< [#3 Interior] = 5:4-5:28 -5| print("x is equal to y") >------------------------< +5| print("x is equal to y") [#3 Insertion delimiter] = "\n" diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/functionCallee.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/functionCallee.scope index 3e04ab9016..d922c928de 100644 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/functionCallee.scope +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/functionCallee.scope @@ -3,11 +3,11 @@ print("a is greater than 10") [Content] = [Removal] = 0:0-0:5 -0| print("a is greater than 10") >-----< +0| print("a is greater than 10") [Domain] = 0:0-0:29 -0| print("a is greater than 10") >-----------------------------< +0| print("a is greater than 10") [Insertion delimiter] = " " diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/map.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/map.scope index 08d064cacf..cbb86ec2a4 100644 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/map.scope +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/map.scope @@ -3,22 +3,22 @@ foo = { bar = "a", baz = "b" } [Content] = [Domain] = 0:6-0:30 -0| foo = { bar = "a", baz = "b" } >------------------------< +0| foo = { bar = "a", baz = "b" } [Removal] = 0:5-0:30 -0| foo = { bar = "a", baz = "b" } >-------------------------< +0| foo = { bar = "a", baz = "b" } [Leading delimiter] = 0:5-0:6 -0| foo = { bar = "a", baz = "b" } >-< +0| foo = { bar = "a", baz = "b" } [Interior: Content] = 0:8-0:28 -0| foo = { bar = "a", baz = "b" } >--------------------< -[Interior: Removal] = 0:7-0:29 0| foo = { bar = "a", baz = "b" } +[Interior: Removal] = 0:7-0:29 >----------------------< +0| foo = { bar = "a", baz = "b" } [Insertion delimiter] = " " diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/name.assignment.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/name.assignment.scope index d9744b323b..b74dbc1331 100644 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/name.assignment.scope +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/name.assignment.scope @@ -2,19 +2,19 @@ a, b = 1, 2 --- [Content] = 0:0-0:4 -0| a, b = 1, 2 >----< +0| a, b = 1, 2 [Removal] = 0:0-0:7 -0| a, b = 1, 2 >-------< +0| a, b = 1, 2 [Trailing delimiter] = 0:4-0:7 -0| a, b = 1, 2 >---< +0| a, b = 1, 2 [Domain] = 0:0-0:11 -0| a, b = 1, 2 >-----------< +0| a, b = 1, 2 [Insertion delimiter] = " " diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/name.variable.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/name.variable.scope index d0bfdc8451..0636e4e0dc 100644 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/name.variable.scope +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/name.variable.scope @@ -2,23 +2,23 @@ local a, b = 1, 2 --- [Content] = 0:6-0:10 -0| local a, b = 1, 2 >----< +0| local a, b = 1, 2 [Removal] = 0:0-0:13 -0| local a, b = 1, 2 >-------------< +0| local a, b = 1, 2 [Leading delimiter] = 0:5-0:6 -0| local a, b = 1, 2 >-< +0| local a, b = 1, 2 [Trailing delimiter] = 0:10-0:11 -0| local a, b = 1, 2 >-< +0| local a, b = 1, 2 [Domain] = 0:0-0:17 -0| local a, b = 1, 2 >-----------------< +0| local a, b = 1, 2 [Insertion delimiter] = " " diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/namedFunction.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/namedFunction.scope index 97bc3f8074..a869646a86 100644 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/namedFunction.scope +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/namedFunction.scope @@ -10,30 +10,22 @@ end [Content] = [Removal] = [Domain] = 0:0-6:3 -0| function makeCounter() >---------------------- +0| function makeCounter() 1| local count = 0 - ------------------- 2| return function() - --------------------- 3| count = count + 1 - ------------------------- 4| return count - -------------------- 5| end - ------- 6| end ---< [Interior] = 1:4-5:7 -1| local count = 0 >--------------- +1| local count = 0 2| return function() - --------------------- 3| count = count + 1 - ------------------------- 4| return count - -------------------- 5| end -------< diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.assignment.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.assignment.scope index 30bf2902d2..6c167887b4 100644 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.assignment.scope +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.assignment.scope @@ -2,19 +2,19 @@ a, b = 1, 2 --- [Content] = 0:7-0:11 -0| a, b = 1, 2 >----< +0| a, b = 1, 2 [Removal] = 0:4-0:11 -0| a, b = 1, 2 >-------< +0| a, b = 1, 2 [Leading delimiter] = 0:4-0:7 -0| a, b = 1, 2 >---< +0| a, b = 1, 2 [Domain] = 0:0-0:11 -0| a, b = 1, 2 >-----------< +0| a, b = 1, 2 [Insertion delimiter] = " " diff --git a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.variable.scope b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.variable.scope index f82a90ea1d..925e70be86 100644 --- a/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.variable.scope +++ b/packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/lua/value.variable.scope @@ -2,19 +2,19 @@ local a, b = 1, 2 --- [Content] = 0:13-0:17 -0| local a, b = 1, 2 >----< +0| local a, b = 1, 2 [Removal] = 0:10-0:17 -0| local a, b = 1, 2 >-------< +0| local a, b = 1, 2 [Leading delimiter] = 0:10-0:13 -0| local a, b = 1, 2 >---< +0| local a, b = 1, 2 [Domain] = 0:0-0:17 -0| local a, b = 1, 2 >-----------------< +0| local a, b = 1, 2 [Insertion delimiter] = " "