Add project-aware playground completion

This commit is contained in:
2026-08-13 18:07:24 +09:00
parent 610358110f
commit e862e53f3e
9 changed files with 416 additions and 12 deletions
+1
View File
@@ -10,6 +10,7 @@
"license": "MIT OR Apache-2.0",
"devDependencies": {
"@codemirror/language": "^6.12.4",
"@codemirror/state": "^6.7.1",
"@codemirror/view": "^6.43.6",
"@lezer/highlight": "^1.2.3",
"@lezer/lr": "^1.4.10"
+4
View File
@@ -9,6 +9,9 @@
"url": "git+https://gitea.hareworks.net/Hare/Decodal.git",
"directory": "packages/decodal-codemirror"
},
"scripts": {
"test": "node --test src/*.test.mjs"
},
"exports": {
".": {
"types": "./src/decodal.d.ts",
@@ -44,6 +47,7 @@
},
"devDependencies": {
"@codemirror/language": "^6.12.4",
"@codemirror/state": "^6.7.1",
"@codemirror/view": "^6.43.6",
"@lezer/highlight": "^1.2.3",
"@lezer/lr": "^1.4.10"
+5 -5
View File
@@ -1,4 +1,4 @@
import { LRLanguage, LanguageSupport, HighlightStyle, syntaxHighlighting, foldNodeProp, indentNodeProp } from '@codemirror/language';
import { LRLanguage, LanguageSupport, HighlightStyle, syntaxHighlighting, delimitedIndent, foldNodeProp, indentNodeProp } from '@codemirror/language';
import { styleTags, tags as t } from '@lezer/highlight';
import { parser } from './decodal-parser.js';
@@ -19,10 +19,10 @@ const parserWithMetadata = parser.configure({
'Semicolon Comma Dot Colon': t.punctuation,
}),
indentNodeProp.add({
Object: context => context.column(context.node.from) + context.unit,
Array: context => context.column(context.node.from) + context.unit,
ArrayConstraint: context => context.column(context.node.from) + context.unit,
MatchExpression: context => context.column(context.node.from) + context.unit,
Object: delimitedIndent({ closing: '}', align: false }),
Array: delimitedIndent({ closing: ']', align: false }),
ArrayConstraint: delimitedIndent({ closing: ']', align: false }),
MatchExpression: delimitedIndent({ closing: '}', align: false }),
LetExpression: context => context.column(context.node.from) + context.unit,
}),
foldNodeProp.add({
@@ -0,0 +1,35 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { getIndentation, indentUnit } from '@codemirror/language';
import { EditorState } from '@codemirror/state';
import { decodal } from './decodal.js';
function indentationAt(doc, lineNumber) {
const state = EditorState.create({
doc,
extensions: [decodal(), indentUnit.of(' ')],
});
return getIndentation(state, state.doc.line(lineNumber).from);
}
test('indents an inline object from its containing line', () => {
const doc = `hoge = fuga & piyo & {
}`;
assert.equal(indentationAt(doc, 2), 2);
assert.equal(indentationAt(doc, 3), 0);
});
test('preserves the surrounding indentation for a nested inline object', () => {
const doc = `root = {
hoge = fuga & piyo & {
};
};`;
assert.equal(indentationAt(doc, 3), 4);
assert.equal(indentationAt(doc, 4), 2);
});
+5 -5
View File
@@ -8,7 +8,7 @@
*
* @module
*/
import { HighlightStyle, LRLanguage, LanguageSupport, foldNodeProp, indentNodeProp, syntaxHighlighting } from 'npm:@codemirror/language@^6.12.4';
import { HighlightStyle, LRLanguage, LanguageSupport, delimitedIndent, foldNodeProp, indentNodeProp, syntaxHighlighting } from 'npm:@codemirror/language@^6.12.4';
import { styleTags, tags as t } from 'npm:@lezer/highlight@^1.2.3';
import { parser } from './decodal-parser-jsr.js';
@@ -29,10 +29,10 @@ const parserWithMetadata = parser.configure({
'Semicolon Comma Dot Colon': t.punctuation,
}),
indentNodeProp.add({
Object: context => context.column(context.node.from) + context.unit,
Array: context => context.column(context.node.from) + context.unit,
ArrayConstraint: context => context.column(context.node.from) + context.unit,
MatchExpression: context => context.column(context.node.from) + context.unit,
Object: delimitedIndent({ closing: '}', align: false }),
Array: delimitedIndent({ closing: ']', align: false }),
ArrayConstraint: delimitedIndent({ closing: ']', align: false }),
MatchExpression: delimitedIndent({ closing: '}', align: false }),
LetExpression: context => context.column(context.node.from) + context.unit,
}),
foldNodeProp.add({