mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-26 11:21:16 +01:00
Rename, fix autocomplete and singleline, etc...
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
import { LRLanguage, LanguageSupport } from '@codemirror/language';
|
||||
import { LanguageSupport, LRLanguage } from '@codemirror/language';
|
||||
import { parseMixed } from '@lezer/common';
|
||||
import { myCompletions } from '../completion/completion';
|
||||
import { placeholders } from '../widgets';
|
||||
import { parser as twigParser } from './twig';
|
||||
|
||||
export function twig(base?: LanguageSupport) {
|
||||
const parser = mixedOrPlainParser(base);
|
||||
const twigLanguage = LRLanguage.define({ name: 'twig', parser, languageData: {} });
|
||||
const completion = twigLanguage.data.of({
|
||||
const language = mixedOrPlainLanguage(base);
|
||||
const completion = language.data.of({
|
||||
autocomplete: myCompletions,
|
||||
});
|
||||
const languageSupport = new LanguageSupport(twigLanguage, [completion]);
|
||||
const languageSupport = new LanguageSupport(language, [completion]);
|
||||
|
||||
if (base) {
|
||||
const completion2 = base.language.data.of({ autocomplete: myCompletions });
|
||||
@@ -21,31 +20,22 @@ export function twig(base?: LanguageSupport) {
|
||||
}
|
||||
}
|
||||
|
||||
function mixedOrPlainParser(base?: LanguageSupport) {
|
||||
if (base === undefined) {
|
||||
return twigParser;
|
||||
function mixedOrPlainLanguage(base?: LanguageSupport): LRLanguage {
|
||||
const name = 'twig';
|
||||
|
||||
if (base == null) {
|
||||
return LRLanguage.define({ name, parser: twigParser });
|
||||
}
|
||||
|
||||
const mixedParser = twigParser.configure({
|
||||
props: [
|
||||
// Add basic folding/indent metadata
|
||||
// foldNodeProp.add({ Conditional: foldInside }),
|
||||
// indentNodeProp.add({
|
||||
// Conditional: (cx) => {
|
||||
// const closed = /^\s*\{% endif/.test(cx.textAfter);
|
||||
// return cx.lineIndent(cx.node.from) + (closed ? 0 : cx.unit);
|
||||
// },
|
||||
// }),
|
||||
],
|
||||
const parser = twigParser.configure({
|
||||
wrap: parseMixed((node) => {
|
||||
return node.type.isTop
|
||||
? {
|
||||
parser: base.language.parser,
|
||||
overlay: (node) => node.type.name === 'Text',
|
||||
}
|
||||
: null;
|
||||
if (!node.type.isTop) return null;
|
||||
return {
|
||||
parser: base.language.parser,
|
||||
overlay: (node) => node.type.name === 'Text',
|
||||
};
|
||||
}),
|
||||
});
|
||||
|
||||
return mixedParser;
|
||||
return LRLanguage.define({ name, parser });
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ directive {
|
||||
}
|
||||
|
||||
@tokens {
|
||||
Text { ![${[] Text? }
|
||||
Text { ![$] Text? }
|
||||
space { @whitespace+ }
|
||||
DirectiveContent { ![\]}$] DirectiveContent? }
|
||||
DirectiveContent { ![\]}] DirectiveContent? }
|
||||
@precedence { space DirectiveContent }
|
||||
"${[" "]}"
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ export const parser = LRParser.deserialize({
|
||||
propSources: [highlight],
|
||||
skippedNodes: [0],
|
||||
repeatNodeCount: 1,
|
||||
tokenData: ")a~RqOX#YX^%i^p#Ypq%iqt#Ytu'vu!}#Y!}#O$V#O#P#Y#P#Q(X#Q#o#Y#o#p$V#p#q#Y#q#r$t#r#y#Y#y#z%i#z$f#Y$f$g%i$g#BY#Y#BY#BZ%i#BZ$IS#Y$IS$I_%i$I_$I|#Y$I|$JO%i$JO$JT#Y$JT$JU%i$JU$KV#Y$KV$KW%i$KW&FU#Y&FU&FV%i&FV;'S#Y;'S;=`%c<%lO#YR#a[UPSQOt#Yu!}#Y!}#O$V#O#P#Y#P#Q$t#Q#o#Y#o#p$V#p#q#Y#q#r$t#r;'S#Y;'S;=`%c<%lO#YQ$[USQOt$Vu#P$V#Q#q$V#r;'S$V;'S;=`$n<%lO$VQ$qP;=`<%l$VP$yUUPOt$tu!}$t#O#o$t#p;'S$t;'S;=`%]<%lO$tP%`P;=`<%l$tR%fP;=`<%l#YR%rpUPYQSQOX#YX^%i^p#Ypq%iqt#Yu!}#Y!}#O$V#O#P#Y#P#Q$t#Q#o#Y#o#p$V#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