Skip to content

Commit 1e3095a

Browse files
committed
Add some more auto completion snippets.
All starred variants have been added. That is with the exception of tripple starred parsed math mode. There is no point in using a tripple starred parse math mode as it is equivalent to the double starred parsed math mode. Add multi line table and command substitution snippets. The multi line table snippets have priority, but the single line command substitution snippets come first. The table snippets now have a cell in them to begin with. Also don't offer table cell completion immediately after a starred table cell. That interferes with being able to hit Enter to go to the next line.
1 parent 35b6dc0 commit 1e3095a

File tree

3 files changed

+174
-51
lines changed

3 files changed

+174
-51
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openwebwork/codemirror-lang-pg",
3-
"version": "0.0.1-beta.9",
3+
"version": "0.0.1-beta.10",
44
"description": "PG language support for CodeMirror",
55
"author": "The WeBWorK Project",
66
"license": "MIT",

src/pgml-language-data.ts

Lines changed: 171 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,20 @@ export const pgmlIndent = {
1818
let i = 99;
1919
let rank = 1;
2020

21-
const answerRuleSnippet = snippetCompletion('[_${}]${}{${$answer}}', {
22-
label: '[_]{ }',
23-
info: 'answer rule',
24-
section: { name: 'answer', rank },
25-
boost: i--
26-
});
21+
const answerRuleSnippets = [
22+
snippetCompletion('[_${}]${}{${$answer}}${}', {
23+
label: '[_]{ }',
24+
info: 'answer rule',
25+
section: { name: 'answer', rank },
26+
boost: i--
27+
}),
28+
snippetCompletion('[_${}]*{${$answer}}${}', {
29+
label: '[_]*{ }',
30+
info: 'array answer rule',
31+
section: { name: 'answer', rank },
32+
boost: i--
33+
})
34+
];
2735

2836
++rank;
2937
const mathModeSnippets = [
@@ -32,7 +40,13 @@ const mathModeSnippets = [
3240
['[``` ```]', 'block display math'],
3341
['[: :]', 'parsed inline math'],
3442
['[:: ::]', 'parsed display style math'],
35-
['[::: :::]', 'parsed block display math']
43+
['[::: :::]', 'parsed block display math'],
44+
['[: :]*', 'parsed inline math in active context'],
45+
['[:: ::]*', 'parsed display style math in active context'],
46+
['[::: :::]*', 'parsed block display math in active context'],
47+
['[: :]**', 'parsed and reduced inline math in active context'],
48+
['[:: ::]**', 'parsed and reduced display style math in active context'],
49+
['[::: :::]**', 'parsed and reduced block display math in active context']
3650
].map(([label, info]) => {
3751
return snippetCompletion(label.replace(' ', '${ }') + '${}', {
3852
label,
@@ -43,21 +57,95 @@ const mathModeSnippets = [
4357
});
4458
});
4559

46-
const variableSnippet = snippetCompletion('[$${ }]${}', {
47-
label: '[$ ]',
48-
info: 'variable',
49-
section: { name: 'substitution', rank: ++rank },
50-
type: 'variable',
51-
boost: i--
52-
});
60+
const variableSnippets = [
61+
snippetCompletion('[$${ }]${}', {
62+
label: '[$ ]',
63+
info: 'variable',
64+
section: { name: 'substitution', rank: ++rank },
65+
type: 'variable',
66+
boost: i--
67+
}),
68+
snippetCompletion('[$${ }]*${}', {
69+
label: '[$ ]*',
70+
info: 'variable with value not HTML escaped',
71+
section: { name: 'substitution', rank },
72+
type: 'variable',
73+
boost: i--
74+
}),
75+
snippetCompletion('[$${ }]**${}', {
76+
label: '[$ ]**',
77+
info: 'variable with value PGML parsed',
78+
section: { name: 'substitution', rank },
79+
type: 'variable',
80+
boost: i--
81+
}),
82+
snippetCompletion('[$${ }]***${}', {
83+
label: '[$ ]***',
84+
info: 'variable with LaTeX value not HTML escaped',
85+
section: { name: 'substitution', rank },
86+
type: 'variable',
87+
boost: i--
88+
})
89+
];
5390

54-
const perlCommandSnippet = snippetCompletion('[@ ${ } @]${}', {
55-
label: '[@ @]',
56-
info: 'perl command',
57-
section: { name: 'substitution', rank },
58-
type: 'variable',
59-
boost: i--
60-
});
91+
const perlCommandSnippets = [
92+
snippetCompletion('[@ ${ } @]${}', {
93+
label: '[@ @]',
94+
info: 'perl command',
95+
section: { name: 'substitution', rank },
96+
type: 'variable',
97+
boost: i--
98+
}),
99+
snippetCompletion('[@ ${ } @]*${}', {
100+
label: '[@ @]*',
101+
info: 'perl command with result not HTML escaped',
102+
section: { name: 'substitution', rank },
103+
type: 'variable',
104+
boost: i--
105+
}),
106+
snippetCompletion('[@ ${ } @]**${}', {
107+
label: '[@ @]**',
108+
info: 'perl command with result PGML parsed',
109+
section: { name: 'substitution', rank },
110+
type: 'variable',
111+
boost: i--
112+
}),
113+
snippetCompletion('[@ ${ } @]***${}', {
114+
label: '[@ @]***',
115+
info: 'perl command with LaTeX result not HTML escaped',
116+
section: { name: 'substitution', rank },
117+
type: 'variable',
118+
boost: i--
119+
}),
120+
snippetCompletion('[@\n\t${ }\n@]${}', {
121+
label: '[@ @]',
122+
info: 'perl command (multi line)',
123+
section: { name: 'substitution', rank },
124+
type: 'variable',
125+
boost: i--
126+
}),
127+
snippetCompletion('[@\n\t${ }\n@]*${}', {
128+
label: '[@ @]*',
129+
info: 'perl command with result not HTML escaped (multi line)',
130+
section: { name: 'substitution', rank },
131+
type: 'variable',
132+
boost: i--
133+
}),
134+
snippetCompletion('[@\n\t${ }\n@]**${}', {
135+
label: '[@ @]**',
136+
info: 'perl command with result PGML parsed (multi line)',
137+
section: { name: 'substitution', rank },
138+
type: 'variable',
139+
boost: i--
140+
}),
141+
snippetCompletion('[@\n\t${ }\n@]***${}', {
142+
label: '[@ @]***',
143+
info: 'perl command with LaTeX result not HTML escaped (multi line)',
144+
section: { name: 'substitution', rank },
145+
type: 'variable',
146+
boost: i--
147+
})
148+
];
61149

62150
const imageSnippet = snippetCompletion('[!${alt text}!]{${$source}}${}', {
63151
label: '[! !]{ }',
@@ -83,26 +171,60 @@ const commentSnippet = snippetCompletion('[% ${ } %]${}', {
83171
boost: i--
84172
});
85173

86-
const tableSnippet = snippetCompletion('[#${ }#]${}', {
87-
label: '[# #]',
88-
info: 'table',
89-
section: { name: 'table', rank: ++rank },
90-
type: 'type',
91-
boost: i--
92-
});
174+
const tableSnippets = [
175+
snippetCompletion('[#\n\t[.${ }.]${}\n#]${}', {
176+
label: '[# [. .] #]',
177+
info: 'table (multi line)',
178+
section: { name: 'table', rank: ++rank },
179+
type: 'type',
180+
boost: i--
181+
}),
182+
snippetCompletion('[#\n\t[.${ }.]${}\n#]*${}', {
183+
label: '[# [. .] #]*',
184+
info: 'layout table (multi line)',
185+
section: { name: 'table', rank },
186+
type: 'type',
187+
boost: i--
188+
}),
189+
snippetCompletion('[# [.${ }.]${} #]${}', {
190+
label: '[# [. .] #]',
191+
info: 'table (single line)',
192+
section: { name: 'table', rank },
193+
type: 'type',
194+
boost: i--
195+
}),
196+
snippetCompletion('[# [.${ }.]${} #]*${}', {
197+
label: '[# [. .] #]*',
198+
info: 'layout table (single line)',
199+
section: { name: 'table', rank },
200+
type: 'type',
201+
boost: i--
202+
})
203+
];
93204

94-
const tableCellSnippet = snippetCompletion('[.${ }.]${}', {
95-
label: '[. .]',
96-
info: 'table cell',
97-
section: { name: 'table', rank },
98-
type: 'type',
99-
boost: i--
100-
});
205+
const tableCellSnippets = [
206+
snippetCompletion('[.${ }.]${}', {
207+
label: '[. .]',
208+
info: 'table cell',
209+
section: { name: 'table', rank },
210+
type: 'type',
211+
boost: i--
212+
}),
213+
snippetCompletion('[.${ }.]*${}', {
214+
label: '[. .]',
215+
info: 'table cell at end of table row',
216+
section: { name: 'table', rank },
217+
type: 'type',
218+
boost: i--
219+
})
220+
];
101221

102222
++rank;
103223
const verbatimSnippets = [
104224
['[| |]', 'verbatim'],
105-
['[|| ||]', 'verbatim with unprocessed inner verbatim']
225+
['[| |]*', 'verbatim code'],
226+
['[|| ||]', 'verbatim with unprocessed inner verbatim'],
227+
['[|| ||]*', 'verbatim code with unprocessed inner verbatim']
106228
].map(([label, info]) => {
107229
return snippetCompletion(label.replace(' ', '${ }') + '${}', {
108230
label,
@@ -148,12 +270,13 @@ export const pgmlLanguageData = {
148270
const insideTable = inside('Table');
149271
if (
150272
(insideTable == 2 || (insideTable == 1 && (!textBefore.endsWith('[#') || /^\s*#\]/.test(textAfter)))) &&
151-
(!inside('TableCell') || (textBefore.endsWith('[.') && !/^[ \t]*.\]/.test(textAfter)))
273+
((!inside('TableCell') && !textBefore.endsWith('.]*')) ||
274+
(textBefore.endsWith('[.') && !/^[ \t]*\.\]/.test(textAfter)))
152275
) {
153276
const previous = context.matchBefore(/\[|\[\./);
154277
return {
155278
from: previous?.from ?? context.pos,
156-
options: [tableCellSnippet]
279+
options: tableCellSnippets
157280
};
158281
}
159282

@@ -168,7 +291,7 @@ export const pgmlLanguageData = {
168291
if (!previous && !context.explicit) return;
169292
return {
170293
from: previous?.from ?? context.pos,
171-
options: [variableSnippet, perlCommandSnippet]
294+
options: [...variableSnippets, ...perlCommandSnippets]
172295
};
173296
}
174297

@@ -178,7 +301,7 @@ export const pgmlLanguageData = {
178301
if (!previous && !context.explicit) return;
179302
return {
180303
from: previous?.from ?? context.pos,
181-
options: [variableSnippet, perlCommandSnippet]
304+
options: [...variableSnippets, ...perlCommandSnippets]
182305
};
183306
}
184307

@@ -196,14 +319,14 @@ export const pgmlLanguageData = {
196319
return {
197320
from: previous?.from ?? context.pos,
198321
options: [
199-
answerRuleSnippet,
322+
...answerRuleSnippets,
200323
...mathModeSnippets,
201-
variableSnippet,
202-
perlCommandSnippet,
324+
...variableSnippets,
325+
...perlCommandSnippets,
203326
imageSnippet,
204327
tagSnippet,
205328
commentSnippet,
206-
tableSnippet,
329+
...tableSnippets,
207330
...verbatimSnippets
208331
]
209332
};
@@ -222,14 +345,14 @@ export const pgmlLanguageData = {
222345
return {
223346
from: context.pos,
224347
options: [
225-
answerRuleSnippet,
348+
...answerRuleSnippets,
226349
...mathModeSnippets,
227-
variableSnippet,
228-
perlCommandSnippet,
350+
...variableSnippets,
351+
...perlCommandSnippets,
229352
imageSnippet,
230353
tagSnippet,
231354
commentSnippet,
232-
tableSnippet,
355+
...tableSnippets,
233356
...verbatimSnippets,
234357
preSnippet
235358
]

0 commit comments

Comments
 (0)