* Move CodeMirror LRLanguage to new file This separates the base language support from the LSP and color picker. * Move the base CodeMirror KCL support to a local package * Start CodeMirror grammar tests * Exclude vitest config in tsconfig * Add KCL path to tsconfig * Remove stray import * Drop extension from import * Use __filename for commonjs compat * Check exec return before access * Build ES and CJS to dist * Format * Exclude all.test.ts from codespell This is to work around "fileTests" imported from Lezer. Future codespell versions look like they'll allow the code to be annotated, which would be nicer. --------- Co-authored-by: Matt Mundell <matt@mundell.me>
43 lines
1.0 KiB
TypeScript
43 lines
1.0 KiB
TypeScript
// Base CodeMirror language support for kcl.
|
|
|
|
import {
|
|
LRLanguage,
|
|
LanguageSupport,
|
|
indentNodeProp,
|
|
continuedIndent,
|
|
delimitedIndent,
|
|
foldNodeProp,
|
|
foldInside,
|
|
} from '@codemirror/language'
|
|
// @ts-ignore: No types available
|
|
import { parser } from './kcl.grammar'
|
|
|
|
export const KclLanguage = LRLanguage.define({
|
|
name: 'kcl',
|
|
parser: parser.configure({
|
|
props: [
|
|
indentNodeProp.add({
|
|
Body: delimitedIndent({ closing: '}' }),
|
|
BlockComment: () => null,
|
|
'Statement Property': continuedIndent({ except: /^{/ }),
|
|
}),
|
|
foldNodeProp.add({
|
|
'Body ArrayExpression ObjectExpression': foldInside,
|
|
BlockComment(tree) {
|
|
return { from: tree.from + 2, to: tree.to - 2 }
|
|
},
|
|
PipeExpression(tree) {
|
|
return { from: tree.firstChild!.to, to: tree.to }
|
|
},
|
|
}),
|
|
],
|
|
}),
|
|
languageData: {
|
|
commentTokens: { line: '//', block: { open: '/*', close: '*/' } },
|
|
},
|
|
})
|
|
|
|
export function kcl() {
|
|
return new LanguageSupport(KclLanguage)
|
|
}
|