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.
Files changed (55) hide show
  1. package/.eslintrc.cjs +2 -2
  2. package/.turbo/turbo-build.log +5 -21
  3. package/.turbo/turbo-lint$colon$js$colon$fix.log +7 -0
  4. package/.turbo/turbo-lint$colon$js.log +7 -0
  5. package/.turbo/turbo-lint$colon$prettier$colon$fix.log +15 -0
  6. package/.turbo/turbo-lint$colon$prettier.log +9 -0
  7. package/.turbo/turbo-lint$colon$types.log +5 -0
  8. package/CHANGELOG.md +15 -0
  9. package/LICENSE +21 -0
  10. package/dev/.eslintcache +1 -0
  11. package/dev/.eslintrc.cjs +2 -2
  12. package/dev/CHANGELOG.md +3 -0
  13. package/dev/index.html +1 -1
  14. package/dev/index.ts +43 -3
  15. package/dev/node_modules/.bin/eslint +4 -4
  16. package/dev/node_modules/.bin/prettier +4 -4
  17. package/dev/node_modules/.bin/tsc +4 -4
  18. package/dev/node_modules/.bin/tsserver +4 -4
  19. package/dev/node_modules/.bin/vite +4 -4
  20. package/dev/package.json +28 -16
  21. package/dev/watch.cjs +3 -3
  22. package/dist/index.cjs +222 -321
  23. package/dist/index.d.cts +22 -4
  24. package/dist/index.d.ts +22 -4
  25. package/dist/index.js +224 -325
  26. package/package.json +42 -26
  27. package/src/auto-close.ts +91 -0
  28. package/src/glimmer.ts +79 -0
  29. package/src/index.ts +3 -154
  30. package/src/language.ts +176 -0
  31. package/src/snippets.ts +48 -0
  32. package/tsconfig.json +2 -1
  33. package/.eslintignore +0 -2
  34. package/.prettierignore +0 -2
  35. package/.prettierrc.cjs +0 -20
  36. package/dist/index.d.cts.map +0 -1
  37. package/dist/index.d.ts.map +0 -1
  38. package/src/highlight.ts +0 -57
  39. package/src/syntax.grammar +0 -139
  40. package/src/syntax.grammar.d.ts +0 -3
  41. package/src/syntax.grammar.terms.d.ts +0 -14
  42. package/src/tokens.ts +0 -277
  43. package/tests/.eslintrc.cjs +0 -5
  44. package/tests/comments.txt +0 -116
  45. package/tests/complex.txt +0 -24
  46. package/tests/expression.txt +0 -95
  47. package/tests/literals.txt +0 -78
  48. package/tests/node_modules/.bin/eslint +0 -17
  49. package/tests/node_modules/.bin/prettier +0 -17
  50. package/tests/node_modules/.bin/tsc +0 -17
  51. package/tests/node_modules/.bin/tsserver +0 -17
  52. package/tests/numbers.txt +0 -88
  53. package/tests/package.json +0 -25
  54. package/tests/property-paths.txt +0 -79
  55. package/tests/strings.txt +0 -64
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codemirror-lang-glimmer",
3
- "version": "0.0.0-beta.3",
3
+ "version": "0.0.0",
4
4
  "author": "NullVoxPopuli",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -13,42 +13,58 @@
13
13
  "types": "dist/index.d.ts",
14
14
  "repository": {
15
15
  "type": "git",
16
- "url": "https://github.com/nullvoxpopuli/glimdown.git",
17
- "path": "packages/lezer/glimmer"
16
+ "url": "https://github.com/NullVoxPopuli/limber.git",
17
+ "directory": "packages/syntax/glimmer/codemirror"
18
18
  },
19
19
  "devDependencies": {
20
- "@babel/core": "^7.21.8",
21
- "@babel/eslint-parser": "^7.21.8",
22
- "@codemirror/buildhelper": "^1.0.0",
23
- "@codemirror/language": "^6.6.0",
24
- "@lezer/generator": "^1.2.3",
25
- "@nullvoxpopuli/eslint-configs": "^3.1.3",
26
- "@tsconfig/ember": "^2.0.0",
27
- "@typescript-eslint/eslint-plugin": "^5.59.5",
28
- "@typescript-eslint/parser": "^5.59.5",
20
+ "@babel/core": "^7.23.9",
21
+ "@babel/eslint-parser": "^7.23.10",
22
+ "@codemirror/buildhelper": "^1.0.1",
23
+ "@codemirror/language": "^6.10.1",
24
+ "@lezer/common": "^1.1.2",
25
+ "@lezer/generator": "^1.6.0",
26
+ "@nullvoxpopuli/eslint-configs": "^3.2.2",
27
+ "@tsconfig/ember": "^3.0.2",
28
+ "@typescript-eslint/eslint-plugin": "^6.20.0",
29
+ "@typescript-eslint/parser": "^6.20.0",
29
30
  "codemirror": "^6.0.1",
30
- "concurrently": "^8.0.1",
31
- "eslint": "^8.40.0",
32
- "prettier": "^2.8.8",
33
- "rollup": "^3.21.5",
34
- "rollup-plugin-ts": "^3.2.0",
35
- "typescript": "^5.0.4"
31
+ "concurrently": "^8.2.2",
32
+ "eslint": "^8.55.0",
33
+ "prettier": "^3.2.5",
34
+ "rollup": "^4.9.6",
35
+ "rollup-plugin-ts": "^3.4.5",
36
+ "typescript": "^5.3.3"
36
37
  },
37
38
  "dependencies": {
38
- "@codemirror/lang-html": "^6.4.3",
39
- "@lezer/common": "^1.0.2",
40
- "@lezer/highlight": "^1.1.4",
41
- "@lezer/html": "^1.3.4",
42
- "@lezer/javascript": "^1.4.3",
43
- "@lezer/lr": "^1.3.4"
39
+ "@codemirror/autocomplete": "6.12.0",
40
+ "@codemirror/lang-css": "^6.2.1",
41
+ "@codemirror/lang-html": "^6.4.8",
42
+ "@codemirror/lang-javascript": "^6.2.1",
43
+ "@codemirror/state": "^6.4.0",
44
+ "@codemirror/view": "^6.23.0",
45
+ "@lezer/highlight": "^1.2.0",
46
+ "@lezer/html": "^1.3.7",
47
+ "@lezer/javascript": "^1.4.13",
48
+ "@lezer/lr": "^1.4.0",
49
+ "@glimdown/lezer-glimmer-expression": "0.0.0",
50
+ "lezer-glimmer": "0.0.0"
44
51
  },
45
52
  "volta": {
46
- "extends": "../../../package.json"
53
+ "extends": "../../../../package.json"
54
+ },
55
+ "engines": {
56
+ "node": ">= v16",
57
+ "npm": "use pnpm",
58
+ "yarn": "use pnpm"
59
+ },
60
+ "peerDependencies": {
61
+ "@lezer/common": "^1.1.2"
47
62
  },
48
63
  "scripts": {
49
64
  "dev": "node ./dev/watch.cjs src/index.ts",
50
- "build": "rollup -c",
65
+ "build": "cm-buildhelper src/index.ts",
51
66
  "lint": "pnpm -w exec lint",
67
+ "lint:types": "tsc --noEmit",
52
68
  "lint:fix": "pnpm -w exec lint fix",
53
69
  "lint:js": "pnpm -w exec lint js",
54
70
  "lint:js:fix": "pnpm -w exec lint js:fix",
@@ -0,0 +1,91 @@
1
+ // unfortunately the HTML language explicitly checks for the language type,
2
+ // so we have to duplicate the entire autoCloseTags extension
3
+
4
+ import { syntaxTree } from '@codemirror/language';
5
+ import { EditorSelection } from '@codemirror/state';
6
+ import { EditorView } from '@codemirror/view';
7
+
8
+ import { glimmerLanguage } from './language';
9
+
10
+ import type { Text } from '@codemirror/state';
11
+ import type { SyntaxNode } from '@lezer/common';
12
+
13
+ function elementName(doc: Text, tree: SyntaxNode | null | undefined, max = doc.length) {
14
+ if (!tree) return '';
15
+
16
+ let tag = tree.firstChild;
17
+ let name =
18
+ tag &&
19
+ (tag.getChild('TagName') || tag.getChild('ComponentName') || tag.getChild('SvelteElementName'));
20
+
21
+ return name ? doc.sliceString(name.from, Math.min(name.to, max)) : '';
22
+ }
23
+
24
+ export const autoCloseTags = EditorView.inputHandler.of((view, from, to, text) => {
25
+ if (
26
+ view.composing ||
27
+ view.state.readOnly ||
28
+ from != to ||
29
+ (text != '>' && text != '/') ||
30
+ !glimmerLanguage.isActiveAt(view.state, from, -1)
31
+ )
32
+ return false;
33
+
34
+ let { state } = view;
35
+ const noChanges = { range: undefined, changes: undefined, effects: undefined };
36
+ let changes = state.changeByRange((range) => {
37
+ let { head } = range;
38
+ let around = syntaxTree(state).resolveInner(head, -1);
39
+ let name: string;
40
+
41
+ if (
42
+ around.name === 'TagName' ||
43
+ around.name === 'ComponentName' ||
44
+ around.name === 'StartTag'
45
+ ) {
46
+ if (!around.parent) return { ...noChanges, range };
47
+ around = around.parent;
48
+ }
49
+
50
+ if (text === '>' && around.name === 'OpenTag') {
51
+ if (
52
+ around.parent?.lastChild?.name != 'CloseTag' &&
53
+ (name = elementName(state.doc, around.parent, head))
54
+ ) {
55
+ let hasRightBracket = view.state.doc.sliceString(head, head + 1) === '>';
56
+ let insert = `${hasRightBracket ? '' : '>'}</${name}>`;
57
+
58
+ return {
59
+ range: EditorSelection.cursor(head + 1),
60
+ changes: { from: head + (hasRightBracket ? 1 : 0), insert },
61
+ };
62
+ }
63
+ } else if (text === '/' && around.name === 'OpenTag') {
64
+ let empty = around.parent,
65
+ base = empty?.parent;
66
+
67
+ if (!empty) return { ...noChanges, range };
68
+ if (!base) return { ...noChanges, range };
69
+
70
+ if (
71
+ empty.from == head - 1 &&
72
+ base.lastChild?.name != 'CloseTag' &&
73
+ (name = elementName(state.doc, base, head))
74
+ ) {
75
+ let hasRightBracket = view.state.doc.sliceString(head, head + 1) === '>';
76
+ let insert = `/${name}${hasRightBracket ? '' : '>'}`;
77
+ let pos = head + insert.length + (hasRightBracket ? 1 : 0);
78
+
79
+ return { range: EditorSelection.cursor(pos), changes: { from: head, insert } };
80
+ }
81
+ }
82
+
83
+ return { range };
84
+ });
85
+
86
+ if (changes.changes.empty) return false;
87
+
88
+ view.dispatch(changes, { userEvent: 'input.type', scrollIntoView: true });
89
+
90
+ return true;
91
+ });
package/src/glimmer.ts ADDED
@@ -0,0 +1,79 @@
1
+ import { CompletionContext } from '@codemirror/autocomplete';
2
+ import { css } from '@codemirror/lang-css';
3
+ import { html, htmlCompletionSource } from '@codemirror/lang-html';
4
+ import { javascript } from '@codemirror/lang-javascript';
5
+ import { LanguageSupport, LRLanguage, syntaxTree } from '@codemirror/language';
6
+ import { EditorState } from '@codemirror/state';
7
+
8
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
9
+ // @ts-expect-error
10
+ import { parser as glimmerExpressionParser } from '@glimdown/lezer-glimmer-expression';
11
+
12
+ import { autoCloseTags } from './auto-close';
13
+ import { glimmerLanguage } from './language';
14
+ import { snippets } from './snippets';
15
+
16
+ import type { Completion } from '@codemirror/autocomplete';
17
+ import type { SyntaxNode } from '@lezer/common';
18
+
19
+ export function glimmer() {
20
+ return new LanguageSupport(glimmerLanguage, [
21
+ javascript().support,
22
+ css().support,
23
+ new LanguageSupport(
24
+ LRLanguage.define({
25
+ name: 'glimmer-expression',
26
+ parser: glimmerExpressionParser.configure({}),
27
+ }),
28
+ []
29
+ ),
30
+ glimmerLanguage.data.of({ autocomplete: snippets }),
31
+ // We may want to swap this with Glimmer-specific tag completion
32
+ glimmerLanguage.data.of({ autocomplete: htmlTagCompletion }),
33
+ autoCloseTags,
34
+ ]);
35
+ }
36
+
37
+ function htmlTagCompletion(context: CompletionContext) {
38
+ let { state, pos } = context,
39
+ m = /<[:\-.\w\u00b7-\uffff]*$/.exec(state.sliceDoc(pos - 25, pos));
40
+
41
+ if (!m) return null;
42
+
43
+ let tree: SyntaxNode | null = syntaxTree(state).resolveInner(pos, -1);
44
+
45
+ while (tree && !tree.type.isTop) {
46
+ if (
47
+ tree.name == 'CodeBlock' ||
48
+ tree.name == 'FencedCode' ||
49
+ tree.name == 'ProcessingInstructionBlock' ||
50
+ tree.name == 'CommentBlock' ||
51
+ tree.name == 'Link' ||
52
+ tree.name == 'Image'
53
+ ) {
54
+ return null;
55
+ }
56
+
57
+ tree = tree.parent;
58
+ }
59
+
60
+ return {
61
+ from: pos - m[0].length,
62
+ to: pos,
63
+ options: htmlTagCompletions(),
64
+ validFor: /^<[:\-.\w\u00b7-\uffff]*$/,
65
+ };
66
+ }
67
+
68
+ let _tagCompletions: readonly Completion[] | null = null;
69
+ const htmlNoMatch = html({ matchClosingTags: false });
70
+
71
+ function htmlTagCompletions() {
72
+ if (_tagCompletions) return _tagCompletions;
73
+
74
+ let result = htmlCompletionSource(
75
+ new CompletionContext(EditorState.create({ extensions: htmlNoMatch }), 0, true)
76
+ );
77
+
78
+ return (_tagCompletions = result ? result.options : []);
79
+ }
package/src/index.ts CHANGED
@@ -1,154 +1,3 @@
1
- import { html, htmlCompletionSource } from '@codemirror/lang-html';
2
- import { foldNodeProp, indentNodeProp, LanguageSupport, LRLanguage } from '@codemirror/language';
3
- import { parseMixed } from '@lezer/common';
4
- import { parser as htmlParser } from '@lezer/html';
5
-
6
- import { parser } from './syntax.grammar';
7
-
8
- import type { SyntaxNode } from '@lezer/common';
9
-
10
- export const glimmerParser = parser;
11
-
12
- export const glimmerLanguage = LRLanguage.define({
13
- parser: parser.configure({
14
- wrap: parseMixed((node) => {
15
- let { name } = node.type;
16
-
17
- switch (name) {
18
- case 'Template':
19
- return null;
20
- case 'Comment':
21
- case 'MoustacheExpression':
22
- case 'NamedBlock':
23
- case 'Splattributes':
24
- case 'Argument':
25
- return { parser };
26
- }
27
-
28
- return { parser: htmlParser };
29
- }),
30
-
31
- props: [
32
- indentNodeProp.add({
33
- Element: (context) => {
34
- let after = /^(\s*)(<\/)?/.exec(context.textAfter);
35
-
36
- if (context.node.to <= context.pos + (after?.[0].length || 0)) return context.continue();
37
-
38
- return context.lineIndent(context.node.from) + (after?.[2] ? 0 : context.unit);
39
- },
40
-
41
- Block: (context) => {
42
- const node = context.node;
43
- const text = context.textAfter.trim();
44
-
45
- if (text.startsWith('{/')) {
46
- const name = node.name;
47
-
48
- if (
49
- (name === 'IfBlock' && text.startsWith('{/if')) ||
50
- (name === 'EachBlock' && text.startsWith('{/each')) ||
51
- (name === 'KeyBlock' && text.startsWith('{/key'))
52
- ) {
53
- return context.lineIndent(context.node.from);
54
- }
55
-
56
- return null;
57
- }
58
-
59
- if (node.name === 'IfBlock' || node.name === 'EachBlock') {
60
- if (text.startsWith('{{:else')) return context.lineIndent(node.from);
61
- if (text.startsWith('{{else')) return context.lineIndent(node.from);
62
- }
63
-
64
- // not sure if this needed to be duplicated
65
- let after = /^(\s*)(<\/)?/.exec(context.textAfter);
66
-
67
- if (context.node.to <= context.pos + (after?.[0].length || 0)) return context.continue();
68
-
69
- return context.lineIndent(context.node.from) + (after?.[2] ? 0 : context.unit);
70
- },
71
-
72
- 'BlockOpen BlockClose BlockInline': (context) => {
73
- return context.column(context.node.from) + context.unit;
74
- },
75
-
76
- 'OpenTag CloseTag SelfClosingTag': (context) => {
77
- return context.column(context.node.from) + context.unit;
78
- },
79
-
80
- Document: (context) => {
81
- if (context.pos + (/\s*/.exec(context.textAfter)?.[0].length || 0) < context.node.to) {
82
- return context.continue();
83
- }
84
-
85
- let endElt: SyntaxNode | null = null;
86
- let close: SyntaxNode;
87
-
88
- for (let cur = context.node; ; ) {
89
- let last = cur.lastChild;
90
-
91
- if (!last || last.name != 'Element' || last.to != cur.to) break;
92
- endElt = cur = last;
93
- }
94
-
95
- if (
96
- endElt?.lastChild &&
97
- !(
98
- (close = endElt.lastChild) &&
99
- (close.name === 'CloseTag' || close.name === 'SelfClosingTag')
100
- )
101
- ) {
102
- return context.lineIndent(endElt.from) + context.unit;
103
- }
104
-
105
- return null;
106
- },
107
- }),
108
-
109
- foldNodeProp.add({
110
- Block: (node) => {
111
- const open = `${node.name}Open`;
112
- const close = `${node.name}Close`;
113
-
114
- const first = node.firstChild;
115
- const last = node.lastChild;
116
-
117
- if (!first || first.name !== open) return null;
118
-
119
- return {
120
- from: first.to,
121
- to: last?.name === close ? last.from : node.to,
122
- };
123
- },
124
-
125
- Element: (node) => {
126
- let first = node.firstChild;
127
- let last = node.lastChild;
128
-
129
- if (!first || first.name != 'OpenTag') return null;
130
-
131
- return {
132
- from: first.to,
133
- to: last?.name === 'CloseTag' ? last.from : node.to,
134
- };
135
- },
136
- }),
137
- ],
138
- }),
139
-
140
- languageData: {
141
- commentTokens: {
142
- block: { open: '<!--', close: '-->' },
143
- devBlock: { open: '{{!--', close: '--}}' },
144
- devBlockShort: { open: '{{!', close: '}}' },
145
- },
146
- indentOnInput: /^\s*((<\/\w+\W)|(\{:(else|then|catch))|(\{\/(if|unless|each|await|key)))$/,
147
- wordChars: '-._',
148
- autocomplete: htmlCompletionSource,
149
- },
150
- });
151
-
152
- export function glimmer() {
153
- return new LanguageSupport(glimmerLanguage, [html().support]);
154
- }
1
+ export { glimmer } from './glimmer';
2
+ export { defaultNesting, glimmerLanguage, glimmerPlain } from './language';
3
+ export { snippets } from './snippets';
@@ -0,0 +1,176 @@
1
+ import { cssLanguage } from '@codemirror/lang-css';
2
+ import { javascriptLanguage, typescriptLanguage } from '@codemirror/lang-javascript';
3
+ import { foldNodeProp, indentNodeProp, LRLanguage } from '@codemirror/language';
4
+ import { configureNesting, glimmerParser } from 'lezer-glimmer';
5
+
6
+ import type { Parser, SyntaxNode } from '@lezer/common';
7
+
8
+ type NestedLang = {
9
+ tag: 'script' | 'style' | 'textarea';
10
+ attrs?: (attrs: { [attr: string]: string }) => boolean;
11
+ parser: Parser;
12
+ };
13
+
14
+ export const defaultNesting: NestedLang[] = [
15
+ {
16
+ tag: 'script',
17
+ attrs: (attrs) => attrs['type'] === 'text/typescript' || attrs['lang'] === 'ts',
18
+ parser: typescriptLanguage.parser,
19
+ },
20
+ {
21
+ tag: 'script',
22
+ attrs(attrs) {
23
+ return (
24
+ !attrs['type'] ||
25
+ /^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i.test(attrs['type'])
26
+ );
27
+ },
28
+ parser: javascriptLanguage.parser,
29
+ },
30
+ {
31
+ tag: 'style',
32
+ attrs(/* attrs */) {
33
+ return true;
34
+ // Always use CSS. We can add varying support later
35
+ // return (
36
+ // (!attrs['lang'] || attrs['lang'] === 'css' || attrs['lang'] === 'scss') &&
37
+ // (!attrs['type'] || /^(text\/)?(x-)?(stylesheet|css|scss)$/i.test(attrs['type']))
38
+ // );
39
+ },
40
+ parser: cssLanguage.parser,
41
+ },
42
+ ];
43
+
44
+ export const glimmerPlain = LRLanguage.define({
45
+ parser: glimmerParser.configure({
46
+ props: [
47
+ indentNodeProp.add({
48
+ Element: (context) => {
49
+ let after = /^(\s*)(<\/)?/.exec(context.textAfter);
50
+
51
+ if (!after) return null;
52
+
53
+ if (context.node.to <= context.pos + after[0].length) return context.continue();
54
+
55
+ return context.lineIndent(context.node.from) + (after[2] ? 0 : context.unit);
56
+ },
57
+
58
+ Block: (context) => {
59
+ const node = context.node;
60
+ const text = context.textAfter.trim();
61
+
62
+ if (text.startsWith('{/')) {
63
+ const name = node.name;
64
+
65
+ if (
66
+ (name === 'IfBlock' && text.startsWith('{/if')) ||
67
+ (name === 'UnlessBlock' && text.startsWith('{/unless')) ||
68
+ (name === 'InElementBlock' && text.startsWith('{/in-element')) ||
69
+ (name === 'EachBlock' && text.startsWith('{/each')) ||
70
+ (name === 'EachInBlock' && text.startsWith('{/each-in')) ||
71
+ (name === 'LetBlock' && text.startsWith('{/let'))
72
+ ) {
73
+ return context.lineIndent(context.node.from);
74
+ }
75
+
76
+ return null;
77
+ }
78
+
79
+ if (
80
+ node.name === 'IfBlock' ||
81
+ node.name === 'EachBlock' ||
82
+ node.name === 'EachInBlock' ||
83
+ node.name === 'UnlessBlock'
84
+ ) {
85
+ if (text.startsWith('{{:else')) return context.lineIndent(node.from);
86
+ if (text.startsWith('{{else')) return context.lineIndent(node.from);
87
+ }
88
+
89
+ // not sure if this needed to be duplicated
90
+ let after = /^(\s*)(<\/)?/.exec(context.textAfter);
91
+
92
+ if (!after) return null;
93
+
94
+ if (context.node.to <= context.pos + after[0].length) return context.continue();
95
+
96
+ return context.lineIndent(context.node.from) + (after[2] ? 0 : context.unit);
97
+ },
98
+
99
+ 'BlockOpen BlockClose BlockInline': (context) => {
100
+ return context.column(context.node.from) + context.unit;
101
+ },
102
+
103
+ 'OpenTag CloseTag SelfClosingTag': (context) => {
104
+ return context.column(context.node.from) + context.unit;
105
+ },
106
+
107
+ Document: (context) => {
108
+ if (context.pos + (/\s*/.exec(context.textAfter)?.[0]?.length || 0) < context.node.to) {
109
+ return context.continue();
110
+ }
111
+
112
+ let endElt: SyntaxNode | null = null;
113
+ let close: SyntaxNode | null;
114
+
115
+ for (let cur = context.node; ; ) {
116
+ let last = cur.lastChild;
117
+
118
+ if (!last || last.name != 'Element' || last.to != cur.to) break;
119
+ endElt = cur = last;
120
+ }
121
+
122
+ if (
123
+ endElt &&
124
+ !(
125
+ (close = endElt.lastChild) &&
126
+ (close.name === 'CloseTag' || close.name === 'SelfClosingTag')
127
+ )
128
+ ) {
129
+ return context.lineIndent(endElt.from) + context.unit;
130
+ }
131
+
132
+ return null;
133
+ },
134
+ }),
135
+
136
+ foldNodeProp.add({
137
+ Block: (node) => {
138
+ const open = `${node.name}Open`;
139
+ const close = `${node.name}Close`;
140
+
141
+ const first = node.firstChild;
142
+ const last = node.lastChild;
143
+
144
+ if (!first || first.name !== open) return null;
145
+
146
+ return { from: first.to, to: last?.name === close ? last.from : node.to };
147
+ },
148
+
149
+ Element: (node) => {
150
+ let first = node.firstChild;
151
+ let last = node.lastChild;
152
+
153
+ if (!last) return null;
154
+
155
+ if (!first || first.name != 'OpenTag') return null;
156
+
157
+ return { from: first.to, to: last.name === 'CloseTag' ? last.from : node.to };
158
+ },
159
+ }),
160
+ ],
161
+ }),
162
+
163
+ languageData: {
164
+ commentTokens: {
165
+ block: { open: '<!--', close: '-->' },
166
+ moustacheLong: { open: '{{!--', close: '--}}' },
167
+ },
168
+ indentOnInput:
169
+ /^\s*((<\/\w+\W)|(\{\{:?(else|then|catch))|(\{\{\/(if|each|each-in|in-element|unless|let)))$/,
170
+ wordChars: '-._',
171
+ },
172
+ });
173
+
174
+ export const glimmerLanguage = glimmerPlain.configure({
175
+ wrap: configureNesting(defaultNesting),
176
+ });
@@ -0,0 +1,48 @@
1
+ import { snippetCompletion as snip } from '@codemirror/autocomplete';
2
+
3
+ import type { Completion } from '@codemirror/autocomplete';
4
+
5
+ /// A collection of JavaScript-related
6
+ /// [snippets](#autocomplete.snippet).
7
+ export const snippets: readonly Completion[] = [
8
+ snip('#each ${list} as |${item}|}}\n\t${}\n{{/each', {
9
+ label: '#each',
10
+ detail: 'loop',
11
+ type: 'keyword',
12
+ }),
13
+ snip('#each-in ${object} as |${key} ${value}|}}\n\t${}\n{{/each-in', {
14
+ label: '#each-in',
15
+ detail: 'loop',
16
+ type: 'keyword',
17
+ }),
18
+ snip('#let ${subExpression} as |${result}|}}\n\t${}\n{{/let', {
19
+ label: '#let',
20
+ detail: 'block',
21
+ type: 'keyword',
22
+ }),
23
+ snip('#if ${condition}}}\n\t${}\n{{/if', {
24
+ label: '#if',
25
+ detail: 'block',
26
+ type: 'keyword',
27
+ }),
28
+ snip('#in-element ${element}}}\n\t${}\n{{/in-element', {
29
+ label: '#in-element',
30
+ detail: 'block',
31
+ type: 'keyword',
32
+ }),
33
+ snip('#unless ${condition}}}\n\t${}\n{{/unless', {
34
+ label: '#unless',
35
+ detail: 'block',
36
+ type: 'keyword',
37
+ }),
38
+ snip('#if ${condition}}}\n\t${}\n{{else}}\n\t${}\n{{/if', {
39
+ label: '#if',
40
+ detail: '/ else block',
41
+ type: 'keyword',
42
+ }),
43
+ snip('#unless ${condition}}}\n\t${}\n{{else}}\n\t${}\n{{/unless', {
44
+ label: '#unless',
45
+ detail: '/ else block',
46
+ type: 'keyword',
47
+ }),
48
+ ];
package/tsconfig.json CHANGED
@@ -1,3 +1,4 @@
1
1
  {
2
- "extends": "@tsconfig/ember/tsconfig.json"
2
+ "extends": "@tsconfig/ember/tsconfig.json",
3
+ "include": ["src/**/*"]
3
4
  }
package/.eslintignore DELETED
@@ -1,2 +0,0 @@
1
- dist/
2
- *.md
package/.prettierignore DELETED
@@ -1,2 +0,0 @@
1
- dist/
2
- *.md
package/.prettierrc.cjs DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- module.exports = {
4
- printWidth: 100,
5
- overrides: [
6
- {
7
- files: ["*.js", "*.ts"],
8
- options: {
9
- singleQuote: true,
10
- trailingComma: "es5",
11
- },
12
- },
13
- {
14
- files: ["*.json"],
15
- options: {
16
- singleQuote: false,
17
- },
18
- },
19
- ],
20
- };
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts","../src/tokens.ts","../src/highlight.ts"],"names":[],"mappings":"AACA,OAAO,+BAA6D,MAAM,sBAAsB,CAAC;AAQjG,QAAO,MAAM,aAAa,8BAAS,CAAC;AAEpC,QAAO,MAAM,eAAe,YA0I1B,CAAC;AAEH,iBAAgB,OAAO,oBAEtB"}