This commit is contained in:
jlkiri 2020-12-27 21:47:59 +09:00
parent 134c767484
commit 908a7bda9a
3 changed files with 171 additions and 173 deletions

View File

@ -12,7 +12,7 @@ function wait_highlight(...args) {
try { try {
const subChannel = new MessageChannel(); const subChannel = new MessageChannel();
worker.postMessage({ signal, port: subChannel.port1, args }, [ worker.postMessage({ signal, port: subChannel.port1, args }, [
subChannel.port1 subChannel.port1,
]); ]);
Atomics.wait(signal, 0, 0); Atomics.wait(signal, 0, 0);
return receiveMessageOnPort(subChannel.port2).message.result; return receiveMessageOnPort(subChannel.port2).message.result;

View File

@ -3,19 +3,17 @@ const shiki = require("shiki");
const path = require("path"); const path = require("path");
async function shiki_highlight(code, lang) { async function shiki_highlight(code, lang) {
const highlighter = await const highlighter = await shiki.getHighlighter({
shiki theme: "nord",
.getHighlighter({ langs: [
theme: 'nord', {
langs: [ id: "kdl",
{ scopeName: "source.kdl",
id: "kdl", path: path.join(process.cwd(), "kdl.tmLanguage.json"),
scopeName: "source.kdl", },
path: path.join(process.cwd(), "kdl.tmLanguage.json") ],
} });
] return highlighter.codeToHtml(code, lang);
})
return highlighter.codeToHtml(code, lang)
} }
parentPort.addListener("message", async ({ signal, port, args }) => { parentPort.addListener("message", async ({ signal, port, args }) => {
@ -25,9 +23,9 @@ parentPort.addListener("message", async ({ signal, port, args }) => {
// Post the result to the main thread before unlocking "signal" // Post the result to the main thread before unlocking "signal"
port.postMessage({ result }); port.postMessage({ result });
port.close(); port.close();
// Change the value of signal[0] to 1 // Change the value of signal[0] to 1
Atomics.store(signal, 0, 1); Atomics.store(signal, 0, 1);
// This will unlock the main thread when we notify it // This will unlock the main thread when we notify it
Atomics.notify(signal, 0); Atomics.notify(signal, 0);
}); });

View File

@ -1,45 +1,45 @@
{ {
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"comment":"Some of these patterns are taken straight from rust-analyzer: https://github.com/rust-lang/vscode-rust/blob/master/rust-analyzer/editors/code/rust.tmGrammar.json. Some was also taken from https://github.com/arm32x/vscode-sdlang/blob/master/syntaxes/sdlang.tmLanguage.json", "comment": "Some of these patterns are taken straight from rust-analyzer: https://github.com/rust-lang/vscode-rust/blob/master/rust-analyzer/editors/code/rust.tmGrammar.json. Some was also taken from https://github.com/arm32x/vscode-sdlang/blob/master/syntaxes/sdlang.tmLanguage.json",
"name": "KDL", "name": "KDL",
"patterns": [ "patterns": [
{ {
"include": "#null" "include": "#null"
}, },
{ {
"include": "#boolean" "include": "#boolean"
}, },
{ {
"include": "#float_fraction" "include": "#float_fraction"
}, },
{ {
"include": "#float_exp" "include": "#float_exp"
}, },
{ {
"include": "#decimal" "include": "#decimal"
}, },
{ {
"include": "#hexadecimal" "include": "#hexadecimal"
}, },
{ {
"include": "#octal" "include": "#octal"
}, },
{ {
"include": "#binary" "include": "#binary"
}, },
{ {
"include": "#raw-strings" "include": "#raw-strings"
}, },
{ {
"include": "#strings" "include": "#strings"
}, },
{ {
"include": "#block_comment" "include": "#block_comment"
}, },
{ {
"include": "#block_doc_comment" "include": "#block_doc_comment"
}, },
{ {
"include": "#slashdash_block_comment" "include": "#slashdash_block_comment"
}, },
{ {
@ -48,119 +48,119 @@
{ {
"include": "#slashdash_node_comment" "include": "#slashdash_node_comment"
}, },
{ {
"include": "#line_comment" "include": "#line_comment"
}, },
{ {
"include": "#attribute" "include": "#attribute"
}, },
{ {
"include": "#node_name" "include": "#node_name"
} }
], ],
"repository": { "repository": {
"float_fraction": { "float_fraction": {
"comment": "Floating point literal (fraction)", "comment": "Floating point literal (fraction)",
"name": "constant.numeric.float.rust", "name": "constant.numeric.float.rust",
"match": "\\b([0-9\\-\\+]|\\-|\\+)[0-9_]*\\.[0-9][0-9_]*([eE][+-]?[0-9_]+)?\\b" "match": "\\b([0-9\\-\\+]|\\-|\\+)[0-9_]*\\.[0-9][0-9_]*([eE][+-]?[0-9_]+)?\\b"
}, },
"float_exp": { "float_exp": {
"comment": "Floating point literal (exponent)", "comment": "Floating point literal (exponent)",
"name": "constant.numeric.float.rust", "name": "constant.numeric.float.rust",
"match": "\\b[0-9][0-9_]*(\\.[0-9][0-9_]*)?[eE][+-]?[0-9_]+\\b" "match": "\\b[0-9][0-9_]*(\\.[0-9][0-9_]*)?[eE][+-]?[0-9_]+\\b"
}, },
"decimal": { "decimal": {
"comment": "Integer literal (decimal)", "comment": "Integer literal (decimal)",
"name": "constant.numeric.integer.decimal.rust", "name": "constant.numeric.integer.decimal.rust",
"match": "\\b[0-9\\-\\+][0-9_]*\\b" "match": "\\b[0-9\\-\\+][0-9_]*\\b"
}, },
"hexadecimal": { "hexadecimal": {
"comment": "Integer literal (hexadecimal)", "comment": "Integer literal (hexadecimal)",
"name": "constant.numeric.integer.hexadecimal.rust", "name": "constant.numeric.integer.hexadecimal.rust",
"match": "\\b0x[a-fA-F0-9_]+\\b" "match": "\\b0x[a-fA-F0-9_]+\\b"
}, },
"octal": { "octal": {
"comment": "Integer literal (octal)", "comment": "Integer literal (octal)",
"name": "constant.numeric.integer.octal.rust", "name": "constant.numeric.integer.octal.rust",
"match": "\\b0o[0-7_]+\\b" "match": "\\b0o[0-7_]+\\b"
}, },
"binary": { "binary": {
"comment": "Integer literal (binary)", "comment": "Integer literal (binary)",
"name": "constant.numeric.integer.binary.rust", "name": "constant.numeric.integer.binary.rust",
"match": "\\b0b[01_]+\\b" "match": "\\b0b[01_]+\\b"
}, },
"node_name": { "node_name": {
"name": "entity.name.tag", "name": "entity.name.tag",
"match": "(?![\\\\{\\}<>;\\[\\]\\=,])[\\w\\-_~!@#\\$%^&*+|/.\\(\\)]+" "match": "(?![\\\\{\\}<>;\\[\\]\\=,])[\\w\\-_~!@#\\$%^&*+|/.\\(\\)]+"
}, },
"attribute": { "attribute": {
"name": "entity.other.attribute-name.kdl", "name": "entity.other.attribute-name.kdl",
"match": "(?![\\\\{\\}<>;\\[\\]\\=,])[\\w\\-_~!@#\\$%^&*+|/.]+(=)", "match": "(?![\\\\{\\}<>;\\[\\]\\=,])[\\w\\-_~!@#\\$%^&*+|/.]+(=)",
"captures": { "captures": {
"1": { "1": {
"name": "punctuation.separator.key-value.kdl" "name": "punctuation.separator.key-value.kdl"
} }
} }
}, },
"null": { "null": {
"name": "constant.language.null.kdl", "name": "constant.language.null.kdl",
"match": "\\bnull\\b" "match": "\\bnull\\b"
}, },
"boolean": { "boolean": {
"name": "constant.language.boolean.kdl", "name": "constant.language.boolean.kdl",
"match": "\\b(true|false)\\b" "match": "\\b(true|false)\\b"
}, },
"strings": { "strings": {
"name": "string.quoted.double.kdl", "name": "string.quoted.double.kdl",
"begin": "\"", "begin": "\"",
"end": "\"", "end": "\"",
"patterns": [ "patterns": [
{ {
"name": "constant.character.escape.kdl", "name": "constant.character.escape.kdl",
"match": "\\\\(:?[nrtbf\\\\\"]|u\\{[a-fA-F0-9]{1,6}\\})" "match": "\\\\(:?[nrtbf\\\\\"]|u\\{[a-fA-F0-9]{1,6}\\})"
} }
] ]
}, },
"raw-strings": { "raw-strings": {
"name": "string.quoted.double.raw.kdl", "name": "string.quoted.double.raw.kdl",
"begin": "b?r(#*)\"", "begin": "b?r(#*)\"",
"end": "\"\\1" "end": "\"\\1"
}, },
"block_doc_comment": { "block_doc_comment": {
"comment": "Block documentation comment", "comment": "Block documentation comment",
"name": "comment.block.documentation.kdl", "name": "comment.block.documentation.kdl",
"begin": "/\\*[\\*!](?![\\*/])", "begin": "/\\*[\\*!](?![\\*/])",
"end": "\\*/", "end": "\\*/",
"patterns": [ "patterns": [
{ {
"include": "#block_doc_comment" "include": "#block_doc_comment"
}, },
{ {
"include": "#block_comment" "include": "#block_comment"
} }
] ]
}, },
"block_comment": { "block_comment": {
"comment": "Block comment", "comment": "Block comment",
"name": "comment.block.kdl", "name": "comment.block.kdl",
"begin": "/\\*", "begin": "/\\*",
"end": "\\*/", "end": "\\*/",
"patterns": [ "patterns": [
{ {
"include": "#block_doc_comment" "include": "#block_doc_comment"
}, },
{ {
"include": "#block_comment" "include": "#block_comment"
} }
] ]
}, },
"line_comment": { "line_comment": {
"comment": "Single-line comment", "comment": "Single-line comment",
"name": "comment.line.double-slash.rust", "name": "comment.line.double-slash.rust",
"begin": "//", "begin": "//",
"end": "$" "end": "$"
}, },
"slashdash_comment": { "slashdash_comment": {
"name": "comment.line.double-slash", "name": "comment.line.double-slash",
"comment": "Slashdash inline comment", "comment": "Slashdash inline comment",
"begin": "(?<!^)/-", "begin": "(?<!^)/-",
@ -178,6 +178,6 @@
"begin": "/-{", "begin": "/-{",
"end": "}" "end": "}"
} }
}, },
"scopeName": "source.kdl" "scopeName": "source.kdl"
} }