@exercism/codemirror-lang-lua 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +81 -0
- package/LICENSE +21 -0
- package/README.md +143 -2
- package/dist/index.cjs +549 -0
- package/dist/index.d.cts +123 -0
- package/dist/index.d.ts +123 -0
- package/dist/index.js +542 -0
- package/package.json +52 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { LRParser } from '@lezer/lr';
|
|
2
|
+
import { LanguageSupport, LRLanguage } from '@codemirror/language';
|
|
3
|
+
import { CompletionSource } from '@codemirror/autocomplete';
|
|
4
|
+
|
|
5
|
+
declare const parser: LRParser
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
Snippets for the constructs people type most: functions, conditionals,
|
|
9
|
+
loops, and the metatable pattern Lua uses in place of classes.
|
|
10
|
+
*/
|
|
11
|
+
declare const snippets = [
|
|
12
|
+
snippetCompletion("function ${name}(${params})\n\t${}\nend", {
|
|
13
|
+
label: "function",
|
|
14
|
+
detail: "definition",
|
|
15
|
+
type: "keyword"
|
|
16
|
+
}),
|
|
17
|
+
snippetCompletion("local function ${name}(${params})\n\t${}\nend", {
|
|
18
|
+
label: "local function",
|
|
19
|
+
detail: "definition",
|
|
20
|
+
type: "keyword"
|
|
21
|
+
}),
|
|
22
|
+
snippetCompletion("local ${name} = ${value}", {
|
|
23
|
+
label: "local",
|
|
24
|
+
detail: "declaration",
|
|
25
|
+
type: "keyword"
|
|
26
|
+
}),
|
|
27
|
+
snippetCompletion("if ${condition} then\n\t${}\nend", {
|
|
28
|
+
label: "if",
|
|
29
|
+
detail: "block",
|
|
30
|
+
type: "keyword"
|
|
31
|
+
}),
|
|
32
|
+
snippetCompletion("if ${condition} then\n\t${}\nelse\n\t${}\nend", {
|
|
33
|
+
label: "if",
|
|
34
|
+
detail: "/ else block",
|
|
35
|
+
type: "keyword"
|
|
36
|
+
}),
|
|
37
|
+
snippetCompletion("elseif ${condition} then\n\t${}", {
|
|
38
|
+
label: "elseif",
|
|
39
|
+
detail: "branch",
|
|
40
|
+
type: "keyword"
|
|
41
|
+
}),
|
|
42
|
+
snippetCompletion("for ${i} = ${1}, ${n} do\n\t${}\nend", {
|
|
43
|
+
label: "for",
|
|
44
|
+
detail: "numeric loop",
|
|
45
|
+
type: "keyword"
|
|
46
|
+
}),
|
|
47
|
+
snippetCompletion("for ${i}, ${value} in ipairs(${list}) do\n\t${}\nend", {
|
|
48
|
+
label: "for",
|
|
49
|
+
detail: "ipairs loop",
|
|
50
|
+
type: "keyword"
|
|
51
|
+
}),
|
|
52
|
+
snippetCompletion("for ${key}, ${value} in pairs(${table}) do\n\t${}\nend", {
|
|
53
|
+
label: "for",
|
|
54
|
+
detail: "pairs loop",
|
|
55
|
+
type: "keyword"
|
|
56
|
+
}),
|
|
57
|
+
snippetCompletion("while ${condition} do\n\t${}\nend", {
|
|
58
|
+
label: "while",
|
|
59
|
+
detail: "loop",
|
|
60
|
+
type: "keyword"
|
|
61
|
+
}),
|
|
62
|
+
snippetCompletion("repeat\n\t${}\nuntil ${condition}", {
|
|
63
|
+
label: "repeat",
|
|
64
|
+
detail: "loop",
|
|
65
|
+
type: "keyword"
|
|
66
|
+
}),
|
|
67
|
+
snippetCompletion("local ${Name} = {}\n${Name}.__index = ${Name}\n\nfunction ${Name}.new(${params})\n\tlocal self = setmetatable({}, ${Name})\n\t${}\n\treturn self\nend", { label: "class", detail: "metatable", type: "keyword" })
|
|
68
|
+
];
|
|
69
|
+
/**
|
|
70
|
+
Completes the names declared in the file. A local is offered from the
|
|
71
|
+
end of its declaration to the end of its block, a parameter inside its
|
|
72
|
+
function and a loop variable inside its loop. Globals and global
|
|
73
|
+
functions are offered everywhere. After `name.` or `name:` it offers the
|
|
74
|
+
fields declared on that table, or the standard library's members.
|
|
75
|
+
*/
|
|
76
|
+
declare const localCompletionSource = context => {
|
|
77
|
+
const tree = syntaxTree(context.state);
|
|
78
|
+
const inner = tree.resolveInner(context.pos, -1);
|
|
79
|
+
if (inStringOrComment(inner))
|
|
80
|
+
return null;
|
|
81
|
+
const names = gather(context.state, tree);
|
|
82
|
+
const member = completeMember(context, names, inner);
|
|
83
|
+
if (member)
|
|
84
|
+
return member;
|
|
85
|
+
if (dontComplete.indexOf(inner.name) > -1)
|
|
86
|
+
return null;
|
|
87
|
+
if (context.matchBefore(/[.:]\s*\w*$/))
|
|
88
|
+
return null;
|
|
89
|
+
const word = context.matchBefore(/[a-zA-Z_\u{80}-\u{10ffff}][\w\u{80}-\u{10ffff}]*$/u);
|
|
90
|
+
if (!word && !context.explicit)
|
|
91
|
+
return null;
|
|
92
|
+
const options = [];
|
|
93
|
+
const seen = new Set();
|
|
94
|
+
// Later definitions are closer to the cursor, so they win on a name clash.
|
|
95
|
+
for (let i = names.definitions.length - 1; i >= 0; i--) {
|
|
96
|
+
const d = names.definitions[i];
|
|
97
|
+
if (d.from > context.pos || d.to < context.pos || seen.has(d.label))
|
|
98
|
+
continue;
|
|
99
|
+
if (word && d.at == word.from)
|
|
100
|
+
continue;
|
|
101
|
+
seen.add(d.label);
|
|
102
|
+
options.push({ label: d.label, type: d.type });
|
|
103
|
+
}
|
|
104
|
+
return { from: word ? word.from : context.pos, options, validFor: identifier };
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
A language provider based on the Lezer Lua parser in this package,
|
|
109
|
+
extended with highlighting, folding and indentation information.
|
|
110
|
+
*/
|
|
111
|
+
declare const luaLanguage: LRLanguage;
|
|
112
|
+
/**
|
|
113
|
+
Autocompletion for Lua's keywords, snippets, globals and standard library
|
|
114
|
+
tables. It offers nothing inside strings and comments.
|
|
115
|
+
*/
|
|
116
|
+
declare const luaCompletion: CompletionSource;
|
|
117
|
+
/**
|
|
118
|
+
Lua language support, with completion for keywords, snippets, the standard
|
|
119
|
+
library and the names declared in the file.
|
|
120
|
+
*/
|
|
121
|
+
declare function lua(): LanguageSupport;
|
|
122
|
+
|
|
123
|
+
export { localCompletionSource, lua, luaCompletion, luaLanguage, parser, snippets };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { LRParser } from '@lezer/lr';
|
|
2
|
+
import { LanguageSupport, LRLanguage } from '@codemirror/language';
|
|
3
|
+
import { CompletionSource } from '@codemirror/autocomplete';
|
|
4
|
+
|
|
5
|
+
declare const parser: LRParser
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
Snippets for the constructs people type most: functions, conditionals,
|
|
9
|
+
loops, and the metatable pattern Lua uses in place of classes.
|
|
10
|
+
*/
|
|
11
|
+
declare const snippets = [
|
|
12
|
+
snippetCompletion("function ${name}(${params})\n\t${}\nend", {
|
|
13
|
+
label: "function",
|
|
14
|
+
detail: "definition",
|
|
15
|
+
type: "keyword"
|
|
16
|
+
}),
|
|
17
|
+
snippetCompletion("local function ${name}(${params})\n\t${}\nend", {
|
|
18
|
+
label: "local function",
|
|
19
|
+
detail: "definition",
|
|
20
|
+
type: "keyword"
|
|
21
|
+
}),
|
|
22
|
+
snippetCompletion("local ${name} = ${value}", {
|
|
23
|
+
label: "local",
|
|
24
|
+
detail: "declaration",
|
|
25
|
+
type: "keyword"
|
|
26
|
+
}),
|
|
27
|
+
snippetCompletion("if ${condition} then\n\t${}\nend", {
|
|
28
|
+
label: "if",
|
|
29
|
+
detail: "block",
|
|
30
|
+
type: "keyword"
|
|
31
|
+
}),
|
|
32
|
+
snippetCompletion("if ${condition} then\n\t${}\nelse\n\t${}\nend", {
|
|
33
|
+
label: "if",
|
|
34
|
+
detail: "/ else block",
|
|
35
|
+
type: "keyword"
|
|
36
|
+
}),
|
|
37
|
+
snippetCompletion("elseif ${condition} then\n\t${}", {
|
|
38
|
+
label: "elseif",
|
|
39
|
+
detail: "branch",
|
|
40
|
+
type: "keyword"
|
|
41
|
+
}),
|
|
42
|
+
snippetCompletion("for ${i} = ${1}, ${n} do\n\t${}\nend", {
|
|
43
|
+
label: "for",
|
|
44
|
+
detail: "numeric loop",
|
|
45
|
+
type: "keyword"
|
|
46
|
+
}),
|
|
47
|
+
snippetCompletion("for ${i}, ${value} in ipairs(${list}) do\n\t${}\nend", {
|
|
48
|
+
label: "for",
|
|
49
|
+
detail: "ipairs loop",
|
|
50
|
+
type: "keyword"
|
|
51
|
+
}),
|
|
52
|
+
snippetCompletion("for ${key}, ${value} in pairs(${table}) do\n\t${}\nend", {
|
|
53
|
+
label: "for",
|
|
54
|
+
detail: "pairs loop",
|
|
55
|
+
type: "keyword"
|
|
56
|
+
}),
|
|
57
|
+
snippetCompletion("while ${condition} do\n\t${}\nend", {
|
|
58
|
+
label: "while",
|
|
59
|
+
detail: "loop",
|
|
60
|
+
type: "keyword"
|
|
61
|
+
}),
|
|
62
|
+
snippetCompletion("repeat\n\t${}\nuntil ${condition}", {
|
|
63
|
+
label: "repeat",
|
|
64
|
+
detail: "loop",
|
|
65
|
+
type: "keyword"
|
|
66
|
+
}),
|
|
67
|
+
snippetCompletion("local ${Name} = {}\n${Name}.__index = ${Name}\n\nfunction ${Name}.new(${params})\n\tlocal self = setmetatable({}, ${Name})\n\t${}\n\treturn self\nend", { label: "class", detail: "metatable", type: "keyword" })
|
|
68
|
+
];
|
|
69
|
+
/**
|
|
70
|
+
Completes the names declared in the file. A local is offered from the
|
|
71
|
+
end of its declaration to the end of its block, a parameter inside its
|
|
72
|
+
function and a loop variable inside its loop. Globals and global
|
|
73
|
+
functions are offered everywhere. After `name.` or `name:` it offers the
|
|
74
|
+
fields declared on that table, or the standard library's members.
|
|
75
|
+
*/
|
|
76
|
+
declare const localCompletionSource = context => {
|
|
77
|
+
const tree = syntaxTree(context.state);
|
|
78
|
+
const inner = tree.resolveInner(context.pos, -1);
|
|
79
|
+
if (inStringOrComment(inner))
|
|
80
|
+
return null;
|
|
81
|
+
const names = gather(context.state, tree);
|
|
82
|
+
const member = completeMember(context, names, inner);
|
|
83
|
+
if (member)
|
|
84
|
+
return member;
|
|
85
|
+
if (dontComplete.indexOf(inner.name) > -1)
|
|
86
|
+
return null;
|
|
87
|
+
if (context.matchBefore(/[.:]\s*\w*$/))
|
|
88
|
+
return null;
|
|
89
|
+
const word = context.matchBefore(/[a-zA-Z_\u{80}-\u{10ffff}][\w\u{80}-\u{10ffff}]*$/u);
|
|
90
|
+
if (!word && !context.explicit)
|
|
91
|
+
return null;
|
|
92
|
+
const options = [];
|
|
93
|
+
const seen = new Set();
|
|
94
|
+
// Later definitions are closer to the cursor, so they win on a name clash.
|
|
95
|
+
for (let i = names.definitions.length - 1; i >= 0; i--) {
|
|
96
|
+
const d = names.definitions[i];
|
|
97
|
+
if (d.from > context.pos || d.to < context.pos || seen.has(d.label))
|
|
98
|
+
continue;
|
|
99
|
+
if (word && d.at == word.from)
|
|
100
|
+
continue;
|
|
101
|
+
seen.add(d.label);
|
|
102
|
+
options.push({ label: d.label, type: d.type });
|
|
103
|
+
}
|
|
104
|
+
return { from: word ? word.from : context.pos, options, validFor: identifier };
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
A language provider based on the Lezer Lua parser in this package,
|
|
109
|
+
extended with highlighting, folding and indentation information.
|
|
110
|
+
*/
|
|
111
|
+
declare const luaLanguage: LRLanguage;
|
|
112
|
+
/**
|
|
113
|
+
Autocompletion for Lua's keywords, snippets, globals and standard library
|
|
114
|
+
tables. It offers nothing inside strings and comments.
|
|
115
|
+
*/
|
|
116
|
+
declare const luaCompletion: CompletionSource;
|
|
117
|
+
/**
|
|
118
|
+
Lua language support, with completion for keywords, snippets, the standard
|
|
119
|
+
library and the names declared in the file.
|
|
120
|
+
*/
|
|
121
|
+
declare function lua(): LanguageSupport;
|
|
122
|
+
|
|
123
|
+
export { localCompletionSource, lua, luaCompletion, luaLanguage, parser, snippets };
|