@lokascript/language-server 2.10.0 → 2.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4189,14 +4189,26 @@ var MultilingualDSLImpl = class {
|
|
|
4189
4189
|
}
|
|
4190
4190
|
translate(input, fromLanguage, toLanguage) {
|
|
4191
4191
|
if (isExplicitSyntax(input)) return input;
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4192
|
+
let node;
|
|
4193
|
+
try {
|
|
4194
|
+
node = this.parseWithConfidence(input, fromLanguage).node;
|
|
4195
|
+
} catch (parseError) {
|
|
4196
|
+
if (this.hasGrammarProfile(fromLanguage) && this.hasGrammarProfile(toLanguage)) {
|
|
4197
|
+
return this.transformer.transform(input, fromLanguage, toLanguage);
|
|
4197
4198
|
}
|
|
4199
|
+
throw parseError;
|
|
4200
|
+
}
|
|
4201
|
+
const rendered = this.registry.getSupportedLanguages().includes(toLanguage) ? this.render(node, toLanguage) : null;
|
|
4202
|
+
if (rendered != null) return rendered;
|
|
4203
|
+
if (this.hasGrammarProfile(fromLanguage) && this.hasGrammarProfile(toLanguage)) {
|
|
4204
|
+
return this.transformer.transform(input, fromLanguage, toLanguage);
|
|
4198
4205
|
}
|
|
4199
|
-
|
|
4206
|
+
throw new Error(
|
|
4207
|
+
`translate() could not render action "${node.action}" in language "${toLanguage}": no custom renderer, domain renderer, or schema pattern covers it, and no grammar profile is configured for the transformer fallback. Either add "${toLanguage}" to the DSL's languages/renderer, or set 'grammarProfile' on its LanguageConfig in createMultilingualDSL() (parse/validate/compile do not need it).`
|
|
4208
|
+
);
|
|
4209
|
+
}
|
|
4210
|
+
hasGrammarProfile(language) {
|
|
4211
|
+
return this.profileProvider.getProfile(language) != null;
|
|
4200
4212
|
}
|
|
4201
4213
|
compile(input, language) {
|
|
4202
4214
|
if (!this.codeGenerator) {
|
package/dist/server.js
CHANGED
|
@@ -1191,6 +1191,42 @@ function getCommandDescription(command, language) {
|
|
|
1191
1191
|
|
|
1192
1192
|
// src/server.ts
|
|
1193
1193
|
import * as semanticImport from "@lokascript/semantic";
|
|
1194
|
+
|
|
1195
|
+
// src/translate-with-verification.ts
|
|
1196
|
+
import { scoreNodes } from "@lokascript/semantic/fidelity";
|
|
1197
|
+
function translateWithVerification(params, semantic) {
|
|
1198
|
+
if (!params?.code?.trim()) {
|
|
1199
|
+
return { ok: false, error: "No hyperscript code provided." };
|
|
1200
|
+
}
|
|
1201
|
+
if (!params.to) {
|
|
1202
|
+
return { ok: false, error: "No target language provided." };
|
|
1203
|
+
}
|
|
1204
|
+
if (!semantic?.translate || !semantic.parseSemantic) {
|
|
1205
|
+
return {
|
|
1206
|
+
ok: false,
|
|
1207
|
+
error: "Multilingual support is not available in this server build (@lokascript/semantic is absent \u2014 hyperscript mode)."
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
const from = params.from ?? "en";
|
|
1211
|
+
let rendered;
|
|
1212
|
+
try {
|
|
1213
|
+
rendered = semantic.translate(params.code, from, params.to);
|
|
1214
|
+
} catch (e) {
|
|
1215
|
+
return { ok: false, error: e instanceof Error ? e.message : String(e) };
|
|
1216
|
+
}
|
|
1217
|
+
let verification = { ok: false };
|
|
1218
|
+
try {
|
|
1219
|
+
const ref = semantic.parseSemantic(params.code, from);
|
|
1220
|
+
const cand = semantic.parseSemantic(rendered, params.to);
|
|
1221
|
+
if (ref?.node && cand?.node) {
|
|
1222
|
+
verification = { ok: true, ...scoreNodes(ref.node, cand.node) };
|
|
1223
|
+
}
|
|
1224
|
+
} catch {
|
|
1225
|
+
}
|
|
1226
|
+
return { ok: true, code: rendered, verification };
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
// src/server.ts
|
|
1194
1230
|
var semanticPackage = semanticImport;
|
|
1195
1231
|
function getOtherLanguages() {
|
|
1196
1232
|
if (!semanticPackage?.getRegisteredLanguages) return [];
|
|
@@ -1218,7 +1254,7 @@ try {
|
|
|
1218
1254
|
}
|
|
1219
1255
|
var frameworkIR = null;
|
|
1220
1256
|
try {
|
|
1221
|
-
const fw = await import("./dist-
|
|
1257
|
+
const fw = await import("./dist-QIYYJ23V.js");
|
|
1222
1258
|
frameworkIR = { fromInterchangeNode: fw.fromInterchangeNode, renderExplicit: fw.renderExplicit };
|
|
1223
1259
|
console.error(
|
|
1224
1260
|
"[lokascript-ls] @lokascript/framework loaded \u2014 LSE bracket notation in hover enabled"
|
|
@@ -1490,6 +1526,10 @@ function isHyperscriptCompatMode(mode) {
|
|
|
1490
1526
|
var resolvedMode = "hyperscript";
|
|
1491
1527
|
var envDefaultMode = process.env.HYPERSCRIPT_LS_DEFAULT_MODE;
|
|
1492
1528
|
var connection = createConnection(ProposedFeatures.all);
|
|
1529
|
+
connection.onRequest(
|
|
1530
|
+
"lokascript/translateWithVerification",
|
|
1531
|
+
(params) => translateWithVerification(params, semanticPackage)
|
|
1532
|
+
);
|
|
1493
1533
|
var documents = new TextDocuments(TextDocument);
|
|
1494
1534
|
var cachedAnalyzer = null;
|
|
1495
1535
|
function getSemanticAnalyzer() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lokascript/language-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.1",
|
|
4
4
|
"description": "Language Server Protocol implementation for LokaScript/hyperscript with 21 language support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/server.js",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"vscode-languageserver-textdocument": "^1.0.11"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@hyperfixi/core": "^2.
|
|
35
|
-
"@lokascript/semantic": "^2.
|
|
34
|
+
"@hyperfixi/core": "^2.11.1",
|
|
35
|
+
"@lokascript/semantic": "^2.11.1"
|
|
36
36
|
},
|
|
37
37
|
"peerDependenciesMeta": {
|
|
38
38
|
"@lokascript/semantic": {
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@hyperfixi/core": "^2.
|
|
47
|
-
"@lokascript/semantic": "^2.
|
|
46
|
+
"@hyperfixi/core": "^2.11.1",
|
|
47
|
+
"@lokascript/semantic": "^2.11.1",
|
|
48
48
|
"@types/node": "^26.1.2",
|
|
49
49
|
"@vitest/coverage-v8": "^4.0.0",
|
|
50
50
|
"tsup": "^8.0.0",
|