Fold Decodal delimited blocks from opener
This commit is contained in:
parent
ee031bd2e8
commit
720c71157e
|
|
@ -1,4 +1,4 @@
|
|||
import { LRLanguage, LanguageSupport, HighlightStyle, syntaxHighlighting, foldNodeProp, foldInside, indentNodeProp } from '@codemirror/language';
|
||||
import { LRLanguage, LanguageSupport, HighlightStyle, syntaxHighlighting, foldNodeProp, indentNodeProp } from '@codemirror/language';
|
||||
import { styleTags, tags as t } from '@lezer/highlight';
|
||||
import { parser } from './decodal-parser.js';
|
||||
|
||||
|
|
@ -25,13 +25,22 @@ const parserWithMetadata = parser.configure({
|
|||
LetExpression: context => context.column(context.node.from) + context.unit,
|
||||
}),
|
||||
foldNodeProp.add({
|
||||
Object: foldInside,
|
||||
Array: foldInside,
|
||||
MatchExpression: foldInside,
|
||||
Object: foldDelimited('lBrace', 'rBrace'),
|
||||
Array: foldDelimited('lBracket', 'rBracket'),
|
||||
MatchExpression: foldDelimited('lBrace', 'rBrace'),
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
function foldDelimited(openName, closeName) {
|
||||
return (node) => {
|
||||
const open = node.getChild(openName);
|
||||
const close = node.getChild(closeName);
|
||||
if (!open || !close || open.to >= close.from) return null;
|
||||
return { from: open.to, to: close.from };
|
||||
};
|
||||
}
|
||||
|
||||
export const decodalLanguage = LRLanguage.define({
|
||||
parser: parserWithMetadata,
|
||||
languageData: {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user