-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## 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 | #1962 (comment) | | ✓ | ✓ | - | `@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 <[email protected]> Co-authored-by: Pokey Rule <[email protected]>
- Loading branch information
1 parent
1c18476
commit aa76859
Showing
54 changed files
with
1,901 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; |
50 changes: 50 additions & 0 deletions
50
...s/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/bringArgAirAfterBat.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} |
29 changes: 29 additions & 0 deletions
29
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeArg.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} |
25 changes: 25 additions & 0 deletions
25
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeArg2.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} |
25 changes: 25 additions & 0 deletions
25
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCall.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} |
25 changes: 25 additions & 0 deletions
25
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeComment.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} |
27 changes: 27 additions & 0 deletions
27
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeComment2.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} |
23 changes: 23 additions & 0 deletions
23
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/lua/changeCondition.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} |
Oops, something went wrong.