Bundle language tools with CodeMirror package

This commit is contained in:
2026-07-09 21:25:04 +09:00
parent 59cb8f31e4
commit 8eac5c5cb4
24 changed files with 155 additions and 219 deletions
+17
View File
@@ -0,0 +1,17 @@
import type { EditorView } from '@codemirror/view';
export interface FormatSuccess {
ok: true;
source: string;
}
export interface FormatFailure {
ok: false;
error: string;
}
export type FormatResult = FormatSuccess | FormatFailure;
export declare function initDecodalFormatter(moduleOrPath?: RequestInfo | URL | Response | BufferSource | WebAssembly.Module): Promise<void>;
export declare function formatDecodal(source: string): FormatResult;
export declare function formatDecodalCommand(view: EditorView): boolean;
+28
View File
@@ -0,0 +1,28 @@
import initLanguageTools, { formatSource } from '../wasm/decodal_language_tools.js';
let initialized = false;
export async function initDecodalFormatter(moduleOrPath) {
await initLanguageTools(moduleOrPath);
initialized = true;
}
export function formatDecodal(source) {
if (!initialized) {
return { ok: false, error: 'Decodal formatter is not initialized' };
}
return JSON.parse(formatSource(source));
}
export function formatDecodalCommand(view) {
const result = formatDecodal(view.state.doc.toString());
if (!result.ok) return false;
view.dispatch({
changes: {
from: 0,
to: view.state.doc.length,
insert: result.source,
},
});
return true;
}
+17
View File
@@ -0,0 +1,17 @@
import type { EditorView } from '@codemirror/view';
export interface FormatSuccess {
ok: true;
source: string;
}
export interface FormatFailure {
ok: false;
error: string;
}
export type FormatResult = FormatSuccess | FormatFailure;
export declare function initDecodalFormatter(moduleOrPath?: RequestInfo | URL | Response | BufferSource | WebAssembly.Module): Promise<void>;
export declare function formatDecodal(source: string): FormatResult;
export declare function formatDecodalCommand(view: EditorView): boolean;