chore(code): reintegrate hcl syntax

This commit is contained in:
Elian Doran
2025-05-11 10:54:15 +03:00
parent efc08a61ef
commit 9f3e990c95
4 changed files with 33 additions and 31 deletions

View File

@@ -21,6 +21,7 @@
"dependencies": {
"@codemirror/commands": "6.8.1",
"@codemirror/legacy-modes": "6.5.1",
"@codemirror/view": "6.36.7"
"@codemirror/view": "6.36.7",
"codemirror-lang-hcl": "0.1.0"
}
}

View File

@@ -68,8 +68,14 @@ export default class CodeMirror extends EditorView {
const correspondingSyntax = byMimeType[mime];
if (correspondingSyntax) {
const extension = StreamLanguage.define(await correspondingSyntax());
newExtension.push(extension);
const resolvedSyntax = await correspondingSyntax();
if ("token" in resolvedSyntax) {
const extension = StreamLanguage.define(resolvedSyntax);
newExtension.push(extension);
} else {
newExtension.push(resolvedSyntax());
}
}
this.dispatch({

View File

@@ -1,6 +1,6 @@
import { type StreamParser } from "@codemirror/language"
import { LanguageSupport, type StreamParser } from "@codemirror/language"
const byMimeType: Record<string, (() => Promise<StreamParser<unknown>>) | null> = {
const byMimeType: Record<string, (() => Promise<StreamParser<unknown> | (() => LanguageSupport)>) | null> = {
"text/plain": null,
"text/apl": async () => (await import('@codemirror/legacy-modes/mode/apl')).apl,
"text/x-ttcn-asn": async () => (await import('@codemirror/legacy-modes/mode/ttcn')).ttcn,
@@ -134,7 +134,7 @@ const byMimeType: Record<string, (() => Promise<StreamParser<unknown>>) | null>
"text/x-swift": async () => (await import('@codemirror/legacy-modes/mode/swift')).swift,
"text/x-systemverilog": null,
"text/x-tcl": async () => (await import('@codemirror/legacy-modes/mode/tcl')).tcl,
"text/x-hcl": null,
"text/x-hcl": async () => (await import('codemirror-lang-hcl')).hcl,
"text/x-textile": async () => (await import('@codemirror/legacy-modes/mode/textile')).textile,
"text/x-tiddlywiki": async () => (await import('@codemirror/legacy-modes/mode/tiddlywiki')).tiddlyWiki,
"text/tiki": async () => (await import('@codemirror/legacy-modes/mode/tiki')).tiki,