@exercism/codemirror-lang-wren 0.7.2 → 1.0.0
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/README.md +33 -3
- package/dist/index.cjs +278 -20
- package/dist/index.es.js +278 -23
- package/index.d.ts +6 -4
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ This code is released under an
|
|
|
14
14
|
|
|
15
15
|
### Language Support + Lezer Grammar
|
|
16
16
|
|
|
17
|
-
This includes both the CodeMirror `LanguageSupport` and the `
|
|
17
|
+
This includes both the CodeMirror `LanguageSupport` and the `LRLanguage` grammar all bundled into a single small repository with a simple build process.
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
### Maintainers
|
|
@@ -24,6 +24,14 @@ There is a very rough developer tool in `devtool` that can be used for testing.
|
|
|
24
24
|
npm run build-devtool
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
The parser tests are in `test/cases`, and the completion tests are in
|
|
28
|
+
`test/test-completion.js`. After changing the grammar, run
|
|
29
|
+
`npm run build-grammar` before the tests.
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
npm test
|
|
33
|
+
```
|
|
34
|
+
|
|
27
35
|
|
|
28
36
|
|
|
29
37
|
### API Reference
|
|
@@ -31,11 +39,12 @@ npm run build-devtool
|
|
|
31
39
|
<dt id="user-content-wren">
|
|
32
40
|
<code>wren() → <a href="https://codemirror.net/6/docs/ref#language.LanguageSupport">LanguageSupport</a></code></dt>
|
|
33
41
|
|
|
34
|
-
<dd><p>Wren support. Includes
|
|
42
|
+
<dd><p>Wren support. Includes completion of snippets, keywords, core classes,
|
|
43
|
+
the names in scope at the cursor, and methods after a dot.</p>
|
|
35
44
|
</dd>
|
|
36
45
|
|
|
37
46
|
<dt id="user-content-wrenlanguage">
|
|
38
|
-
<code>wrenLanguage: <a href="https://codemirror.net/6/docs/ref#language.
|
|
47
|
+
<code>wrenLanguage: <a href="https://codemirror.net/6/docs/ref#language.LRLanguage">LRLanguage</a></code></dt>
|
|
39
48
|
|
|
40
49
|
<dd><p>A language provider based on the Lezer Wren
|
|
41
50
|
parser provided in this very same package, extended with
|
|
@@ -55,3 +64,24 @@ highlighting and indentation information.</p>
|
|
|
55
64
|
<dd><p>A collection of simple Wren-related
|
|
56
65
|
<a href="https://codemirror.net/6/docs/ref/#autocomplete.snippet">snippets</a>.</p>
|
|
57
66
|
</dd>
|
|
67
|
+
|
|
68
|
+
<dt id="user-content-localcompletionsource">
|
|
69
|
+
<code>localCompletionSource: <a href="https://codemirror.net/6/docs/ref#autocomplete.CompletionSource">CompletionSource</a></code></dt>
|
|
70
|
+
|
|
71
|
+
<dd><p>Completes the variables, parameters, classes, methods and fields
|
|
72
|
+
that are in scope at the cursor.</p>
|
|
73
|
+
</dd>
|
|
74
|
+
|
|
75
|
+
<dt id="user-content-membercompletionsource">
|
|
76
|
+
<code>memberCompletionSource: <a href="https://codemirror.net/6/docs/ref#autocomplete.CompletionSource">CompletionSource</a></code></dt>
|
|
77
|
+
|
|
78
|
+
<dd><p>Completes methods after a dot. After a class name, it offers the
|
|
79
|
+
class's static methods and constructors. After any other value, it offers
|
|
80
|
+
the instance methods of the core classes and of the classes in the file.</p>
|
|
81
|
+
</dd>
|
|
82
|
+
|
|
83
|
+
<dt id="user-content-globalcompletionsource">
|
|
84
|
+
<code>globalCompletionSource: <a href="https://codemirror.net/6/docs/ref#autocomplete.CompletionSource">CompletionSource</a></code></dt>
|
|
85
|
+
|
|
86
|
+
<dd><p>Completes snippets, keywords and the core classes.</p>
|
|
87
|
+
</dd>
|
package/dist/index.cjs
CHANGED
|
@@ -2,33 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var lr = require('@lezer/lr');
|
|
6
6
|
var language = require('@codemirror/language');
|
|
7
|
-
var highlight = require('@
|
|
7
|
+
var highlight = require('@lezer/highlight');
|
|
8
8
|
var autocomplete = require('@codemirror/autocomplete');
|
|
9
9
|
|
|
10
10
|
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
11
|
-
const spec_identifier = {__proto__:null,import:10, true:36, false:36, this:38, null:40, super:42, is:104, for:
|
|
11
|
+
const spec_identifier = {__proto__:null,import:10, true:36, false:36, this:38, null:40, super:42, is:104, for:134, as:138, in:144, while:148, if:152, else:154, return:158, break:162, continue:166, foreign:172, class:174, var:194};
|
|
12
12
|
const spec_word = {__proto__:null,static:183, foreign:185, construct:187};
|
|
13
|
-
const parser =
|
|
14
|
-
version:
|
|
15
|
-
states: "
|
|
16
|
-
stateData: "!
|
|
17
|
-
goto: "
|
|
18
|
-
nodeNames: "⚠ LineComment BlockComment Script ImportDeclaration import String \"\"\" \" StringEscape HexEscape UnicodeEscape CharEscape ) %( Interpolation Number VariableName BooleanLiteral this null super ] [ ArrayExpression , } { ObjectExpression Property : UnaryExpression LogicOp BitOp ArithOp ( ParenthesizedExpression MemberExpression . PropertyName BinaryExpression ArithOp ArithOp ArithOp RangeOp BitOp BitOp BitOp BitOp | CompareOp CompareOp is CompareOp LogicOp LogicOp ConditionalExpression LogicOp LogicOp AssignmentExpression Equals CallExpression ArgList BlockMaybeArgs BlockArgs SequenceExpression for ImportName
|
|
13
|
+
const parser = lr.LRParser.deserialize({
|
|
14
|
+
version: 14,
|
|
15
|
+
states: "AYO]QPOOOOQO'#Cm'#CmO#wQPO'#CtO$RQPO'#ESO!yQPO'#C{O!yQPO'#DQO%jQPO'#EtO(pQPO'#EuOOQO'#Eu'#EuOOQO'#Et'#EtO*lOQO'#CbO+VOSO'#CbOOQO'#FP'#FPOOQO'#Eb'#EbOOQO'#Eq'#EqOOQO'#Ec'#EcQ]QPOOO+^QPO'#C`O+fQPO'#DtO+kQPO'#DwO+kQPO'#DyO+pQPO'#D|OOQO'#EO'#EOOOQO'#EQ'#EQO,mQWO'#ETO,rQPO'#ETO,wQPO'#E`O,|QPO'#EfO-WQPO'#EvO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$T$YQ%Z$^S%n%[%_S%x%o%pS%{%y%zR%}%|i[OR`q!W!i!j!k#a#b$T$YQ!nhQ#t!oQ$e#sR%c$gQ#r!nQ$f#tQ%b$eR%r%cT$_#q$`S$^#q$`U%_$b$c$dS%p%`%aR%z%qQ%[$^Q%o%_Q%y%pR%|%zQ`OQqRW!e`q#a$TQ#a!WR$T#bQ!_YR#h!_Q!dZR#k!dQlQS!sl!tR!tmQ#x!wR$k#xQ$O#]R${$OQ$}$QR%e$}Q!ZUR#e!ZQ%S$WR%h%SQ$`#qR%]$`Q%k%WR%u%k`_OR`q!W#a#b$TQ#n!iQ#o!jQ#p!kR%U$Yh]OR`q!W!i!j!k#a#b$T$YQsTQ!leQ!}uQ#j!bR%T$XrUORT`equ!W!b!i!j!k#a#b$T$X$YQmQQrSQ!rkS!vo#wQ#OxQ#PyQ#QzQ#R{Q#S|Q#T}Q#U!OQ#V!PQ#W!QQ#X!RQ#Y!SQ#Z!UQ#]!VQ#d!YQ#f![Q#g!]Q#{&OQ$h#uQ$i#vQ$l&PQ$m&QQ$n&RQ$o&SQ$p&TQ$q&UQ$r&VQ$s&WQ$t&XQ$u&YQ$v&ZQ$w#|Q$x&[Q$y&]Q$z#}Q%s&^R&_&`RnQR!xoR#^!VQ$R#_R%m%YR!gbR%X$[",
|
|
18
|
+
nodeNames: "⚠ LineComment BlockComment Script ImportDeclaration import String \"\"\" \" StringEscape HexEscape UnicodeEscape CharEscape ) %( Interpolation Number VariableName BooleanLiteral this null super ] [ ArrayExpression , } { ObjectExpression Property : UnaryExpression LogicOp BitOp ArithOp ( ParenthesizedExpression MemberExpression . PropertyName BinaryExpression ArithOp ArithOp ArithOp RangeOp BitOp BitOp BitOp BitOp | CompareOp CompareOp is CompareOp LogicOp LogicOp ConditionalExpression LogicOp LogicOp AssignmentExpression Equals CallExpression ArgList BlockMaybeArgs BlockArgs VariableDefinition SequenceExpression for ImportName as ForStatement ForInSpec in WhileStatement while IfStatement if else ReturnStatement return BreakStatement break ContinueStatement continue Block ClassDeclaration foreign class ClassName ClassBody MethodDeclaration static foreign construct ClassMethodName ParamList VariableDeclaration var ExpressionStatement",
|
|
19
19
|
maxTerm: 139,
|
|
20
20
|
nodeProps: [
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
21
|
+
["group", -11,4,70,73,75,78,80,82,84,85,96,98,"Statement",-17,6,16,17,18,19,20,21,24,28,31,36,37,40,56,59,61,66,"Expression",90,"ClassItem"],
|
|
22
|
+
["openedBy", 13,"%( (",22,"[",26,"{"],
|
|
23
|
+
["closedBy", -2,14,35,")",23,"]",27,"}"]
|
|
24
24
|
],
|
|
25
25
|
skippedNodes: [0,1,2],
|
|
26
26
|
repeatNodeCount: 11,
|
|
27
|
-
tokenData: "
|
|
27
|
+
tokenData: "Cr~R!^OX$}X^%U^p$}pq%Uqr&rrs'Xst$}tu'nuv)Yvw)mwx$}xy*Oyz*Xz{*b{|*m|}*x}!O+R!O!P+^!P!Q+w!Q!R3v!R![6]![!]6r!]!^$}!^!_6}!_!`7j!`!a7}!a!b8`!b!c$}!c!}8i!}#O:X#O#P:b#P#Q>e#Q#R>n#R#S'n#S#T$}#T#o'n#o#p>w#p#q?Q#q#r?c#r#s?l#s#y$}#y#z%U#z$f$}$f$g%U$g#BY'n#BY#BZ?w#BZ$IS'n$IS$I_?w$I_$I|'n$I|$JO?w$JO$JT'n$JT$JU?w$JU$KV'n$KV$KW?w$KW&FU'n&FU&FV?w&FV;'S'n;'S;=`Ce;=`<%lCm<%lO'nU%UO#gQ#qS!a%_Y#gQ#qS#d!ZX^%}pq%}#y#z%}$f$g%}#BY#BZ%}$IS$I_%}$I|$JO%}$JT$JU%}$KV$KW%}&FU&FV%}!Z&SY#d!ZX^%}pq%}#y#z%}$f$g%}#BY#BZ%}$IS$I_%}$I|$JO%}$JT$JU%}$KV$KW%}&FU&FV%}!X&}P$O`pP#gQ#qS!_!`'Q!R'XO#}`!Vq~'`PWT#gQrs'c~'fPrs'i~'nO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O$P`qP#gQ#qS!a@Uh#gQ#qS#l`#fq#d!ZX^%}pq%}tu(c!Q![(c!c!}(c#R#S(c#T#o(c#y#z%}$f$g%}$g#BY(c#BY#BZAp#BZ$IS(c$IS$I_Ap$I_$I|(c$I|$JOAp$JO$JT(c$JT$JUAp$JU$KV(c$KV$KWAp$KW&FU(c&FU&FVAp&FV;'S(c;'S;=`)S<%lO(c!ZAyh#l`#fq#d!ZX^%}pq%}tu(c!Q![(c!c!}(c#R#S(c#T#o(c#y#z%}$f$g%}$g#BY(c#BY#BZAp#BZ$IS(c$IS$I_Ap$I_$I|(c$I|$JOAp$JO$JT(c$JT$JUAp$JU$KV(c$KV$KWAp$KW&FU(c&FU&FVAp&FV;'S(c;'S;=`)S<%lO(c!XCjP#gQ;=`<%l'nQCrO#gQ",
|
|
28
28
|
tokenizers: [0, 1, 2, 3, 4, 5],
|
|
29
29
|
topRules: {"Script":[0,3]},
|
|
30
|
-
specialized: [{term: 114, get: value => spec_identifier[value] || -1},{term: 120, get: value => spec_word[value] || -1}],
|
|
31
|
-
tokenPrec:
|
|
30
|
+
specialized: [{term: 114, get: (value) => spec_identifier[value] || -1},{term: 120, get: (value) => spec_word[value] || -1}],
|
|
31
|
+
tokenPrec: 3694
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
/// A collection of Wren-related snippets
|
|
@@ -63,11 +63,265 @@ const snippets = [
|
|
|
63
63
|
detail: "as",
|
|
64
64
|
type: "keyword"
|
|
65
65
|
}),
|
|
66
|
+
autocomplete.snippetCompletion("if (${condition}) {\n\t${}\n}", {
|
|
67
|
+
label: "if",
|
|
68
|
+
detail: "block",
|
|
69
|
+
type: "keyword"
|
|
70
|
+
}),
|
|
71
|
+
autocomplete.snippetCompletion("if (${condition}) {\n\t${}\n} else {\n\t${}\n}", {
|
|
72
|
+
label: "if",
|
|
73
|
+
detail: "/ else block",
|
|
74
|
+
type: "keyword"
|
|
75
|
+
}),
|
|
76
|
+
autocomplete.snippetCompletion("while (${condition}) {\n\t${}\n}", {
|
|
77
|
+
label: "while",
|
|
78
|
+
detail: "loop",
|
|
79
|
+
type: "keyword"
|
|
80
|
+
}),
|
|
81
|
+
autocomplete.snippetCompletion("${name}(${params}) {\n\t${}\n}", {
|
|
82
|
+
label: "method",
|
|
83
|
+
detail: "definition",
|
|
84
|
+
type: "keyword"
|
|
85
|
+
}),
|
|
86
|
+
autocomplete.snippetCompletion("static ${name}(${params}) {\n\t${}\n}", {
|
|
87
|
+
label: "static",
|
|
88
|
+
detail: "method definition",
|
|
89
|
+
type: "keyword"
|
|
90
|
+
}),
|
|
91
|
+
autocomplete.snippetCompletion("construct new(${params}) {\n\t${}\n}", {
|
|
92
|
+
label: "construct",
|
|
93
|
+
detail: "constructor",
|
|
94
|
+
type: "keyword"
|
|
95
|
+
}),
|
|
66
96
|
];
|
|
67
97
|
|
|
98
|
+
// Wren's reserved words, and the classes and methods of its core library
|
|
99
|
+
// (https://wren.io/modules/core/) and the CLI's "random" module.
|
|
100
|
+
|
|
101
|
+
const keywords = ("as break class construct continue else false for foreign if " +
|
|
102
|
+
"import in is null return static super this true var while").split(" ");
|
|
103
|
+
|
|
104
|
+
const coreClasses = ("Bool Class Fiber Fn List Map Null Num Object Range " +
|
|
105
|
+
"Sequence String System").split(" ");
|
|
106
|
+
|
|
107
|
+
// Methods called on a class, as in `Num.fromString("1")`.
|
|
108
|
+
const staticMembers = {
|
|
109
|
+
Fiber: ["abort(message)", "current", "new(function)", "suspend()", "yield()", "yield(value)"],
|
|
110
|
+
Fn: ["new(function)"],
|
|
111
|
+
List: ["filled(size, element)", "new()"],
|
|
112
|
+
Map: ["new()"],
|
|
113
|
+
Num: ["fromString(value)", "infinity", "largest", "maxSafeInteger", "minSafeInteger",
|
|
114
|
+
"nan", "pi", "smallest", "tau"],
|
|
115
|
+
Object: ["same(obj1, obj2)"],
|
|
116
|
+
String: ["fromByte(byte)", "fromCodePoint(codePoint)"],
|
|
117
|
+
System: ["clock", "gc()", "print()", "print(object)", "printAll(sequence)",
|
|
118
|
+
"write(object)", "writeAll(sequence)"],
|
|
119
|
+
Random: ["new()", "new(seed)"],
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// Methods called on a value, as in `list.count`.
|
|
123
|
+
const instanceMembers = {
|
|
124
|
+
Object: ["toString", "type"],
|
|
125
|
+
Class: ["name", "supertype"],
|
|
126
|
+
Fiber: ["call()", "call(value)", "error", "isDone", "transfer()", "transfer(value)",
|
|
127
|
+
"transferError(error)", "try()", "try(value)"],
|
|
128
|
+
Fn: ["arity", "call()"],
|
|
129
|
+
Sequence: ["all(predicate)", "any(predicate)", "contains(element)", "count",
|
|
130
|
+
"count(predicate)", "each(function)", "isEmpty", "join()", "join(separator)",
|
|
131
|
+
"map(transformation)", "reduce(function)", "reduce(seed, function)", "skip(count)",
|
|
132
|
+
"take(count)", "toList", "where(predicate)"],
|
|
133
|
+
List: ["add(item)", "addAll(other)", "clear()", "indexOf(value)", "insert(index, item)",
|
|
134
|
+
"remove(value)", "removeAt(index)", "sort()", "sort(comparer)", "swap(index0, index1)"],
|
|
135
|
+
Map: ["containsKey(key)", "keys", "remove(key)", "values"],
|
|
136
|
+
Num: ["abs", "acos", "asin", "atan", "atan(x)", "cbrt", "ceil", "clamp(min, max)", "cos",
|
|
137
|
+
"exp", "floor", "fraction", "isInfinity", "isInteger", "isNan", "log", "log2",
|
|
138
|
+
"max(other)", "min(other)", "pow(power)", "round", "sign", "sin", "sqrt", "tan",
|
|
139
|
+
"truncate"],
|
|
140
|
+
Range: ["from", "isInclusive", "max", "min", "to"],
|
|
141
|
+
String: ["bytes", "codePoints", "endsWith(suffix)", "indexOf(search)",
|
|
142
|
+
"indexOf(search, start)", "replace(old, swap)", "split(separator)",
|
|
143
|
+
"startsWith(prefix)", "trim()", "trim(chars)", "trimEnd()", "trimEnd(chars)",
|
|
144
|
+
"trimStart()", "trimStart(chars)"],
|
|
145
|
+
Random: ["float()", "float(end)", "float(start, end)", "int(end)", "int(start, end)",
|
|
146
|
+
"sample(list)", "sample(list, count)", "shuffle(list)"],
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const ScopeNodes = new Set([
|
|
150
|
+
"Script", "Block", "BlockMaybeArgs", "MethodDeclaration", "ForStatement", "ClassBody"
|
|
151
|
+
]);
|
|
152
|
+
|
|
153
|
+
const dontComplete = [
|
|
154
|
+
"String", "LineComment", "BlockComment", "VariableDefinition", "ClassMethodName"
|
|
155
|
+
];
|
|
156
|
+
|
|
157
|
+
const Identifier = /^[\w$\xa1-]*$/;
|
|
158
|
+
|
|
159
|
+
// `foo.ba|` (the cursor is after a dot) is member completion's job.
|
|
160
|
+
function afterDot(context) {
|
|
161
|
+
return context.matchBefore(/\.\w*$/) != null
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function text(state, node) {
|
|
165
|
+
return state.sliceDoc(node.from, node.to)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function children(node, name) {
|
|
169
|
+
let found = [];
|
|
170
|
+
for (let child = node.firstChild; child; child = child.nextSibling)
|
|
171
|
+
if (child.name == name) found.push(child);
|
|
172
|
+
return found
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Instance method names in a class are in scope inside its body, because
|
|
176
|
+
// `count` there means `this.count`.
|
|
177
|
+
function methodName(state, method) {
|
|
178
|
+
let name = children(method, "ClassMethodName")[0];
|
|
179
|
+
let match = name && /^[A-Za-z_]\w*/.exec(text(state, name));
|
|
180
|
+
return match ? match[0] : null
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function classBodyNames(state, body, add) {
|
|
184
|
+
for (let method of children(body, "MethodDeclaration")) {
|
|
185
|
+
let name = methodName(state, method);
|
|
186
|
+
if (name) add(name, "method");
|
|
187
|
+
}
|
|
188
|
+
// Fields (`_name`) and static fields (`__name`) are created by assigning
|
|
189
|
+
// to them anywhere in the class.
|
|
190
|
+
body.cursor().iterate(node => {
|
|
191
|
+
if (node.name == "VariableName") {
|
|
192
|
+
let name = text(state, node);
|
|
193
|
+
if (name.startsWith("_")) add(name, "property");
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function scopeNames(state, scope, add) {
|
|
199
|
+
if (scope.name == "ClassBody") return classBodyNames(state, scope, add)
|
|
200
|
+
let gather = node => {
|
|
201
|
+
for (let child = node.firstChild; child; child = child.nextSibling) {
|
|
202
|
+
if (child.name == "ImportName") {
|
|
203
|
+
// In `import "x" for A as B`, only `B` is in scope.
|
|
204
|
+
let defs = children(child, "VariableDefinition");
|
|
205
|
+
let name = text(state, defs[defs.length - 1]);
|
|
206
|
+
add(name, /^[A-Z]/.test(name) ? "class" : "variable");
|
|
207
|
+
} else if (child.name == "ClassDeclaration") {
|
|
208
|
+
let name = children(child, "ClassName")[0];
|
|
209
|
+
if (name) add(text(state, name), "class");
|
|
210
|
+
} else if (child.name == "VariableDefinition") {
|
|
211
|
+
add(text(state, child), "variable");
|
|
212
|
+
} else if (!ScopeNodes.has(child.name)) {
|
|
213
|
+
gather(child);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
gather(scope);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/// Completes the names of variables, parameters, classes, methods and
|
|
221
|
+
/// fields that are in scope at the cursor.
|
|
222
|
+
function localCompletionSource(context) {
|
|
223
|
+
let inner = language.syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
224
|
+
if (dontComplete.includes(inner.name) || afterDot(context)) return null
|
|
225
|
+
let word = context.matchBefore(/[\w$\xa1-]+$/);
|
|
226
|
+
if (!word && !context.explicit) return null
|
|
227
|
+
let seen = new Set(), options = [];
|
|
228
|
+
let add = (label, type) => {
|
|
229
|
+
if (seen.has(label)) return
|
|
230
|
+
seen.add(label);
|
|
231
|
+
options.push({label, type});
|
|
232
|
+
};
|
|
233
|
+
for (let pos = inner; pos; pos = pos.parent)
|
|
234
|
+
if (ScopeNodes.has(pos.name)) scopeNames(context.state, pos, add);
|
|
235
|
+
return {options, from: word ? word.from : context.pos, validFor: Identifier}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function memberOptions(signatures) {
|
|
239
|
+
let byName = new Map();
|
|
240
|
+
for (let sig of signatures) {
|
|
241
|
+
let paren = sig.indexOf("(");
|
|
242
|
+
let name = paren < 0 ? sig : sig.slice(0, paren);
|
|
243
|
+
let args = paren < 0 ? "" : sig.slice(paren);
|
|
244
|
+
if (!byName.has(name)) byName.set(name, []);
|
|
245
|
+
if (args) byName.get(name).push(args);
|
|
246
|
+
}
|
|
247
|
+
return [...byName].map(([label, args]) => ({
|
|
248
|
+
label,
|
|
249
|
+
type: args.length ? "method" : "property",
|
|
250
|
+
detail: args.join(" ") || undefined
|
|
251
|
+
}))
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const staticOptions = {};
|
|
255
|
+
for (let name in staticMembers) staticOptions[name] = memberOptions(staticMembers[name]);
|
|
256
|
+
|
|
257
|
+
const instanceOptions = memberOptions(Object.values(instanceMembers).flat());
|
|
258
|
+
|
|
259
|
+
function fileClasses(state) {
|
|
260
|
+
let classes = new Map();
|
|
261
|
+
language.syntaxTree(state).topNode.cursor().iterate(node => {
|
|
262
|
+
if (node.name != "ClassDeclaration") return
|
|
263
|
+
let decl = node.node;
|
|
264
|
+
let name = children(decl, "ClassName")[0];
|
|
265
|
+
let body = children(decl, "ClassBody")[0];
|
|
266
|
+
if (!name || !body) return false
|
|
267
|
+
let statics = [], instance = [];
|
|
268
|
+
for (let method of children(body, "MethodDeclaration")) {
|
|
269
|
+
let label = methodName(state, method);
|
|
270
|
+
if (!label) continue
|
|
271
|
+
let onClass = children(method, "static").length || children(method, "construct").length
|
|
272
|
+
;(onClass ? statics : instance).push({label, type: "method"});
|
|
273
|
+
}
|
|
274
|
+
classes.set(text(state, name), {statics, instance});
|
|
275
|
+
return false
|
|
276
|
+
});
|
|
277
|
+
return classes
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/// Completes method names after a dot. After a class name, it offers that
|
|
281
|
+
/// class's static methods and constructors. After anything else, it offers
|
|
282
|
+
/// the instance methods of the core classes and of classes in the file.
|
|
283
|
+
function memberCompletionSource(context) {
|
|
284
|
+
let inner = language.syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
285
|
+
if (dontComplete.includes(inner.name)) return null
|
|
286
|
+
let member = context.matchBefore(/\.\w*$/);
|
|
287
|
+
if (!member) return null
|
|
288
|
+
let line = context.state.doc.lineAt(member.from);
|
|
289
|
+
let before = context.state.sliceDoc(line.from, member.from);
|
|
290
|
+
// `0..1` is a range.
|
|
291
|
+
if (before.endsWith(".")) return null
|
|
292
|
+
let receiver = /([A-Za-z_]\w*)\s*$/.exec(before);
|
|
293
|
+
let name = receiver ? receiver[1] : null;
|
|
294
|
+
let classes = fileClasses(context.state);
|
|
295
|
+
let options;
|
|
296
|
+
if (name && classes.has(name)) options = classes.get(name).statics;
|
|
297
|
+
else if (name && staticOptions[name]) options = staticOptions[name];
|
|
298
|
+
else if (name && /^[A-Z]/.test(name)) options = [];
|
|
299
|
+
else {
|
|
300
|
+
options = [...instanceOptions];
|
|
301
|
+
for (let cls of classes.values()) options.push(...cls.instance);
|
|
302
|
+
}
|
|
303
|
+
let seen = new Set();
|
|
304
|
+
options = options.filter(o => !seen.has(o.label) && seen.add(o.label));
|
|
305
|
+
return {options, from: member.from + 1, validFor: Identifier}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const globals = snippets.concat(
|
|
309
|
+
keywords.map(label => ({label, type: "keyword"})),
|
|
310
|
+
coreClasses.map(label => ({label, type: "class"}))
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
const globalList = autocomplete.completeFromList(globals);
|
|
314
|
+
|
|
315
|
+
/// Completes snippets, keywords and the core classes.
|
|
316
|
+
function globalCompletionSource(context) {
|
|
317
|
+
let inner = language.syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
318
|
+
if (dontComplete.includes(inner.name) || afterDot(context)) return null
|
|
319
|
+
return globalList(context)
|
|
320
|
+
}
|
|
321
|
+
|
|
68
322
|
const lezerParser = parser;
|
|
69
323
|
|
|
70
|
-
const wrenLanguage = language.
|
|
324
|
+
const wrenLanguage = language.LRLanguage.define({
|
|
71
325
|
parser: parser.configure({
|
|
72
326
|
props: [
|
|
73
327
|
language.indentNodeProp.add({
|
|
@@ -134,15 +388,19 @@ const wrenLanguage = language.LezerLanguage.define({
|
|
|
134
388
|
});
|
|
135
389
|
|
|
136
390
|
|
|
137
|
-
/// Wren support. Includes snippets
|
|
391
|
+
/// Wren support. Includes completion of snippets, keywords, core
|
|
392
|
+
/// classes, names in scope and methods after a dot.
|
|
138
393
|
function wren(config = {}) {
|
|
139
394
|
let lang = wrenLanguage;
|
|
140
|
-
return new language.LanguageSupport(lang,
|
|
141
|
-
|
|
142
|
-
}))
|
|
395
|
+
return new language.LanguageSupport(lang, [
|
|
396
|
+
globalCompletionSource, localCompletionSource, memberCompletionSource
|
|
397
|
+
].map(autocomplete => wrenLanguage.data.of({autocomplete})))
|
|
143
398
|
}
|
|
144
399
|
|
|
400
|
+
exports.globalCompletionSource = globalCompletionSource;
|
|
145
401
|
exports.lezerParser = lezerParser;
|
|
402
|
+
exports.localCompletionSource = localCompletionSource;
|
|
403
|
+
exports.memberCompletionSource = memberCompletionSource;
|
|
146
404
|
exports.snippets = snippets;
|
|
147
405
|
exports.wren = wren;
|
|
148
406
|
exports.wrenLanguage = wrenLanguage;
|
package/dist/index.es.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { styleTags, tags } from '@
|
|
4
|
-
import { snippetCompletion,
|
|
1
|
+
import { LRParser } from '@lezer/lr';
|
|
2
|
+
import { syntaxTree, LRLanguage, indentNodeProp, continuedIndent, delimitedIndent, foldNodeProp, foldInside, LanguageSupport } from '@codemirror/language';
|
|
3
|
+
import { styleTags, tags } from '@lezer/highlight';
|
|
4
|
+
import { snippetCompletion, completeFromList } from '@codemirror/autocomplete';
|
|
5
5
|
|
|
6
6
|
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
7
|
-
const spec_identifier = {__proto__:null,import:10, true:36, false:36, this:38, null:40, super:42, is:104, for:
|
|
7
|
+
const spec_identifier = {__proto__:null,import:10, true:36, false:36, this:38, null:40, super:42, is:104, for:134, as:138, in:144, while:148, if:152, else:154, return:158, break:162, continue:166, foreign:172, class:174, var:194};
|
|
8
8
|
const spec_word = {__proto__:null,static:183, foreign:185, construct:187};
|
|
9
|
-
const parser =
|
|
10
|
-
version:
|
|
11
|
-
states: "
|
|
12
|
-
stateData: "!
|
|
13
|
-
goto: "
|
|
14
|
-
nodeNames: "⚠ LineComment BlockComment Script ImportDeclaration import String \"\"\" \" StringEscape HexEscape UnicodeEscape CharEscape ) %( Interpolation Number VariableName BooleanLiteral this null super ] [ ArrayExpression , } { ObjectExpression Property : UnaryExpression LogicOp BitOp ArithOp ( ParenthesizedExpression MemberExpression . PropertyName BinaryExpression ArithOp ArithOp ArithOp RangeOp BitOp BitOp BitOp BitOp | CompareOp CompareOp is CompareOp LogicOp LogicOp ConditionalExpression LogicOp LogicOp AssignmentExpression Equals CallExpression ArgList BlockMaybeArgs BlockArgs SequenceExpression for ImportName
|
|
9
|
+
const parser = LRParser.deserialize({
|
|
10
|
+
version: 14,
|
|
11
|
+
states: "AYO]QPOOOOQO'#Cm'#CmO#wQPO'#CtO$RQPO'#ESO!yQPO'#C{O!yQPO'#DQO%jQPO'#EtO(pQPO'#EuOOQO'#Eu'#EuOOQO'#Et'#EtO*lOQO'#CbO+VOSO'#CbOOQO'#FP'#FPOOQO'#Eb'#EbOOQO'#Eq'#EqOOQO'#Ec'#EcQ]QPOOO+^QPO'#C`O+fQPO'#DtO+kQPO'#DwO+kQPO'#DyO+pQPO'#D|OOQO'#EO'#EOOOQO'#EQ'#EQO,mQWO'#ETO,rQPO'#ETO,wQPO'#E`O,|QPO'#EfO-WQPO'#EvO-`QPO'#EvO-jQP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%[%_S%x%o%pS%{%y%zR%}%|i[OR`q!W!i!j!k#a#b$T$YQ!nhQ#t!oQ$e#sR%c$gQ#r!nQ$f#tQ%b$eR%r%cT$_#q$`S$^#q$`U%_$b$c$dS%p%`%aR%z%qQ%[$^Q%o%_Q%y%pR%|%zQ`OQqRW!e`q#a$TQ#a!WR$T#bQ!_YR#h!_Q!dZR#k!dQlQS!sl!tR!tmQ#x!wR$k#xQ$O#]R${$OQ$}$QR%e$}Q!ZUR#e!ZQ%S$WR%h%SQ$`#qR%]$`Q%k%WR%u%k`_OR`q!W#a#b$TQ#n!iQ#o!jQ#p!kR%U$Yh]OR`q!W!i!j!k#a#b$T$YQsTQ!leQ!}uQ#j!bR%T$XrUORT`equ!W!b!i!j!k#a#b$T$X$YQmQQrSQ!rkS!vo#wQ#OxQ#PyQ#QzQ#R{Q#S|Q#T}Q#U!OQ#V!PQ#W!QQ#X!RQ#Y!SQ#Z!UQ#]!VQ#d!YQ#f![Q#g!]Q#{&OQ$h#uQ$i#vQ$l&PQ$m&QQ$n&RQ$o&SQ$p&TQ$q&UQ$r&VQ$s&WQ$t&XQ$u&YQ$v&ZQ$w#|Q$x&[Q$y&]Q$z#}Q%s&^R&_&`RnQR!xoR#^!VQ$R#_R%m%YR!gbR%X$[",
|
|
14
|
+
nodeNames: "⚠ LineComment BlockComment Script ImportDeclaration import String \"\"\" \" StringEscape HexEscape UnicodeEscape CharEscape ) %( Interpolation Number VariableName BooleanLiteral this null super ] [ ArrayExpression , } { ObjectExpression Property : UnaryExpression LogicOp BitOp ArithOp ( ParenthesizedExpression MemberExpression . PropertyName BinaryExpression ArithOp ArithOp ArithOp RangeOp BitOp BitOp BitOp BitOp | CompareOp CompareOp is CompareOp LogicOp LogicOp ConditionalExpression LogicOp LogicOp AssignmentExpression Equals CallExpression ArgList BlockMaybeArgs BlockArgs VariableDefinition SequenceExpression for ImportName as ForStatement ForInSpec in WhileStatement while IfStatement if else ReturnStatement return BreakStatement break ContinueStatement continue Block ClassDeclaration foreign class ClassName ClassBody MethodDeclaration static foreign construct ClassMethodName ParamList VariableDeclaration var ExpressionStatement",
|
|
15
15
|
maxTerm: 139,
|
|
16
16
|
nodeProps: [
|
|
17
|
-
[
|
|
18
|
-
[
|
|
19
|
-
[
|
|
17
|
+
["group", -11,4,70,73,75,78,80,82,84,85,96,98,"Statement",-17,6,16,17,18,19,20,21,24,28,31,36,37,40,56,59,61,66,"Expression",90,"ClassItem"],
|
|
18
|
+
["openedBy", 13,"%( (",22,"[",26,"{"],
|
|
19
|
+
["closedBy", -2,14,35,")",23,"]",27,"}"]
|
|
20
20
|
],
|
|
21
21
|
skippedNodes: [0,1,2],
|
|
22
22
|
repeatNodeCount: 11,
|
|
23
|
-
tokenData: "
|
|
23
|
+
tokenData: "Cr~R!^OX$}X^%U^p$}pq%Uqr&rrs'Xst$}tu'nuv)Yvw)mwx$}xy*Oyz*Xz{*b{|*m|}*x}!O+R!O!P+^!P!Q+w!Q!R3v!R![6]![!]6r!]!^$}!^!_6}!_!`7j!`!a7}!a!b8`!b!c$}!c!}8i!}#O:X#O#P:b#P#Q>e#Q#R>n#R#S'n#S#T$}#T#o'n#o#p>w#p#q?Q#q#r?c#r#s?l#s#y$}#y#z%U#z$f$}$f$g%U$g#BY'n#BY#BZ?w#BZ$IS'n$IS$I_?w$I_$I|'n$I|$JO?w$JO$JT'n$JT$JU?w$JU$KV'n$KV$KW?w$KW&FU'n&FU&FV?w&FV;'S'n;'S;=`Ce;=`<%lCm<%lO'nU%UO#gQ#qS!a%_Y#gQ#qS#d!ZX^%}pq%}#y#z%}$f$g%}#BY#BZ%}$IS$I_%}$I|$JO%}$JT$JU%}$KV$KW%}&FU&FV%}!Z&SY#d!ZX^%}pq%}#y#z%}$f$g%}#BY#BZ%}$IS$I_%}$I|$JO%}$JT$JU%}$KV$KW%}&FU&FV%}!X&}P$O`pP#gQ#qS!_!`'Q!R'XO#}`!Vq~'`PWT#gQrs'c~'fPrs'i~'nOV~!X'yW#gQ#qS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a@Uh#gQ#qS#l`#fq#d!ZX^%}pq%}tu(c!Q![(c!c!}(c#R#S(c#T#o(c#y#z%}$f$g%}$g#BY(c#BY#BZAp#BZ$IS(c$IS$I_Ap$I_$I|(c$I|$JOAp$JO$JT(c$JT$JUAp$JU$KV(c$KV$KWAp$KW&FU(c&FU&FVAp&FV;'S(c;'S;=`)S<%lO(c!ZAyh#l`#fq#d!ZX^%}pq%}tu(c!Q![(c!c!}(c#R#S(c#T#o(c#y#z%}$f$g%}$g#BY(c#BY#BZAp#BZ$IS(c$IS$I_Ap$I_$I|(c$I|$JOAp$JO$JT(c$JT$JUAp$JU$KV(c$KV$KWAp$KW&FU(c&FU&FVAp&FV;'S(c;'S;=`)S<%lO(c!XCjP#gQ;=`<%l'nQCrO#gQ",
|
|
24
24
|
tokenizers: [0, 1, 2, 3, 4, 5],
|
|
25
25
|
topRules: {"Script":[0,3]},
|
|
26
|
-
specialized: [{term: 114, get: value => spec_identifier[value] || -1},{term: 120, get: value => spec_word[value] || -1}],
|
|
27
|
-
tokenPrec:
|
|
26
|
+
specialized: [{term: 114, get: (value) => spec_identifier[value] || -1},{term: 120, get: (value) => spec_word[value] || -1}],
|
|
27
|
+
tokenPrec: 3694
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
/// A collection of Wren-related snippets
|
|
@@ -59,11 +59,265 @@ const snippets = [
|
|
|
59
59
|
detail: "as",
|
|
60
60
|
type: "keyword"
|
|
61
61
|
}),
|
|
62
|
+
snippetCompletion("if (${condition}) {\n\t${}\n}", {
|
|
63
|
+
label: "if",
|
|
64
|
+
detail: "block",
|
|
65
|
+
type: "keyword"
|
|
66
|
+
}),
|
|
67
|
+
snippetCompletion("if (${condition}) {\n\t${}\n} else {\n\t${}\n}", {
|
|
68
|
+
label: "if",
|
|
69
|
+
detail: "/ else block",
|
|
70
|
+
type: "keyword"
|
|
71
|
+
}),
|
|
72
|
+
snippetCompletion("while (${condition}) {\n\t${}\n}", {
|
|
73
|
+
label: "while",
|
|
74
|
+
detail: "loop",
|
|
75
|
+
type: "keyword"
|
|
76
|
+
}),
|
|
77
|
+
snippetCompletion("${name}(${params}) {\n\t${}\n}", {
|
|
78
|
+
label: "method",
|
|
79
|
+
detail: "definition",
|
|
80
|
+
type: "keyword"
|
|
81
|
+
}),
|
|
82
|
+
snippetCompletion("static ${name}(${params}) {\n\t${}\n}", {
|
|
83
|
+
label: "static",
|
|
84
|
+
detail: "method definition",
|
|
85
|
+
type: "keyword"
|
|
86
|
+
}),
|
|
87
|
+
snippetCompletion("construct new(${params}) {\n\t${}\n}", {
|
|
88
|
+
label: "construct",
|
|
89
|
+
detail: "constructor",
|
|
90
|
+
type: "keyword"
|
|
91
|
+
}),
|
|
62
92
|
];
|
|
63
93
|
|
|
94
|
+
// Wren's reserved words, and the classes and methods of its core library
|
|
95
|
+
// (https://wren.io/modules/core/) and the CLI's "random" module.
|
|
96
|
+
|
|
97
|
+
const keywords = ("as break class construct continue else false for foreign if " +
|
|
98
|
+
"import in is null return static super this true var while").split(" ");
|
|
99
|
+
|
|
100
|
+
const coreClasses = ("Bool Class Fiber Fn List Map Null Num Object Range " +
|
|
101
|
+
"Sequence String System").split(" ");
|
|
102
|
+
|
|
103
|
+
// Methods called on a class, as in `Num.fromString("1")`.
|
|
104
|
+
const staticMembers = {
|
|
105
|
+
Fiber: ["abort(message)", "current", "new(function)", "suspend()", "yield()", "yield(value)"],
|
|
106
|
+
Fn: ["new(function)"],
|
|
107
|
+
List: ["filled(size, element)", "new()"],
|
|
108
|
+
Map: ["new()"],
|
|
109
|
+
Num: ["fromString(value)", "infinity", "largest", "maxSafeInteger", "minSafeInteger",
|
|
110
|
+
"nan", "pi", "smallest", "tau"],
|
|
111
|
+
Object: ["same(obj1, obj2)"],
|
|
112
|
+
String: ["fromByte(byte)", "fromCodePoint(codePoint)"],
|
|
113
|
+
System: ["clock", "gc()", "print()", "print(object)", "printAll(sequence)",
|
|
114
|
+
"write(object)", "writeAll(sequence)"],
|
|
115
|
+
Random: ["new()", "new(seed)"],
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// Methods called on a value, as in `list.count`.
|
|
119
|
+
const instanceMembers = {
|
|
120
|
+
Object: ["toString", "type"],
|
|
121
|
+
Class: ["name", "supertype"],
|
|
122
|
+
Fiber: ["call()", "call(value)", "error", "isDone", "transfer()", "transfer(value)",
|
|
123
|
+
"transferError(error)", "try()", "try(value)"],
|
|
124
|
+
Fn: ["arity", "call()"],
|
|
125
|
+
Sequence: ["all(predicate)", "any(predicate)", "contains(element)", "count",
|
|
126
|
+
"count(predicate)", "each(function)", "isEmpty", "join()", "join(separator)",
|
|
127
|
+
"map(transformation)", "reduce(function)", "reduce(seed, function)", "skip(count)",
|
|
128
|
+
"take(count)", "toList", "where(predicate)"],
|
|
129
|
+
List: ["add(item)", "addAll(other)", "clear()", "indexOf(value)", "insert(index, item)",
|
|
130
|
+
"remove(value)", "removeAt(index)", "sort()", "sort(comparer)", "swap(index0, index1)"],
|
|
131
|
+
Map: ["containsKey(key)", "keys", "remove(key)", "values"],
|
|
132
|
+
Num: ["abs", "acos", "asin", "atan", "atan(x)", "cbrt", "ceil", "clamp(min, max)", "cos",
|
|
133
|
+
"exp", "floor", "fraction", "isInfinity", "isInteger", "isNan", "log", "log2",
|
|
134
|
+
"max(other)", "min(other)", "pow(power)", "round", "sign", "sin", "sqrt", "tan",
|
|
135
|
+
"truncate"],
|
|
136
|
+
Range: ["from", "isInclusive", "max", "min", "to"],
|
|
137
|
+
String: ["bytes", "codePoints", "endsWith(suffix)", "indexOf(search)",
|
|
138
|
+
"indexOf(search, start)", "replace(old, swap)", "split(separator)",
|
|
139
|
+
"startsWith(prefix)", "trim()", "trim(chars)", "trimEnd()", "trimEnd(chars)",
|
|
140
|
+
"trimStart()", "trimStart(chars)"],
|
|
141
|
+
Random: ["float()", "float(end)", "float(start, end)", "int(end)", "int(start, end)",
|
|
142
|
+
"sample(list)", "sample(list, count)", "shuffle(list)"],
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const ScopeNodes = new Set([
|
|
146
|
+
"Script", "Block", "BlockMaybeArgs", "MethodDeclaration", "ForStatement", "ClassBody"
|
|
147
|
+
]);
|
|
148
|
+
|
|
149
|
+
const dontComplete = [
|
|
150
|
+
"String", "LineComment", "BlockComment", "VariableDefinition", "ClassMethodName"
|
|
151
|
+
];
|
|
152
|
+
|
|
153
|
+
const Identifier = /^[\w$\xa1-]*$/;
|
|
154
|
+
|
|
155
|
+
// `foo.ba|` (the cursor is after a dot) is member completion's job.
|
|
156
|
+
function afterDot(context) {
|
|
157
|
+
return context.matchBefore(/\.\w*$/) != null
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function text(state, node) {
|
|
161
|
+
return state.sliceDoc(node.from, node.to)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function children(node, name) {
|
|
165
|
+
let found = [];
|
|
166
|
+
for (let child = node.firstChild; child; child = child.nextSibling)
|
|
167
|
+
if (child.name == name) found.push(child);
|
|
168
|
+
return found
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Instance method names in a class are in scope inside its body, because
|
|
172
|
+
// `count` there means `this.count`.
|
|
173
|
+
function methodName(state, method) {
|
|
174
|
+
let name = children(method, "ClassMethodName")[0];
|
|
175
|
+
let match = name && /^[A-Za-z_]\w*/.exec(text(state, name));
|
|
176
|
+
return match ? match[0] : null
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function classBodyNames(state, body, add) {
|
|
180
|
+
for (let method of children(body, "MethodDeclaration")) {
|
|
181
|
+
let name = methodName(state, method);
|
|
182
|
+
if (name) add(name, "method");
|
|
183
|
+
}
|
|
184
|
+
// Fields (`_name`) and static fields (`__name`) are created by assigning
|
|
185
|
+
// to them anywhere in the class.
|
|
186
|
+
body.cursor().iterate(node => {
|
|
187
|
+
if (node.name == "VariableName") {
|
|
188
|
+
let name = text(state, node);
|
|
189
|
+
if (name.startsWith("_")) add(name, "property");
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function scopeNames(state, scope, add) {
|
|
195
|
+
if (scope.name == "ClassBody") return classBodyNames(state, scope, add)
|
|
196
|
+
let gather = node => {
|
|
197
|
+
for (let child = node.firstChild; child; child = child.nextSibling) {
|
|
198
|
+
if (child.name == "ImportName") {
|
|
199
|
+
// In `import "x" for A as B`, only `B` is in scope.
|
|
200
|
+
let defs = children(child, "VariableDefinition");
|
|
201
|
+
let name = text(state, defs[defs.length - 1]);
|
|
202
|
+
add(name, /^[A-Z]/.test(name) ? "class" : "variable");
|
|
203
|
+
} else if (child.name == "ClassDeclaration") {
|
|
204
|
+
let name = children(child, "ClassName")[0];
|
|
205
|
+
if (name) add(text(state, name), "class");
|
|
206
|
+
} else if (child.name == "VariableDefinition") {
|
|
207
|
+
add(text(state, child), "variable");
|
|
208
|
+
} else if (!ScopeNodes.has(child.name)) {
|
|
209
|
+
gather(child);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
gather(scope);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/// Completes the names of variables, parameters, classes, methods and
|
|
217
|
+
/// fields that are in scope at the cursor.
|
|
218
|
+
function localCompletionSource(context) {
|
|
219
|
+
let inner = syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
220
|
+
if (dontComplete.includes(inner.name) || afterDot(context)) return null
|
|
221
|
+
let word = context.matchBefore(/[\w$\xa1-]+$/);
|
|
222
|
+
if (!word && !context.explicit) return null
|
|
223
|
+
let seen = new Set(), options = [];
|
|
224
|
+
let add = (label, type) => {
|
|
225
|
+
if (seen.has(label)) return
|
|
226
|
+
seen.add(label);
|
|
227
|
+
options.push({label, type});
|
|
228
|
+
};
|
|
229
|
+
for (let pos = inner; pos; pos = pos.parent)
|
|
230
|
+
if (ScopeNodes.has(pos.name)) scopeNames(context.state, pos, add);
|
|
231
|
+
return {options, from: word ? word.from : context.pos, validFor: Identifier}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function memberOptions(signatures) {
|
|
235
|
+
let byName = new Map();
|
|
236
|
+
for (let sig of signatures) {
|
|
237
|
+
let paren = sig.indexOf("(");
|
|
238
|
+
let name = paren < 0 ? sig : sig.slice(0, paren);
|
|
239
|
+
let args = paren < 0 ? "" : sig.slice(paren);
|
|
240
|
+
if (!byName.has(name)) byName.set(name, []);
|
|
241
|
+
if (args) byName.get(name).push(args);
|
|
242
|
+
}
|
|
243
|
+
return [...byName].map(([label, args]) => ({
|
|
244
|
+
label,
|
|
245
|
+
type: args.length ? "method" : "property",
|
|
246
|
+
detail: args.join(" ") || undefined
|
|
247
|
+
}))
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const staticOptions = {};
|
|
251
|
+
for (let name in staticMembers) staticOptions[name] = memberOptions(staticMembers[name]);
|
|
252
|
+
|
|
253
|
+
const instanceOptions = memberOptions(Object.values(instanceMembers).flat());
|
|
254
|
+
|
|
255
|
+
function fileClasses(state) {
|
|
256
|
+
let classes = new Map();
|
|
257
|
+
syntaxTree(state).topNode.cursor().iterate(node => {
|
|
258
|
+
if (node.name != "ClassDeclaration") return
|
|
259
|
+
let decl = node.node;
|
|
260
|
+
let name = children(decl, "ClassName")[0];
|
|
261
|
+
let body = children(decl, "ClassBody")[0];
|
|
262
|
+
if (!name || !body) return false
|
|
263
|
+
let statics = [], instance = [];
|
|
264
|
+
for (let method of children(body, "MethodDeclaration")) {
|
|
265
|
+
let label = methodName(state, method);
|
|
266
|
+
if (!label) continue
|
|
267
|
+
let onClass = children(method, "static").length || children(method, "construct").length
|
|
268
|
+
;(onClass ? statics : instance).push({label, type: "method"});
|
|
269
|
+
}
|
|
270
|
+
classes.set(text(state, name), {statics, instance});
|
|
271
|
+
return false
|
|
272
|
+
});
|
|
273
|
+
return classes
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/// Completes method names after a dot. After a class name, it offers that
|
|
277
|
+
/// class's static methods and constructors. After anything else, it offers
|
|
278
|
+
/// the instance methods of the core classes and of classes in the file.
|
|
279
|
+
function memberCompletionSource(context) {
|
|
280
|
+
let inner = syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
281
|
+
if (dontComplete.includes(inner.name)) return null
|
|
282
|
+
let member = context.matchBefore(/\.\w*$/);
|
|
283
|
+
if (!member) return null
|
|
284
|
+
let line = context.state.doc.lineAt(member.from);
|
|
285
|
+
let before = context.state.sliceDoc(line.from, member.from);
|
|
286
|
+
// `0..1` is a range.
|
|
287
|
+
if (before.endsWith(".")) return null
|
|
288
|
+
let receiver = /([A-Za-z_]\w*)\s*$/.exec(before);
|
|
289
|
+
let name = receiver ? receiver[1] : null;
|
|
290
|
+
let classes = fileClasses(context.state);
|
|
291
|
+
let options;
|
|
292
|
+
if (name && classes.has(name)) options = classes.get(name).statics;
|
|
293
|
+
else if (name && staticOptions[name]) options = staticOptions[name];
|
|
294
|
+
else if (name && /^[A-Z]/.test(name)) options = [];
|
|
295
|
+
else {
|
|
296
|
+
options = [...instanceOptions];
|
|
297
|
+
for (let cls of classes.values()) options.push(...cls.instance);
|
|
298
|
+
}
|
|
299
|
+
let seen = new Set();
|
|
300
|
+
options = options.filter(o => !seen.has(o.label) && seen.add(o.label));
|
|
301
|
+
return {options, from: member.from + 1, validFor: Identifier}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const globals = snippets.concat(
|
|
305
|
+
keywords.map(label => ({label, type: "keyword"})),
|
|
306
|
+
coreClasses.map(label => ({label, type: "class"}))
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
const globalList = completeFromList(globals);
|
|
310
|
+
|
|
311
|
+
/// Completes snippets, keywords and the core classes.
|
|
312
|
+
function globalCompletionSource(context) {
|
|
313
|
+
let inner = syntaxTree(context.state).resolveInner(context.pos, -1);
|
|
314
|
+
if (dontComplete.includes(inner.name) || afterDot(context)) return null
|
|
315
|
+
return globalList(context)
|
|
316
|
+
}
|
|
317
|
+
|
|
64
318
|
const lezerParser = parser;
|
|
65
319
|
|
|
66
|
-
const wrenLanguage =
|
|
320
|
+
const wrenLanguage = LRLanguage.define({
|
|
67
321
|
parser: parser.configure({
|
|
68
322
|
props: [
|
|
69
323
|
indentNodeProp.add({
|
|
@@ -130,12 +384,13 @@ const wrenLanguage = LezerLanguage.define({
|
|
|
130
384
|
});
|
|
131
385
|
|
|
132
386
|
|
|
133
|
-
/// Wren support. Includes snippets
|
|
387
|
+
/// Wren support. Includes completion of snippets, keywords, core
|
|
388
|
+
/// classes, names in scope and methods after a dot.
|
|
134
389
|
function wren(config = {}) {
|
|
135
390
|
let lang = wrenLanguage;
|
|
136
|
-
return new LanguageSupport(lang,
|
|
137
|
-
|
|
138
|
-
}))
|
|
391
|
+
return new LanguageSupport(lang, [
|
|
392
|
+
globalCompletionSource, localCompletionSource, memberCompletionSource
|
|
393
|
+
].map(autocomplete => wrenLanguage.data.of({autocomplete})))
|
|
139
394
|
}
|
|
140
395
|
|
|
141
|
-
export { lezerParser, snippets, wren, wrenLanguage };
|
|
396
|
+
export { globalCompletionSource, lezerParser, localCompletionSource, memberCompletionSource, snippets, wren, wrenLanguage };
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { Completion } from "@codemirror/autocomplete"
|
|
2
|
-
import { LanguageSupport,
|
|
1
|
+
import { Completion, CompletionSource } from "@codemirror/autocomplete"
|
|
2
|
+
import { LanguageSupport, LRLanguage } from "@codemirror/language"
|
|
3
3
|
|
|
4
|
-
export const wrenLanguage:
|
|
4
|
+
export const wrenLanguage: LRLanguage
|
|
5
5
|
export function wren(config?: {}): LanguageSupport
|
|
6
6
|
export const snippets: Completion[]
|
|
7
|
-
|
|
7
|
+
export const localCompletionSource: CompletionSource
|
|
8
|
+
export const memberCompletionSource: CompletionSource
|
|
9
|
+
export const globalCompletionSource: CompletionSource
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exercism/codemirror-lang-wren",
|
|
3
3
|
"description": "Wren Lezer parser and language support for CodeMirror",
|
|
4
|
-
"author": "Josh Goebel <
|
|
5
|
-
"version": "0.
|
|
4
|
+
"author": "Josh Goebel <hello@joshgoebel.com>",
|
|
5
|
+
"version": "1.0.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/exercism/codemirror-lang-wren"
|
|
9
|
+
"url": "git+https://github.com/exercism/codemirror-lang-wren.git"
|
|
10
10
|
},
|
|
11
11
|
"imports": {
|
|
12
12
|
"#parser": "./src/lezer/parser.js"
|
|
@@ -28,18 +28,18 @@
|
|
|
28
28
|
"build-devtool": "npm run build-grammar && rollup -c rollup.config.devtool.js"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@codemirror/autocomplete": "^0.
|
|
32
|
-
"@codemirror/
|
|
33
|
-
"@
|
|
31
|
+
"@codemirror/autocomplete": "^6.0.0",
|
|
32
|
+
"@codemirror/language": "^6.0.0",
|
|
33
|
+
"@lezer/highlight": "^1.0.0",
|
|
34
|
+
"@lezer/lr": "^1.0.0"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
|
-
"
|
|
37
|
-
"@
|
|
37
|
+
"codemirror": "^6.0.0",
|
|
38
|
+
"@lezer/generator": "^1.1.1",
|
|
39
|
+
"@rollup/plugin-node-resolve": "^14.1.0",
|
|
38
40
|
"colors": "^1.4.0",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"mocha": "^9.0.0",
|
|
42
|
-
"rollup": "^2.50.4"
|
|
41
|
+
"rollup": "^2.50.4",
|
|
42
|
+
"mocha": "^10.0.0"
|
|
43
43
|
},
|
|
44
44
|
"files": [
|
|
45
45
|
"dist",
|