1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
-- Enumeration of commonly encountered syntax token types.
local SyntaxTokenType = {
Other = 0, -- Everything except tokens that are part of comments, string literals and regular expressions.
Comment = 1, -- A comment.
String = 2, -- A string literal.
RegEx = 3 -- A regular expression.
}
-- Describes what to do with the indentation when pressing Enter.
local IndentAction = {
None = 0, -- Insert new line and copy the previous line's indentation.
Indent = 1, -- Insert new line and indent once (relative to the previous line's indentation).
IndentOutdent = 2, -- Insert two new lines: the first one indented which will hold the cursor, and the second one at the same indentation level.
Outdent = 3 -- Insert new line and outdent once (relative to the previous line's indentation).
}
local languageConfiguration = {
id = 'lua',
configuration = {
autoClosingPairs = {
{ open = "{", close = "}" },
{ open = "[", close = "]" },
{ open = "(", close = ")" },
{ open = "'", close = "'", notIn = { SyntaxTokenType.String } },
{ open = '"', close = '"', notIn = { SyntaxTokenType.String } },
{ open = "[=", close = "=]" },
{ open = "[==", close = "==]" },
{ open = "[===", close = "===]" },
{ open = "[====", close = "====]" },
{ open = "[=====", close = "=====]" },
},
onEnterRules = {
{
beforeText = [[\)\s*$]],
afterText = [[^\s*end\b]],
action = {
indentAction = IndentAction.IndentOutdent,
}
},
{
beforeText = [[\b()\s*$]],
afterText = [[^\s*end\b]],
action = {
indentAction = IndentAction.IndentOutdent,
}
},
{
beforeText = [[\b(repeat)\s*$]],
afterText = [[^\s*until\b]],
action = {
indentAction = IndentAction.IndentOutdent,
}
},
{
beforeText = [[^\s*---@]],
action = {
indentAction = IndentAction.None,
appendText = "---@"
}
},
{
beforeText = [[^\s*--- @]],
action = {
indentAction = IndentAction.None,
appendText = "--- @"
}
},
{
beforeText = [[^\s*--- ]],
action = {
indentAction = IndentAction.None,
appendText = "--- "
}
},
{
beforeText = [[^\s*---]],
action = {
indentAction = IndentAction.None,
appendText = "---"
}
},
},
},
}
return languageConfiguration
|