Bundle language tools with CodeMirror package
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
CodeMirror 6 language support for Decodal.
|
||||
|
||||
This package provides the Lezer parser metadata, highlighting tags, indentation rules, and block folding used by the Decodal Web playground.
|
||||
It does not include the Decodal runtime or WebAssembly evaluator.
|
||||
This package provides the Lezer parser metadata, highlighting tags, indentation rules, block folding, and formatter command used by the Decodal Web playground.
|
||||
It does not include the Decodal runtime evaluator.
|
||||
Use `decodal-wasm` when you want to evaluate Decodal in a browser.
|
||||
|
||||
## Install
|
||||
@@ -52,3 +52,23 @@ decodal({ highlight: false })
|
||||
```
|
||||
|
||||
Use this when you want the language support without the bundled highlight style.
|
||||
|
||||
## Formatting
|
||||
|
||||
The formatter is exposed as a separate subpath so plain syntax highlighting does not force callers to initialize WebAssembly.
|
||||
|
||||
```js
|
||||
import {
|
||||
formatDecodal,
|
||||
formatDecodalCommand,
|
||||
initDecodalFormatter,
|
||||
} from 'decodal-codemirror/format';
|
||||
import formatterWasm from 'decodal-codemirror/wasm/decodal_language_tools_bg.wasm?url';
|
||||
|
||||
await initDecodalFormatter(formatterWasm);
|
||||
|
||||
const result = formatDecodal('Server={port=Int default 8080;};');
|
||||
if (result.ok) console.log(result.source);
|
||||
|
||||
formatDecodalCommand(view);
|
||||
```
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
{
|
||||
"name": "@hare/decodal-codemirror",
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.4",
|
||||
"license": "MIT",
|
||||
"exports": "./src/mod.ts",
|
||||
"exports": {
|
||||
".": "./src/mod.ts",
|
||||
"./format": "./src/format.js",
|
||||
"./parser": "./src/decodal-parser.js",
|
||||
"./terms": "./src/decodal-parser.terms.js"
|
||||
},
|
||||
"imports": {
|
||||
"@codemirror/language": "npm:@codemirror/language@^6.12.4",
|
||||
"@codemirror/view": "npm:@codemirror/view@^6.43.6",
|
||||
"@lezer/highlight": "npm:@lezer/highlight@^1.2.3",
|
||||
"@lezer/lr": "npm:@lezer/lr@^1.4.10"
|
||||
},
|
||||
@@ -15,9 +21,16 @@
|
||||
"src/decodal.js",
|
||||
"src/decodal.d.ts",
|
||||
"src/decodal.js.d.ts",
|
||||
"src/format.js",
|
||||
"src/format.d.ts",
|
||||
"src/format.js.d.ts",
|
||||
"src/decodal-parser-jsr.js",
|
||||
"src/decodal-parser.js",
|
||||
"src/decodal-parser.terms.js",
|
||||
"wasm/decodal_language_tools.js",
|
||||
"wasm/decodal_language_tools.d.ts",
|
||||
"wasm/decodal_language_tools_bg.wasm",
|
||||
"wasm/decodal_language_tools_bg.wasm.d.ts",
|
||||
"package.json"
|
||||
]
|
||||
}
|
||||
|
||||
+4
-2
@@ -1,20 +1,22 @@
|
||||
{
|
||||
"name": "decodal-codemirror",
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.4",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "decodal-codemirror",
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.4",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"devDependencies": {
|
||||
"@codemirror/language": "^6.12.4",
|
||||
"@codemirror/view": "^6.43.6",
|
||||
"@lezer/highlight": "^1.2.3",
|
||||
"@lezer/lr": "^1.4.10"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@codemirror/language": "^6.12.4",
|
||||
"@codemirror/view": "^6.43.6",
|
||||
"@lezer/highlight": "^1.2.3",
|
||||
"@lezer/lr": "^1.4.10"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "decodal-codemirror",
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.4",
|
||||
"description": "CodeMirror 6 language support for Decodal.",
|
||||
"type": "module",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
@@ -14,13 +14,22 @@
|
||||
"types": "./src/decodal.d.ts",
|
||||
"import": "./src/decodal.js"
|
||||
},
|
||||
"./format": {
|
||||
"types": "./src/format.d.ts",
|
||||
"import": "./src/format.js"
|
||||
},
|
||||
"./parser": "./src/decodal-parser.js",
|
||||
"./terms": "./src/decodal-parser.terms.js"
|
||||
"./terms": "./src/decodal-parser.terms.js",
|
||||
"./wasm/decodal_language_tools_bg.wasm": "./wasm/decodal_language_tools_bg.wasm"
|
||||
},
|
||||
"types": "./src/decodal.d.ts",
|
||||
"files": [
|
||||
"README.md",
|
||||
"src/"
|
||||
"src/",
|
||||
"wasm/decodal_language_tools.js",
|
||||
"wasm/decodal_language_tools.d.ts",
|
||||
"wasm/decodal_language_tools_bg.wasm",
|
||||
"wasm/decodal_language_tools_bg.wasm.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"decodal",
|
||||
@@ -29,11 +38,13 @@
|
||||
],
|
||||
"peerDependencies": {
|
||||
"@codemirror/language": "^6.12.4",
|
||||
"@codemirror/view": "^6.43.6",
|
||||
"@lezer/highlight": "^1.2.3",
|
||||
"@lezer/lr": "^1.4.10"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@codemirror/language": "^6.12.4",
|
||||
"@codemirror/view": "^6.43.6",
|
||||
"@lezer/highlight": "^1.2.3",
|
||||
"@lezer/lr": "^1.4.10"
|
||||
}
|
||||
|
||||
+17
@@ -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;
|
||||
@@ -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
@@ -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;
|
||||
@@ -0,0 +1 @@
|
||||
# wasm-pack output is committed as part of decodal-codemirror.
|
||||
@@ -1 +0,0 @@
|
||||
# wasm-pack output is committed for the browser language tools package.
|
||||
@@ -1,39 +0,0 @@
|
||||
# decodal-language-tools
|
||||
|
||||
Source-level language tooling for Decodal.
|
||||
|
||||
This package is generated from the Rust crate in `crates/decodal-language-tools` with `wasm-pack`.
|
||||
It currently exposes a comment-preserving formatter that is shared by the official playground and future editor/LSP tooling.
|
||||
|
||||
Use `decodal-codemirror` separately when you need CodeMirror 6 language support.
|
||||
Use `decodal-wasm` separately when you need to evaluate Decodal in a browser.
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install decodal-language-tools
|
||||
```
|
||||
|
||||
JSR:
|
||||
|
||||
```sh
|
||||
deno add jsr:@hare/decodal-language-tools
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import init, { formatSource } from 'decodal-language-tools';
|
||||
|
||||
await init();
|
||||
|
||||
const result = JSON.parse(formatSource('Server={# host\nhost=String default "localhost";};'));
|
||||
|
||||
if (result.ok) {
|
||||
console.log(result.source);
|
||||
} else {
|
||||
console.error(result.error);
|
||||
}
|
||||
```
|
||||
|
||||
The exported functions return JSON strings so callers can handle diagnostics without depending on Rust data structures.
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"name": "@hare/decodal-language-tools",
|
||||
"version": "0.1.2",
|
||||
"license": "MIT",
|
||||
"exports": "./decodal_language_tools.js",
|
||||
"publish": {
|
||||
"include": [
|
||||
"README.md",
|
||||
"decodal_language_tools.js",
|
||||
"decodal_language_tools.d.ts",
|
||||
"decodal_language_tools_bg.wasm",
|
||||
"package.json"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
{
|
||||
"name": "decodal-language-tools",
|
||||
"type": "module",
|
||||
"description": "Source-level language tooling for Decodal.",
|
||||
"version": "0.1.2",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://gitea.hareworks.net/Hare/Decodal"
|
||||
},
|
||||
"files": [
|
||||
"decodal_language_tools_bg.wasm",
|
||||
"decodal_language_tools.js",
|
||||
"decodal_language_tools.d.ts"
|
||||
],
|
||||
"main": "decodal_language_tools.js",
|
||||
"types": "decodal_language_tools.d.ts",
|
||||
"sideEffects": [
|
||||
"./snippets/*"
|
||||
],
|
||||
"keywords": [
|
||||
"decodal",
|
||||
"formatter",
|
||||
"lsp",
|
||||
"tree-sitter"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user