Initial lua support (#1962)

## What

Adds support for the `lua` programming language

## Checklist

- [x] Recorded tests for the new language
- [x] Used `"change"` / `"clear"` instead of` "take"` for selection
tests to make recorded tests easier to read
- [x] Added a few specific tests that use `"chuck"` instead of
`"change"` to test removal behaviour when it's interesting, especially:
  - [x] `"chuck arg"` with single argument in list
  - [x] `"chuck arg"` with multiple arguments in list
  - [x] `"chuck item"` with single argument in list
  - [x] `"chuck item"` with multiple arguments in list
- [x] Added `@textFragment` captures. Usually you want to put these on
comment and string nodes. This enables `"take round"` to work within
comments and strings.
- [x] Added a test for `"change round"` inside a string, eg `"hello
(there)"`
- [-] Supported` "type"` both for type annotations (eg `foo: string`)
and declarations (eg `interface Foo {}`) (and added tests for this
behaviour 😊)
- [x] Supported` "item"` both for map pairs and list entries (with tests
of course)

## Scope Support

| Supported | Tested | Term | Capture | Definition | Comment |
| - | - | - | - | - | - |
| ✓ | ✓ | `list` | `@list` | List type equivalent | - |
| ✓ | ✓ | `inside list` | `@list.interior` | Inside of a
list | - |
| ✓ | ✓ | `map` | `@map` | Dictionary type equivalent | - |
| ✓ | ✓ | `inside map` | `@map.interior` | Inside of a
dictionary | - |
| ✓ | ✓ | `key` | `@collectionKey` | Dictionary key
equivalent | - |
| ✓ | ✓ | `funk` | `@namedFunction` | A named function
declaration | - |
| ✓ | ✓ | `inside funk` | `@namedFunction.interior` | The
inside of a lambda declaration | - |
| ✓ | ✓ | `funk name` | `@functionName` | Name of declared
function | - |
| ✓ | ✓ | `lambda` | `@anonymousFunction` | A lambda
declaration | - |
| ✓ | ✓ | `inside lambda` | `@anonymousFunction.interior` |
The inside of a lambda declaration | - |
| ✓ | ✓ | `name` | `@name` | Variable name | - |
| ✓ | ✓ | `value` | `@value` | Right-hand-side value of an
assignment | - |
| ✓ | ✓ | `value` | `@value` | Value returned from a
function | - |
| ✓ | ✓ | `value` | `@value` | Value of a key-value pair | -
|
| ✓ | ✓ | `state` | `@statement` | Any single coded
statement | - |
| ✓ | ✓ | `if state` | `@ifStatement` | An if conditional
block | - |
| ✓ | ✓ | `condition` | `@condition` | Condition of an if
block | - |
| ✓ | ✓ | `condition` | `@condition` | Condition of a while
loop | - |
| ✓ | ✓ | `condition` | `@condition` | Condition of a do
while style loop | - |
| - | - | `condition` | `@condition` | Condition of a for loop | - |
| ✓ | ✓ | `condition` | `@condition` | Condition of a
ternary expression | - |
| ✓ | ✓ | `branch` | `@branch` | The resulting code
associated with a conditional expression | - |
| ✓ | ✓ | `comment` | `@comment` | Code comment | - |
| ✓ | ✓ | `string` | `@string` | Single line strings | - |
| ✗ | ✗ | `string` | `@string` | Multi-line strings |
https://github.com/cursorless-dev/cursorless/pull/1962#issuecomment-1783674916
|
| ✓ | ✓ | - | `@textFragment` | Used to capture string-type
nodes (strings and comments) | - |
| ✓ | ✓ | `call` | `@functionCall` | A function call (not a
function definition) | - |
| ✓ | ✓ | `callee` | `@functionCallee` | Name of the
function being called | - |
| ✓ | ✓ | `arg` | `@argumentOrParameter` | Arguments to
functions and calls | - |
| _ | _ | `class` | `@class` | Class or structure declaration | - |
| _ | _ | `inside class` | `@class.interior` | The inside of a class
declaration | - |
| _ | _ | `class name` | `@className` | Name of class or structure
declaration | - |
| _ | _ | `type` | `@type` | Type declarations | - |

---------

Co-authored-by: fidgetingbits <fidgetingbits@memeoid.cx>
Co-authored-by: Pokey Rule <755842+pokey@users.noreply.github.com>
This commit is contained in:
Aaron Adams 2024-03-20 01:26:38 +08:00 committed by GitHub
parent 1c18476c85
commit aa768597e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
54 changed files with 1901 additions and 0 deletions

131
data/playground/lua/lua.lua Normal file
View File

@ -0,0 +1,131 @@
-- 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
-- ternary
local max = x > y and x or y

View File

@ -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}'`);
}

View File

@ -0,0 +1,21 @@
/* eslint-disable @typescript-eslint/naming-convention */
import {
LanguageScopeSupportFacetMap,
ScopeSupportFacetLevel,
} from "./scopeSupportFacets.types";
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,
functionCallee: supported,
map: supported,
"branch.if": supported,
namedFunction: supported,
};

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -0,0 +1,19 @@
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: {}
thrownError: {name: NoContainingScopeError}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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}

View File

@ -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"

View File

@ -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] = " "

View File

@ -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] = " "

View File

@ -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] = " "

View File

@ -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] = " "

View File

@ -0,0 +1,32 @@
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"

View File

@ -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] = " "

View File

@ -0,0 +1,20 @@
local a, b = 1, 2
---
[Content] = 0:13-0:17
>----<
0| local a, b = 1, 2
[Removal] = 0:10-0:17
>-------<
0| local a, b = 1, 2
[Leading delimiter] = 0:10-0:13
>---<
0| local a, b = 1, 2
[Domain] = 0:0-0:17
>-----------------<
0| local a, b = 1, 2
[Insertion delimiter] = " "

298
queries/lua.scm Normal file
View File

@ -0,0 +1,298 @@
;; 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 above due to 3 label node limit
[
(block)
(chunk)
] @ifStatement.iteration @value.iteration @name.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
;;!! 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
(field
name: (_)
)
"}" @_.interior.end.startOf @value.iteration.end.startOf @collectionKey.iteration.end.startOf
) @map
;;!! a = { foo = "bar" }
;;! ^^^--------
;;! xxxxxx-----
;;!! a = { foo = "bar" }
;;! ------^^^^^
;;! ---xxxxxxxx
(field
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" }
;;! ^^^^^^^^^^^^^^^^^
(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
(_)? @_.leading.endOf
.
(_) @argumentOrParameter
.
(_)? @_.trailing.startOf
) @_dummy
(#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
(_)? @_.leading.endOf
.
(_) @argumentOrParameter
.
(_)? @_.trailing.startOf
) @_dummy
(#single-or-multi-line-delimiter! @argumentOrParameter @_dummy ", " ",\n")
)
;;!!function add(5, 7)
;;! ****
(parameters
"(" @argumentOrParameter.iteration.start.endOf
")" @argumentOrParameter.iteration.end.startOf
)
;; 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
) @functionName.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: (_)? @_.interior
) @anonymousFunction
;; Names and values
;; Handle variable assignments
;;!! a = 42
;;! ^-----
;;! xxxx--
(
(assignment_statement
(variable_list) @name
(_) @_.trailing.startOf
) @_dummy @_.domain
(#not-parent-type? @_dummy variable_declaration)
)
;; Handle variable declarations
;;!! local a = 42
;;! ------^-----
;;! xxxxxxxxxx--
local_declaration: (variable_declaration
(assignment_statement
(variable_list) @name
(_) @_.removal.end.startOf
)
) @_.domain @_.removal.start.startOf
;; Handle assignment values
;;!! a = 42
;;! ----^^
;;! -xxxxx
(
(assignment_statement
(_) @_.leading.endOf
(expression_list) @value
) @_dummy @_.domain
(#not-parent-type? @_dummy variable_declaration)
)
;; Handle variable declaration values
;;!! local a = 42
;;! ----------^^
;;! -------xxxxx
local_declaration: (variable_declaration
(assignment_statement
(_) @_.leading.endOf
(expression_list) @value
)
) @_.domain
;;!! return a + b
;;! -------^^^^^
;;! ------xxxxxx
(return_statement
(_) @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