Skip to content

Commit aa76859

Browse files
fidgetingbitsfidgetingbitspokey
authored
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 | | - | - | - | - | - | - | | &check; | &check; | `list` | `@list` | List type equivalent | - | | &check; | &check; | `inside list` | `@list.interior` | Inside of a list | - | | &check; | &check; | `map` | `@map` | Dictionary type equivalent | - | | &check; | &check; | `inside map` | `@map.interior` | Inside of a dictionary | - | | &check; | &check; | `key` | `@collectionKey` | Dictionary key equivalent | - | | &check; | &check; | `funk` | `@namedFunction` | A named function declaration | - | | &check; | &check; | `inside funk` | `@namedFunction.interior` | The inside of a lambda declaration | - | | &check; | &check; | `funk name` | `@functionName` | Name of declared function | - | | &check; | &check; | `lambda` | `@anonymousFunction` | A lambda declaration | - | | &check; | &check; | `inside lambda` | `@anonymousFunction.interior` | The inside of a lambda declaration | - | | &check; | &check; | `name` | `@name` | Variable name | - | | &check; | &check; | `value` | `@value` | Right-hand-side value of an assignment | - | | &check; | &check; | `value` | `@value` | Value returned from a function | - | | &check; | &check; | `value` | `@value` | Value of a key-value pair | - | | &check; | &check; | `state` | `@statement` | Any single coded statement | - | | &check; | &check; | `if state` | `@ifStatement` | An if conditional block | - | | &check; | &check; | `condition` | `@condition` | Condition of an if block | - | | &check; | &check; | `condition` | `@condition` | Condition of a while loop | - | | &check; | &check; | `condition` | `@condition` | Condition of a do while style loop | - | | - | - | `condition` | `@condition` | Condition of a for loop | - | | &check; | &check; | `condition` | `@condition` | Condition of a ternary expression | - | | &check; | &check; | `branch` | `@branch` | The resulting code associated with a conditional expression | - | | &check; | &check; | `comment` | `@comment` | Code comment | - | | &check; | &check; | `string` | `@string` | Single line strings | - | | &cross; | &cross; | `string` | `@string` | Multi-line strings | #1962 (comment) | | &check; | &check; | - | `@textFragment` | Used to capture string-type nodes (strings and comments) | - | | &check; | &check; | `call` | `@functionCall` | A function call (not a function definition) | - | | &check; | &check; | `callee` | `@functionCallee` | Name of the function being called | - | | &check; | &check; | `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 <[email protected]> Co-authored-by: Pokey Rule <[email protected]>
1 parent 1c18476 commit aa76859

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1901
-0
lines changed

data/playground/lua/lua.lua

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
-- This is a single-line comment
2+
3+
--[[
4+
This is a multi-line comment.
5+
It spans multiple lines.
6+
--]]
7+
8+
-- Variables
9+
local a = 42
10+
local b, c = "Hello", "World"
11+
12+
-- Data Types
13+
local number = 3.14
14+
local boolean = true
15+
local string = "Lua is awesome!"
16+
local table = { 1, 2, 3 }
17+
local nilValue = nil
18+
19+
-- Conditional Constructs
20+
local x = 10
21+
local y = 20
22+
23+
-- if-then-else
24+
if x < y then
25+
print("x is less than y")
26+
elseif x > y then
27+
print("x is greater than y")
28+
else
29+
print("x is equal to y")
30+
end
31+
32+
-- ternary conditional (short if-then-else)
33+
local max = x > y and x or y
34+
print("The maximum value is: " .. max)
35+
36+
-- Functions
37+
function add(x, b)
38+
return x + y
39+
end
40+
41+
local sum = add(5, 7)
42+
print("Sum:", sum)
43+
44+
-- Tables
45+
local person = {
46+
name = "John",
47+
age = 30,
48+
hobbies = { "reading", "gaming", "programming" },
49+
address = {
50+
street = "123 Main St",
51+
city = "Example City",
52+
},
53+
}
54+
55+
-- String manipulation
56+
local concatString = "Hello " .. "World"
57+
58+
-- Metatables and metatable operations
59+
local mt = {
60+
__add = function(a, b)
61+
return a + b
62+
end,
63+
__sub = function(a, b)
64+
return a - b
65+
end,
66+
}
67+
68+
setmetatable(a, mt)
69+
70+
-- Closures
71+
function makeCounter()
72+
local count = 0
73+
return function()
74+
count = count + 1
75+
return count
76+
end
77+
end
78+
79+
local counter = makeCounter()
80+
81+
-- Coroutines
82+
local co = coroutine.create(function()
83+
for i = 1, 3 do
84+
print("Coroutine", i)
85+
coroutine.yield()
86+
end
87+
end)
88+
89+
-- Error handling
90+
local success, result = pcall(function()
91+
error("This is an error")
92+
end)
93+
94+
if not success then
95+
print("Error:", result)
96+
end
97+
98+
-- Loop Constructs
99+
-- while loop
100+
local i = 1
101+
i = 2
102+
while i <= 5 do
103+
print("While loop iteration: " .. i)
104+
i = i + 1
105+
end
106+
107+
-- repeat-until loop
108+
i = 1
109+
repeat
110+
print("Repeat-Until loop iteration: " .. i)
111+
i = i + 1
112+
until i > 5
113+
114+
-- for loop
115+
for j = 1, 5 do
116+
print("For loop iteration: " .. j)
117+
end
118+
119+
-- numeric for loop with step
120+
for k = 10, 1, -1 do
121+
print("Numeric for loop with step: " .. k)
122+
end
123+
124+
-- for-in loop (iterating over a table)
125+
local fruits = { "apple", "banana", "cherry" }
126+
for key, value in pairs(fruits) do
127+
print("For-In loop: " .. key .. " = " .. value)
128+
end
129+
130+
-- ternary
131+
local max = x > y and x or y

packages/common/src/scopeSupportFacets/getLanguageScopeSupport.ts

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { javaScopeSupport } from "./java";
33
import { javascriptScopeSupport } from "./javascript";
44
import { jsonScopeSupport } from "./json";
55
import { pythonScopeSupport } from "./python";
6+
import { luaScopeSupport } from "./lua";
67
import { LanguageScopeSupportFacetMap } from "./scopeSupportFacets.types";
78
import { talonScopeSupport } from "./talon";
89
import { typescriptScopeSupport } from "./typescript";
@@ -25,6 +26,8 @@ export function getLanguageScopeSupport(
2526
return talonScopeSupport;
2627
case "typescript":
2728
return typescriptScopeSupport;
29+
case "lua":
30+
return luaScopeSupport;
2831
}
2932
throw Error(`Unsupported language: '${languageId}'`);
3033
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
2+
3+
import {
4+
LanguageScopeSupportFacetMap,
5+
ScopeSupportFacetLevel,
6+
} from "./scopeSupportFacets.types";
7+
8+
const { supported, notApplicable } = ScopeSupportFacetLevel;
9+
10+
export const luaScopeSupport: LanguageScopeSupportFacetMap = {
11+
"key.attribute": notApplicable,
12+
tags: notApplicable,
13+
"name.assignment": supported,
14+
"name.variable": supported,
15+
"value.assignment": supported,
16+
"value.variable": supported,
17+
functionCallee: supported,
18+
map: supported,
19+
"branch.if": supported,
20+
namedFunction: supported,
21+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: bring arg air after bat
5+
action:
6+
name: replaceWithTarget
7+
source:
8+
type: primitive
9+
mark: {type: decoratedSymbol, symbolColor: default, character: a}
10+
modifiers:
11+
- type: containingScope
12+
scopeType: {type: argumentOrParameter}
13+
destination:
14+
type: primitive
15+
insertionMode: after
16+
target:
17+
type: primitive
18+
mark: {type: decoratedSymbol, symbolColor: default, character: b}
19+
usePrePhraseSnapshot: true
20+
initialState:
21+
documentContents: |-
22+
function makeCounter(a, b)
23+
local count = 0
24+
return function()
25+
count = count + 1
26+
return count
27+
end
28+
end
29+
selections:
30+
- anchor: {line: 0, character: 21}
31+
active: {line: 0, character: 21}
32+
marks:
33+
default.a:
34+
start: {line: 0, character: 21}
35+
end: {line: 0, character: 22}
36+
default.b:
37+
start: {line: 0, character: 24}
38+
end: {line: 0, character: 25}
39+
finalState:
40+
documentContents: |-
41+
function makeCounter(a, b, a)
42+
local count = 0
43+
return function()
44+
count = count + 1
45+
return count
46+
end
47+
end
48+
selections:
49+
- anchor: {line: 0, character: 21}
50+
active: {line: 0, character: 21}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change arg
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: argumentOrParameter}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
function add(x, b)
16+
return x + y
17+
end
18+
selections:
19+
- anchor: {line: 0, character: 13}
20+
active: {line: 0, character: 13}
21+
marks: {}
22+
finalState:
23+
documentContents: |-
24+
function add(, b)
25+
return x + y
26+
end
27+
selections:
28+
- anchor: {line: 0, character: 13}
29+
active: {line: 0, character: 13}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change arg
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: argumentOrParameter}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
local sum = add(5, 7)
16+
selections:
17+
- anchor: {line: 0, character: 16}
18+
active: {line: 0, character: 16}
19+
marks: {}
20+
finalState:
21+
documentContents: |
22+
local sum = add(, 7)
23+
selections:
24+
- anchor: {line: 0, character: 16}
25+
active: {line: 0, character: 16}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change call
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: functionCall}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
print("a is greater than 10")
16+
selections:
17+
- anchor: {line: 0, character: 0}
18+
active: {line: 0, character: 0}
19+
marks: {}
20+
finalState:
21+
documentContents: |+
22+
23+
selections:
24+
- anchor: {line: 0, character: 0}
25+
active: {line: 0, character: 0}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change comment
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: comment}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |
15+
-- This is a single-line comment
16+
selections:
17+
- anchor: {line: 0, character: 0}
18+
active: {line: 0, character: 0}
19+
marks: {}
20+
finalState:
21+
documentContents: |+
22+
23+
selections:
24+
- anchor: {line: 0, character: 0}
25+
active: {line: 0, character: 0}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change comment
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: comment}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
--[[
16+
This is a multi-line comment.
17+
It spans multiple lines.
18+
--]]
19+
selections:
20+
- anchor: {line: 2, character: 4}
21+
active: {line: 2, character: 4}
22+
marks: {}
23+
finalState:
24+
documentContents: ""
25+
selections:
26+
- anchor: {line: 0, character: 0}
27+
active: {line: 0, character: 0}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
languageId: lua
2+
command:
3+
version: 6
4+
spokenForm: change condition
5+
action:
6+
name: clearAndSetSelection
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: condition}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: local max = x > y and x or y
15+
selections:
16+
- anchor: {line: 0, character: 12}
17+
active: {line: 0, character: 12}
18+
marks: {}
19+
finalState:
20+
documentContents: local max = and x or y
21+
selections:
22+
- anchor: {line: 0, character: 12}
23+
active: {line: 0, character: 12}

0 commit comments

Comments
 (0)