codemirror-lang-glimmer 0.0.0-beta.3 → 0.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/.eslintrc.cjs +2 -2
- package/.turbo/turbo-build.log +5 -21
- package/.turbo/turbo-lint$colon$js$colon$fix.log +7 -0
- package/.turbo/turbo-lint$colon$js.log +7 -0
- package/.turbo/turbo-lint$colon$prettier$colon$fix.log +15 -0
- package/.turbo/turbo-lint$colon$prettier.log +9 -0
- package/.turbo/turbo-lint$colon$types.log +5 -0
- package/CHANGELOG.md +15 -0
- package/LICENSE +21 -0
- package/dev/.eslintcache +1 -0
- package/dev/.eslintrc.cjs +2 -2
- package/dev/CHANGELOG.md +3 -0
- package/dev/index.html +1 -1
- package/dev/index.ts +43 -3
- package/dev/node_modules/.bin/eslint +4 -4
- package/dev/node_modules/.bin/prettier +4 -4
- package/dev/node_modules/.bin/tsc +4 -4
- package/dev/node_modules/.bin/tsserver +4 -4
- package/dev/node_modules/.bin/vite +4 -4
- package/dev/package.json +28 -16
- package/dev/watch.cjs +3 -3
- package/dist/index.cjs +222 -321
- package/dist/index.d.cts +22 -4
- package/dist/index.d.ts +22 -4
- package/dist/index.js +224 -325
- package/package.json +42 -26
- package/src/auto-close.ts +91 -0
- package/src/glimmer.ts +79 -0
- package/src/index.ts +3 -154
- package/src/language.ts +176 -0
- package/src/snippets.ts +48 -0
- package/tsconfig.json +2 -1
- package/.eslintignore +0 -2
- package/.prettierignore +0 -2
- package/.prettierrc.cjs +0 -20
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/src/highlight.ts +0 -57
- package/src/syntax.grammar +0 -139
- package/src/syntax.grammar.d.ts +0 -3
- package/src/syntax.grammar.terms.d.ts +0 -14
- package/src/tokens.ts +0 -277
- package/tests/.eslintrc.cjs +0 -5
- package/tests/comments.txt +0 -116
- package/tests/complex.txt +0 -24
- package/tests/expression.txt +0 -95
- package/tests/literals.txt +0 -78
- package/tests/node_modules/.bin/eslint +0 -17
- package/tests/node_modules/.bin/prettier +0 -17
- package/tests/node_modules/.bin/tsc +0 -17
- package/tests/node_modules/.bin/tsserver +0 -17
- package/tests/numbers.txt +0 -88
- package/tests/package.json +0 -25
- package/tests/property-paths.txt +0 -79
- package/tests/strings.txt +0 -64
package/dist/index.js
CHANGED
|
@@ -1,313 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { snippetCompletion, CompletionContext } from '@codemirror/autocomplete';
|
|
2
|
+
import { cssLanguage, css } from '@codemirror/lang-css';
|
|
3
|
+
import { html, htmlCompletionSource } from '@codemirror/lang-html';
|
|
4
|
+
import { typescriptLanguage, javascriptLanguage, javascript } from '@codemirror/lang-javascript';
|
|
5
|
+
import { LRLanguage, indentNodeProp, foldNodeProp, syntaxTree, LanguageSupport } from '@codemirror/language';
|
|
6
|
+
import { EditorSelection, EditorState } from '@codemirror/state';
|
|
7
|
+
import { parser } from '@glimdown/lezer-glimmer-expression';
|
|
8
|
+
import { EditorView } from '@codemirror/view';
|
|
9
|
+
import { glimmerParser, configureNesting } from 'lezer-glimmer';
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const slash = 47;
|
|
26
|
-
const greaterThan = 62;
|
|
27
|
-
const dash = 45;
|
|
28
|
-
const quoteDouble = 34;
|
|
29
|
-
const quoteSingle = 39;
|
|
30
|
-
const backslash = 92;
|
|
31
|
-
const newline = 10;
|
|
32
|
-
const asterisk = 42;
|
|
33
|
-
const tick = 96;
|
|
34
|
-
const prefixes = [colon, hash, at, slash];
|
|
35
|
-
const shortCommentEnd = [curlyClose, curlyClose];
|
|
36
|
-
const longCommentEnd = [dash, dash, curlyClose, curlyClose];
|
|
37
|
-
const htmlCommentEnd = [dash, dash, greaterThan];
|
|
38
|
-
// Is there a way to make this a build time (rather than eval-time?) operation?
|
|
39
|
-
const closingTemplateTag = '</template>'.split('').map((char) => char.charCodeAt(0));
|
|
40
|
-
function matchForComment(commentEndPattern, commentToken, input) {
|
|
41
|
-
for (let found = 0, i = 0;; i++) {
|
|
42
|
-
if (input.next < 0) {
|
|
43
|
-
if (i)
|
|
44
|
-
input.acceptToken(commentToken);
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
let hasMatch = commentEndPattern[found] === input.next;
|
|
48
|
-
if (!hasMatch) {
|
|
49
|
-
found = 0;
|
|
50
|
-
input.advance();
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
if (found === commentEndPattern.length - 1) {
|
|
54
|
-
if (i > commentEndPattern.length - 1) {
|
|
55
|
-
input.acceptToken(commentToken, 1 - commentEndPattern.length);
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
console.warn('Reached end of comment but there is still content left');
|
|
60
|
-
}
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
found++;
|
|
64
|
-
input.advance();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
const shortCommentContent = new ExternalTokenizer((input) => {
|
|
68
|
-
return matchForComment(shortCommentEnd, shortCommentContent$1, input);
|
|
69
|
-
});
|
|
70
|
-
const longCommentContent = new ExternalTokenizer((input) => {
|
|
71
|
-
return matchForComment(longCommentEnd, longCommentContent$1, input);
|
|
72
|
-
});
|
|
73
|
-
const htmlCommentContent = new ExternalTokenizer((input) => {
|
|
74
|
-
return matchForComment(htmlCommentEnd, htmlCommentContent$1, input);
|
|
75
|
-
});
|
|
76
|
-
const templateTagContent = new ExternalTokenizer((input) => {
|
|
77
|
-
return matchForComment(closingTemplateTag, templateTagContent$1, input);
|
|
78
|
-
});
|
|
79
|
-
// TODO: string handler does not handle interpolation
|
|
80
|
-
function createStringHandler(input) {
|
|
81
|
-
let inString = false;
|
|
82
|
-
let inStringType = null;
|
|
83
|
-
let inStringIgnoreNext = false;
|
|
84
|
-
return () => {
|
|
85
|
-
if (inString) {
|
|
86
|
-
if (inStringIgnoreNext) {
|
|
87
|
-
inStringIgnoreNext = false;
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
if (input.next === backslash) {
|
|
91
|
-
inStringIgnoreNext = true;
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
if (inStringType === 'double' && input.next === quoteDouble) {
|
|
95
|
-
inString = false;
|
|
96
|
-
inStringType = null;
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
if (inStringType === 'single' && input.next === quoteSingle) {
|
|
100
|
-
inString = false;
|
|
101
|
-
inStringType = null;
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
if (inStringType === 'template' && input.next === tick) {
|
|
105
|
-
inString = false;
|
|
106
|
-
inStringType = null;
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
return true;
|
|
110
|
-
}
|
|
111
|
-
if (input.next === quoteDouble) {
|
|
112
|
-
inString = true;
|
|
113
|
-
inStringType = 'double';
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
if (input.next === quoteSingle) {
|
|
117
|
-
inString = true;
|
|
118
|
-
inStringType = 'single';
|
|
119
|
-
return true;
|
|
120
|
-
}
|
|
121
|
-
if (input.next === tick) {
|
|
122
|
-
inString = true;
|
|
123
|
-
inStringType = 'template';
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
return false;
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
function createCommentHandler(input) {
|
|
130
|
-
let inLineComment = false;
|
|
131
|
-
let inBlockComment = false;
|
|
132
|
-
return () => {
|
|
133
|
-
if (inLineComment) {
|
|
134
|
-
if (input.next === newline) {
|
|
135
|
-
inLineComment = false;
|
|
136
|
-
return true;
|
|
137
|
-
}
|
|
138
|
-
return true;
|
|
139
|
-
}
|
|
140
|
-
if (inBlockComment) {
|
|
141
|
-
if (input.next === asterisk && input.peek(1) === slash) {
|
|
142
|
-
inBlockComment = false;
|
|
143
|
-
return true;
|
|
144
|
-
}
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
if (input.next === slash && input.peek(1) === slash) {
|
|
148
|
-
inLineComment = true;
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
if (input.next === slash && input.peek(1) === asterisk) {
|
|
152
|
-
inBlockComment = true;
|
|
11
|
+
const defaultNesting = [
|
|
12
|
+
{
|
|
13
|
+
tag: 'script',
|
|
14
|
+
attrs: (attrs) => attrs['type'] === 'text/typescript' || attrs['lang'] === 'ts',
|
|
15
|
+
parser: typescriptLanguage.parser,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
tag: 'script',
|
|
19
|
+
attrs(attrs) {
|
|
20
|
+
return (!attrs['type'] ||
|
|
21
|
+
/^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i.test(attrs['type']));
|
|
22
|
+
},
|
|
23
|
+
parser: javascriptLanguage.parser,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
tag: 'style',
|
|
27
|
+
attrs( /* attrs */) {
|
|
153
28
|
return true;
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
//
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
let stack = [];
|
|
166
|
-
const popIfMatch = (match) => {
|
|
167
|
-
const idx = stack.lastIndexOf(match);
|
|
168
|
-
if (idx !== -1) {
|
|
169
|
-
while (stack.length > idx) {
|
|
170
|
-
stack.pop();
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
for (let pos = 0;; pos++) {
|
|
175
|
-
// end of input
|
|
176
|
-
if (input.next < 0) {
|
|
177
|
-
if (pos > 0)
|
|
178
|
-
input.acceptToken(MoustacheExpression);
|
|
179
|
-
break;
|
|
180
|
-
}
|
|
181
|
-
if (commentHandler() || stringHandler()) {
|
|
182
|
-
input.advance();
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
if (stack.length === 0 &&
|
|
186
|
-
(input.next === curlyClose || input.next === parenClose || input.next === squareClose)) {
|
|
187
|
-
input.acceptToken(MoustacheExpression);
|
|
188
|
-
break;
|
|
189
|
-
}
|
|
190
|
-
switch (input.next) {
|
|
191
|
-
case parenOpen:
|
|
192
|
-
stack.push('(');
|
|
193
|
-
break;
|
|
194
|
-
case parenClose:
|
|
195
|
-
popIfMatch('(');
|
|
196
|
-
break;
|
|
197
|
-
case squareOpen:
|
|
198
|
-
stack.push('[');
|
|
199
|
-
break;
|
|
200
|
-
case squareClose:
|
|
201
|
-
popIfMatch('[');
|
|
202
|
-
break;
|
|
203
|
-
case curlyOpen:
|
|
204
|
-
stack.push('{');
|
|
205
|
-
break;
|
|
206
|
-
case curlyClose:
|
|
207
|
-
popIfMatch('{');
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
input.advance();
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
const glimmerHighlighting = styleTags({
|
|
215
|
-
'Text RawText': tags.content,
|
|
216
|
-
'StartTag StartCloseTag SelfClosingEndTag EndTag': tags.angleBracket,
|
|
217
|
-
TagName: tags.tagName,
|
|
218
|
-
'MismatchedCloseTag/TagName': [tags.tagName, tags.invalid],
|
|
219
|
-
AttributeName: tags.attributeName,
|
|
220
|
-
// Glimmer
|
|
221
|
-
TemplateTag: tags.definition(tags.annotation),
|
|
222
|
-
'{{ }}': tags.bracket,
|
|
223
|
-
'( )': tags.paren,
|
|
224
|
-
Function: tags.function(tags.name),
|
|
225
|
-
Splattributes: tags.derefOperator,
|
|
226
|
-
Comment: tags.blockComment,
|
|
227
|
-
ShortComment: tags.blockComment,
|
|
228
|
-
LongComment: tags.blockComment,
|
|
229
|
-
HtmlComment: tags.blockComment,
|
|
230
|
-
ArgName: tags.attributeName,
|
|
231
|
-
Argument: tags.propertyName,
|
|
232
|
-
NamedBlock: tags.tagName,
|
|
233
|
-
Is: tags.definitionOperator,
|
|
234
|
-
Pipe: tags.definitionOperator,
|
|
235
|
-
as: tags.definitionOperator,
|
|
236
|
-
let: tags.function(tags.definitionOperator),
|
|
237
|
-
this: tags.self,
|
|
238
|
-
yield: tags.operatorKeyword,
|
|
239
|
-
outlet: tags.operatorKeyword,
|
|
240
|
-
component: tags.function(tags.definitionKeyword),
|
|
241
|
-
modifier: tags.function(tags.definitionKeyword),
|
|
242
|
-
helper: tags.function(tags.definitionKeyword),
|
|
243
|
-
hash: tags.function(tags.definitionKeyword),
|
|
244
|
-
array: tags.function(tags.definitionKeyword),
|
|
245
|
-
on: tags.function(tags.definitionKeyword),
|
|
246
|
-
concat: tags.function(tags.operatorKeyword),
|
|
247
|
-
'if then catch unless else each each-in': tags.controlKeyword,
|
|
248
|
-
// TODO:
|
|
249
|
-
UnquotedAttributeValue: tags.attributeValue,
|
|
250
|
-
'DoubleQuote SingleQuote AttributeValueContent': tags.attributeValue,
|
|
251
|
-
'EntityReference CharacterReference': tags.character,
|
|
252
|
-
'[ ]': tags.squareBracket,
|
|
253
|
-
ComponentName: tags.className,
|
|
254
|
-
StyleAttributeName: tags.propertyName,
|
|
255
|
-
BlockType: tags.controlKeyword,
|
|
256
|
-
BlockPrefix: tags.typeOperator,
|
|
257
|
-
'UnknownBlock/BlockType': tags.invalid,
|
|
258
|
-
UnknownBlockContent: tags.invalid,
|
|
259
|
-
Variable: tags.variableName,
|
|
260
|
-
Modifier: tags.modifier,
|
|
261
|
-
ModifierValue: tags.function(tags.modifier),
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
265
|
-
const spec_identifier = {__proto__:null,this:36, as:38, if:40, unless:42, else:44, let:46, and:48, or:50, not:52, eq:54, neq:56, "not-eq":58, gt:60, gte:62, lt:64, lte:66, array:68, concat:70, hash:72, each:74, "each-in":76, on:78, modifier:80, component:82, helper:84, "in-element":86, yield:88, outlet:90};
|
|
266
|
-
const parser = LRParser.deserialize({
|
|
267
|
-
version: 14,
|
|
268
|
-
states: "(dQVQ`OOOwQhO'#C^O!PQaO'#CbO!XQbO'#CcO!aQ`O'#CmO$oOpO'#CeO$vO`O'#CeO${QdO'#CdOOQO'#Ca'#CaOOQO'#D]'#D]O%^Q`O'#D^OOQO'#Dl'#DlOOQO'#D_'#D_QVQ`OOOOQW'#D`'#D`O%cQhO,58xOOQO,58x,58xOOQP'#Da'#DaO%kQaO,58|OOQO,58|,58|OOQQ'#Db'#DbO%sQbO,58}OOQO,58},58}OOQO,59X,59XO(RQ`O'#ChOOOO'#Cg'#CgOOOO'#Dd'#DdO(]OpO,59POOQS,59P,59POOOO'#Dt'#DtO(dOpO,59POOQS'#Dc'#DcO(iQdO,59OOOQO,59O,59OOOQO,59x,59xOOQO-E7]-E7]OOQW-E7^-E7^OOQO1G.d1G.dOOQP-E7_-E7_OOQO1G.h1G.hOOQQ-E7`-E7`OOQO1G.i1G.iOOOO,59S,59SO(zQ`O,59SO)VQ`O,59SOOOO-E7b-E7bOOQS1G.k1G.kOOQS-E7a-E7aOOQO1G.j1G.jO!fQ`O1G.nOOOO1G.n1G.nO)_Q`O1G.nO)dQ`O7+$YO!fQ`O7+$YOOOO<<Gt<<GtO)iQ`O<<GtOOOOAN=`AN=`",
|
|
269
|
-
stateData: ")p~O!_OS~ORPOYTO!aQO!cRO!eVO!gSO!iTO!jUO!lXO!mYO~OS`O!]^O~O!YaO!bcO~O!ZdO!dfO~O!fgO~O]hO^iO`iObmOcmOdmOemOfmOgmOhmOimOjmOkmOlmOmmOnmOomOpmOqmOrmOsmOtmOumOvmOwmOxmOymOzmO{mO|mO}mO!fiO!gSO~O!OlO~P!fO!fnO~OYTO![oO!iTO!jUO!kqO~O!frO~OSuO!]^O~O!YaO!bwO~O!ZdO!dyO~O]hO^iO`iObmOcmOdmOemOfmOgmOhmOimOjmOkmOlmOmmOnmOomOpmOqmOrmOsmOtmOumOvmOwmOxmOymOzmO{mO|mO}mO!gSO~O_zO!f{O~P%{O!O!OO~P!fO!O!OO~OYTO![oO!iTO!jUO!k!QO~O^!RO_ZX!fZX~O_!SO!f!TO~O^!VO~O_!WO~O_!YO~O!_~",
|
|
270
|
-
goto: "$e!iPP!jPP!j!n!n!n!rP!z#XPPPP#`PPPPPPPPPPPPPPPPPPPPPPPPPPPPP!j!j#k#q#w#}$T$ZPPPPPPP$aPPPPPPP#XTZO]TWO]SZO]ToVpSjTkQ|hQ!U!RR!X!VZiThk!R!VSZO]ZiThk!R!VQ]ORs]Q_PRt_QbQRvbQeRRxeQpVR!PpQkTR}kT[O]",
|
|
271
|
-
nodeNames: "⚠ Template GlimmerTemplateTag TemplateTag TemplateTag Comment ShortComment LongComment HtmlComment MoustacheExpression {{ SExpression CallExpression ( Is ) Pipe Argument this as if unless else let and or not eq neq not-eq gt gte lt lte array concat hash each each-in on modifier component helper in-element yield outlet }} Splattributes NamedBlock",
|
|
272
|
-
maxTerm: 75,
|
|
273
|
-
nodeProps: [
|
|
274
|
-
["closedBy", 3,"templateTagEnd",10,"}}",13,"("],
|
|
275
|
-
["openedBy", 4,"templateTagStart",15,")",46,"{{"]
|
|
276
|
-
],
|
|
277
|
-
propSources: [glimmerHighlighting],
|
|
278
|
-
skippedNodes: [0],
|
|
279
|
-
repeatNodeCount: 6,
|
|
280
|
-
tokenData: "+W~RhX^!mpq!mxy#eyz#j|}!m}!O#o!O!P$`![!]&P!^!_&U!_!`)X!b!c)^!c!})c#T#o)c#o#p)q#p#q*t#q#r*y#y#z!m$f$g!m#BY#BZ!m$IS$I_!m$I|$JO!m$JT$JU!m$KV$KW!m&FU&FV!m~!rZ!_~X^!mpq!m|}!m#y#z!m$f$g!m#BY#BZ!m$IS$I_!m$I|$JO!m$JT$JU!m$KV$KW!m&FU&FV!m~#jO]~~#oO_~~#rP}!O#u~#xQ!`!a$O#q#r$T~$TO!k~~$WP#q#r$Z~$`O!d~~$cP!O!P$f~$iP!O!P$l~$oP#T#U$r~$uP#h#i$x~${P#h#i%O~%RP#f#g%U~%XP#]#^%[~%_P#U#V%b~%eP#i#j%h~%kP#h#i%n~%qP#X#Y%t~%wP#g#h%z~&PO!l~~&UO!m~~&XRqr&b!P!Q&s#h#i(Q~&eP}!O&h~&kP}!O&n~&sO!e~~&vP#h#i&y~&|P#X#Y'P~'SP#a#b'V~'YP#d#e']~'`P#`#a'c~'fP#T#U'i~'lP#h#i'o~'rP#X#Y'u~'xP!`!a'{~(QOS~~(TP#X#Y(W~(ZP#a#b(^~(aP#d#e(d~(gP#`#a(j~(mP#T#U(p~(sP#h#i(v~(yP#X#Y(|~)PP!`!a)S~)XOR~~)^O^~~)cO!g~~)hR!f~!Q![)c!c!})c#T#o)c~)tP#o#p)w~)|RY~qr*Vst*j!P!Q*o~*[P!a~}!O*_~*bP}!O*e~*jO!c~~*oO!i~~*tO!j~~*yO`~R*|P#q#r+PR+WO!OQ!bP",
|
|
281
|
-
tokenizers: [shortCommentContent, longCommentContent, htmlCommentContent, templateTagContent, 0, 1],
|
|
282
|
-
topRules: {"Template":[0,1]},
|
|
283
|
-
specialized: [{term: 68, get: value => spec_identifier[value] || -1}],
|
|
284
|
-
tokenPrec: 398
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
const glimmerParser = parser;
|
|
288
|
-
const glimmerLanguage = LRLanguage.define({
|
|
289
|
-
parser: parser.configure({
|
|
290
|
-
wrap: parseMixed((node) => {
|
|
291
|
-
let { name } = node.type;
|
|
292
|
-
switch (name) {
|
|
293
|
-
case 'Template':
|
|
294
|
-
return null;
|
|
295
|
-
case 'Comment':
|
|
296
|
-
case 'MoustacheExpression':
|
|
297
|
-
case 'NamedBlock':
|
|
298
|
-
case 'Splattributes':
|
|
299
|
-
case 'Argument':
|
|
300
|
-
return { parser };
|
|
301
|
-
}
|
|
302
|
-
return { parser: parser$1 };
|
|
303
|
-
}),
|
|
29
|
+
// Always use CSS. We can add varying support later
|
|
30
|
+
// return (
|
|
31
|
+
// (!attrs['lang'] || attrs['lang'] === 'css' || attrs['lang'] === 'scss') &&
|
|
32
|
+
// (!attrs['type'] || /^(text\/)?(x-)?(stylesheet|css|scss)$/i.test(attrs['type']))
|
|
33
|
+
// );
|
|
34
|
+
},
|
|
35
|
+
parser: cssLanguage.parser,
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
const glimmerPlain = /*@__PURE__*/LRLanguage.define({
|
|
39
|
+
parser: /*@__PURE__*/glimmerParser.configure({
|
|
304
40
|
props: [
|
|
305
|
-
indentNodeProp.add({
|
|
41
|
+
/*@__PURE__*/indentNodeProp.add({
|
|
306
42
|
Element: (context) => {
|
|
307
43
|
let after = /^(\s*)(<\/)?/.exec(context.textAfter);
|
|
308
|
-
if (
|
|
44
|
+
if (!after)
|
|
45
|
+
return null;
|
|
46
|
+
if (context.node.to <= context.pos + after[0].length)
|
|
309
47
|
return context.continue();
|
|
310
|
-
return context.lineIndent(context.node.from) + (after
|
|
48
|
+
return context.lineIndent(context.node.from) + (after[2] ? 0 : context.unit);
|
|
311
49
|
},
|
|
312
50
|
Block: (context) => {
|
|
313
51
|
const node = context.node;
|
|
@@ -315,13 +53,19 @@ const glimmerLanguage = LRLanguage.define({
|
|
|
315
53
|
if (text.startsWith('{/')) {
|
|
316
54
|
const name = node.name;
|
|
317
55
|
if ((name === 'IfBlock' && text.startsWith('{/if')) ||
|
|
56
|
+
(name === 'UnlessBlock' && text.startsWith('{/unless')) ||
|
|
57
|
+
(name === 'InElementBlock' && text.startsWith('{/in-element')) ||
|
|
318
58
|
(name === 'EachBlock' && text.startsWith('{/each')) ||
|
|
319
|
-
(name === '
|
|
59
|
+
(name === 'EachInBlock' && text.startsWith('{/each-in')) ||
|
|
60
|
+
(name === 'LetBlock' && text.startsWith('{/let'))) {
|
|
320
61
|
return context.lineIndent(context.node.from);
|
|
321
62
|
}
|
|
322
63
|
return null;
|
|
323
64
|
}
|
|
324
|
-
if (node.name === 'IfBlock' ||
|
|
65
|
+
if (node.name === 'IfBlock' ||
|
|
66
|
+
node.name === 'EachBlock' ||
|
|
67
|
+
node.name === 'EachInBlock' ||
|
|
68
|
+
node.name === 'UnlessBlock') {
|
|
325
69
|
if (text.startsWith('{{:else'))
|
|
326
70
|
return context.lineIndent(node.from);
|
|
327
71
|
if (text.startsWith('{{else'))
|
|
@@ -329,9 +73,11 @@ const glimmerLanguage = LRLanguage.define({
|
|
|
329
73
|
}
|
|
330
74
|
// not sure if this needed to be duplicated
|
|
331
75
|
let after = /^(\s*)(<\/)?/.exec(context.textAfter);
|
|
332
|
-
if (
|
|
76
|
+
if (!after)
|
|
77
|
+
return null;
|
|
78
|
+
if (context.node.to <= context.pos + after[0].length)
|
|
333
79
|
return context.continue();
|
|
334
|
-
return context.lineIndent(context.node.from) + (after
|
|
80
|
+
return context.lineIndent(context.node.from) + (after[2] ? 0 : context.unit);
|
|
335
81
|
},
|
|
336
82
|
'BlockOpen BlockClose BlockInline': (context) => {
|
|
337
83
|
return context.column(context.node.from) + context.unit;
|
|
@@ -340,7 +86,8 @@ const glimmerLanguage = LRLanguage.define({
|
|
|
340
86
|
return context.column(context.node.from) + context.unit;
|
|
341
87
|
},
|
|
342
88
|
Document: (context) => {
|
|
343
|
-
|
|
89
|
+
var _a, _b;
|
|
90
|
+
if (context.pos + (((_b = (_a = /\s*/.exec(context.textAfter)) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.length) || 0) < context.node.to) {
|
|
344
91
|
return context.continue();
|
|
345
92
|
}
|
|
346
93
|
let endElt = null;
|
|
@@ -351,7 +98,7 @@ const glimmerLanguage = LRLanguage.define({
|
|
|
351
98
|
break;
|
|
352
99
|
endElt = cur = last;
|
|
353
100
|
}
|
|
354
|
-
if (endElt
|
|
101
|
+
if (endElt &&
|
|
355
102
|
!((close = endElt.lastChild) &&
|
|
356
103
|
(close.name === 'CloseTag' || close.name === 'SelfClosingTag'))) {
|
|
357
104
|
return context.lineIndent(endElt.from) + context.unit;
|
|
@@ -359,7 +106,7 @@ const glimmerLanguage = LRLanguage.define({
|
|
|
359
106
|
return null;
|
|
360
107
|
},
|
|
361
108
|
}),
|
|
362
|
-
foldNodeProp.add({
|
|
109
|
+
/*@__PURE__*/foldNodeProp.add({
|
|
363
110
|
Block: (node) => {
|
|
364
111
|
const open = `${node.name}Open`;
|
|
365
112
|
const close = `${node.name}Close`;
|
|
@@ -367,20 +114,16 @@ const glimmerLanguage = LRLanguage.define({
|
|
|
367
114
|
const last = node.lastChild;
|
|
368
115
|
if (!first || first.name !== open)
|
|
369
116
|
return null;
|
|
370
|
-
return {
|
|
371
|
-
from: first.to,
|
|
372
|
-
to: last?.name === close ? last.from : node.to,
|
|
373
|
-
};
|
|
117
|
+
return { from: first.to, to: (last === null || last === void 0 ? void 0 : last.name) === close ? last.from : node.to };
|
|
374
118
|
},
|
|
375
119
|
Element: (node) => {
|
|
376
120
|
let first = node.firstChild;
|
|
377
121
|
let last = node.lastChild;
|
|
122
|
+
if (!last)
|
|
123
|
+
return null;
|
|
378
124
|
if (!first || first.name != 'OpenTag')
|
|
379
125
|
return null;
|
|
380
|
-
return {
|
|
381
|
-
from: first.to,
|
|
382
|
-
to: last?.name === 'CloseTag' ? last.from : node.to,
|
|
383
|
-
};
|
|
126
|
+
return { from: first.to, to: last.name === 'CloseTag' ? last.from : node.to };
|
|
384
127
|
},
|
|
385
128
|
}),
|
|
386
129
|
],
|
|
@@ -388,16 +131,172 @@ const glimmerLanguage = LRLanguage.define({
|
|
|
388
131
|
languageData: {
|
|
389
132
|
commentTokens: {
|
|
390
133
|
block: { open: '<!--', close: '-->' },
|
|
391
|
-
|
|
392
|
-
devBlockShort: { open: '{{!', close: '}}' },
|
|
134
|
+
moustacheLong: { open: '{{!--', close: '--}}' },
|
|
393
135
|
},
|
|
394
|
-
indentOnInput: /^\s*((<\/\w+\W)|(\{
|
|
136
|
+
indentOnInput: /^\s*((<\/\w+\W)|(\{\{:?(else|then|catch))|(\{\{\/(if|each|each-in|in-element|unless|let)))$/,
|
|
395
137
|
wordChars: '-._',
|
|
396
|
-
autocomplete: htmlCompletionSource,
|
|
397
138
|
},
|
|
398
139
|
});
|
|
140
|
+
const glimmerLanguage = /*@__PURE__*/glimmerPlain.configure({
|
|
141
|
+
wrap: /*@__PURE__*/configureNesting(defaultNesting),
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// unfortunately the HTML language explicitly checks for the language type,
|
|
145
|
+
// so we have to duplicate the entire autoCloseTags extension
|
|
146
|
+
function elementName(doc, tree, max = doc.length) {
|
|
147
|
+
if (!tree)
|
|
148
|
+
return '';
|
|
149
|
+
let tag = tree.firstChild;
|
|
150
|
+
let name = tag &&
|
|
151
|
+
(tag.getChild('TagName') || tag.getChild('ComponentName') || tag.getChild('SvelteElementName'));
|
|
152
|
+
return name ? doc.sliceString(name.from, Math.min(name.to, max)) : '';
|
|
153
|
+
}
|
|
154
|
+
const autoCloseTags = /*@__PURE__*/EditorView.inputHandler.of((view, from, to, text) => {
|
|
155
|
+
if (view.composing ||
|
|
156
|
+
view.state.readOnly ||
|
|
157
|
+
from != to ||
|
|
158
|
+
(text != '>' && text != '/') ||
|
|
159
|
+
!glimmerLanguage.isActiveAt(view.state, from, -1))
|
|
160
|
+
return false;
|
|
161
|
+
let { state } = view;
|
|
162
|
+
const noChanges = { range: undefined, changes: undefined, effects: undefined };
|
|
163
|
+
let changes = state.changeByRange((range) => {
|
|
164
|
+
var _a, _b, _c;
|
|
165
|
+
let { head } = range;
|
|
166
|
+
let around = syntaxTree(state).resolveInner(head, -1);
|
|
167
|
+
let name;
|
|
168
|
+
if (around.name === 'TagName' ||
|
|
169
|
+
around.name === 'ComponentName' ||
|
|
170
|
+
around.name === 'StartTag') {
|
|
171
|
+
if (!around.parent)
|
|
172
|
+
return Object.assign(Object.assign({}, noChanges), { range });
|
|
173
|
+
around = around.parent;
|
|
174
|
+
}
|
|
175
|
+
if (text === '>' && around.name === 'OpenTag') {
|
|
176
|
+
if (((_b = (_a = around.parent) === null || _a === void 0 ? void 0 : _a.lastChild) === null || _b === void 0 ? void 0 : _b.name) != 'CloseTag' &&
|
|
177
|
+
(name = elementName(state.doc, around.parent, head))) {
|
|
178
|
+
let hasRightBracket = view.state.doc.sliceString(head, head + 1) === '>';
|
|
179
|
+
let insert = `${hasRightBracket ? '' : '>'}</${name}>`;
|
|
180
|
+
return {
|
|
181
|
+
range: EditorSelection.cursor(head + 1),
|
|
182
|
+
changes: { from: head + (hasRightBracket ? 1 : 0), insert },
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else if (text === '/' && around.name === 'OpenTag') {
|
|
187
|
+
let empty = around.parent, base = empty === null || empty === void 0 ? void 0 : empty.parent;
|
|
188
|
+
if (!empty)
|
|
189
|
+
return Object.assign(Object.assign({}, noChanges), { range });
|
|
190
|
+
if (!base)
|
|
191
|
+
return Object.assign(Object.assign({}, noChanges), { range });
|
|
192
|
+
if (empty.from == head - 1 &&
|
|
193
|
+
((_c = base.lastChild) === null || _c === void 0 ? void 0 : _c.name) != 'CloseTag' &&
|
|
194
|
+
(name = elementName(state.doc, base, head))) {
|
|
195
|
+
let hasRightBracket = view.state.doc.sliceString(head, head + 1) === '>';
|
|
196
|
+
let insert = `/${name}${hasRightBracket ? '' : '>'}`;
|
|
197
|
+
let pos = head + insert.length + (hasRightBracket ? 1 : 0);
|
|
198
|
+
return { range: EditorSelection.cursor(pos), changes: { from: head, insert } };
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return { range };
|
|
202
|
+
});
|
|
203
|
+
if (changes.changes.empty)
|
|
204
|
+
return false;
|
|
205
|
+
view.dispatch(changes, { userEvent: 'input.type', scrollIntoView: true });
|
|
206
|
+
return true;
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
A collection of JavaScript-related
|
|
211
|
+
[snippets](https://codemirror.net/6/docs/ref/#autocomplete.snippet).
|
|
212
|
+
*/
|
|
213
|
+
const snippets = [
|
|
214
|
+
/*@__PURE__*/snippetCompletion('#each ${list} as |${item}|}}\n\t${}\n{{/each', {
|
|
215
|
+
label: '#each',
|
|
216
|
+
detail: 'loop',
|
|
217
|
+
type: 'keyword',
|
|
218
|
+
}),
|
|
219
|
+
/*@__PURE__*/snippetCompletion('#each-in ${object} as |${key} ${value}|}}\n\t${}\n{{/each-in', {
|
|
220
|
+
label: '#each-in',
|
|
221
|
+
detail: 'loop',
|
|
222
|
+
type: 'keyword',
|
|
223
|
+
}),
|
|
224
|
+
/*@__PURE__*/snippetCompletion('#let ${subExpression} as |${result}|}}\n\t${}\n{{/let', {
|
|
225
|
+
label: '#let',
|
|
226
|
+
detail: 'block',
|
|
227
|
+
type: 'keyword',
|
|
228
|
+
}),
|
|
229
|
+
/*@__PURE__*/snippetCompletion('#if ${condition}}}\n\t${}\n{{/if', {
|
|
230
|
+
label: '#if',
|
|
231
|
+
detail: 'block',
|
|
232
|
+
type: 'keyword',
|
|
233
|
+
}),
|
|
234
|
+
/*@__PURE__*/snippetCompletion('#in-element ${element}}}\n\t${}\n{{/in-element', {
|
|
235
|
+
label: '#in-element',
|
|
236
|
+
detail: 'block',
|
|
237
|
+
type: 'keyword',
|
|
238
|
+
}),
|
|
239
|
+
/*@__PURE__*/snippetCompletion('#unless ${condition}}}\n\t${}\n{{/unless', {
|
|
240
|
+
label: '#unless',
|
|
241
|
+
detail: 'block',
|
|
242
|
+
type: 'keyword',
|
|
243
|
+
}),
|
|
244
|
+
/*@__PURE__*/snippetCompletion('#if ${condition}}}\n\t${}\n{{else}}\n\t${}\n{{/if', {
|
|
245
|
+
label: '#if',
|
|
246
|
+
detail: '/ else block',
|
|
247
|
+
type: 'keyword',
|
|
248
|
+
}),
|
|
249
|
+
/*@__PURE__*/snippetCompletion('#unless ${condition}}}\n\t${}\n{{else}}\n\t${}\n{{/unless', {
|
|
250
|
+
label: '#unless',
|
|
251
|
+
detail: '/ else block',
|
|
252
|
+
type: 'keyword',
|
|
253
|
+
}),
|
|
254
|
+
];
|
|
255
|
+
|
|
399
256
|
function glimmer() {
|
|
400
|
-
return new LanguageSupport(glimmerLanguage, [
|
|
257
|
+
return new LanguageSupport(glimmerLanguage, [
|
|
258
|
+
javascript().support,
|
|
259
|
+
css().support,
|
|
260
|
+
new LanguageSupport(LRLanguage.define({
|
|
261
|
+
name: 'glimmer-expression',
|
|
262
|
+
parser: parser.configure({}),
|
|
263
|
+
}), []),
|
|
264
|
+
glimmerLanguage.data.of({ autocomplete: snippets }),
|
|
265
|
+
// We may want to swap this with Glimmer-specific tag completion
|
|
266
|
+
glimmerLanguage.data.of({ autocomplete: htmlTagCompletion }),
|
|
267
|
+
autoCloseTags,
|
|
268
|
+
]);
|
|
269
|
+
}
|
|
270
|
+
function htmlTagCompletion(context) {
|
|
271
|
+
let { state, pos } = context, m = /<[:\-.\w\u00b7-\uffff]*$/.exec(state.sliceDoc(pos - 25, pos));
|
|
272
|
+
if (!m)
|
|
273
|
+
return null;
|
|
274
|
+
let tree = syntaxTree(state).resolveInner(pos, -1);
|
|
275
|
+
while (tree && !tree.type.isTop) {
|
|
276
|
+
if (tree.name == 'CodeBlock' ||
|
|
277
|
+
tree.name == 'FencedCode' ||
|
|
278
|
+
tree.name == 'ProcessingInstructionBlock' ||
|
|
279
|
+
tree.name == 'CommentBlock' ||
|
|
280
|
+
tree.name == 'Link' ||
|
|
281
|
+
tree.name == 'Image') {
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
tree = tree.parent;
|
|
285
|
+
}
|
|
286
|
+
return {
|
|
287
|
+
from: pos - m[0].length,
|
|
288
|
+
to: pos,
|
|
289
|
+
options: htmlTagCompletions(),
|
|
290
|
+
validFor: /^<[:\-.\w\u00b7-\uffff]*$/,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
let _tagCompletions = null;
|
|
294
|
+
const htmlNoMatch = /*@__PURE__*/html({ matchClosingTags: false });
|
|
295
|
+
function htmlTagCompletions() {
|
|
296
|
+
if (_tagCompletions)
|
|
297
|
+
return _tagCompletions;
|
|
298
|
+
let result = htmlCompletionSource(new CompletionContext(EditorState.create({ extensions: htmlNoMatch }), 0, true));
|
|
299
|
+
return (_tagCompletions = result ? result.options : []);
|
|
401
300
|
}
|
|
402
301
|
|
|
403
|
-
export { glimmer, glimmerLanguage,
|
|
302
|
+
export { defaultNesting, glimmer, glimmerLanguage, glimmerPlain, snippets };
|