@marko/language-server 0.12.6 → 0.12.7
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.
- package/dist/index.js +61 -58
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +61 -58
- package/dist/index.mjs.map +2 -2
- package/dist/utils/compiler.d.ts +1 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -17,7 +17,6 @@ import { TextDocument as TextDocument3 } from "vscode-languageserver-textdocumen
|
|
|
17
17
|
import { inspect as inspect2, isDeepStrictEqual } from "util";
|
|
18
18
|
|
|
19
19
|
// src/utils/compiler.ts
|
|
20
|
-
import { URI as URI2 } from "vscode-uri";
|
|
21
20
|
import resolveFrom from "resolve-from";
|
|
22
21
|
import lassoPackageRoot from "lasso-package-root";
|
|
23
22
|
import * as builtinCompiler from "@marko/compiler";
|
|
@@ -558,29 +557,14 @@ function getCompilerInfo(doc) {
|
|
|
558
557
|
}
|
|
559
558
|
return info;
|
|
560
559
|
}
|
|
561
|
-
function
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
getCompilerInfo(document).cache.delete(document);
|
|
569
|
-
} else if (/[./\\]marko(?:-tag)?\.json$/.test(document.uri)) {
|
|
570
|
-
clearAllCaches();
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
});
|
|
574
|
-
documents2.onDidClose(({ document }) => {
|
|
575
|
-
if (document.languageId === "marko" && URI2.parse(document.uri).scheme !== "file") {
|
|
576
|
-
getCompilerInfo(document).cache.delete(document);
|
|
560
|
+
function clearCompilerCache(doc) {
|
|
561
|
+
if (doc) {
|
|
562
|
+
getCompilerInfo(doc).cache.delete(doc);
|
|
563
|
+
} else {
|
|
564
|
+
for (const [, info] of compilerInfoByDir) {
|
|
565
|
+
info.cache.clear();
|
|
566
|
+
info.compiler.taglib.clearCaches();
|
|
577
567
|
}
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
function clearAllCaches() {
|
|
581
|
-
for (const [, info] of compilerInfoByDir) {
|
|
582
|
-
info.cache.clear();
|
|
583
|
-
info.compiler.taglib.clearCaches();
|
|
584
568
|
}
|
|
585
569
|
}
|
|
586
570
|
function loadCompilerInfo(dir) {
|
|
@@ -625,7 +609,7 @@ function loadCompilerInfo(dir) {
|
|
|
625
609
|
// src/utils/messages.ts
|
|
626
610
|
import { inspect } from "util";
|
|
627
611
|
var connection;
|
|
628
|
-
function
|
|
612
|
+
function setup(_) {
|
|
629
613
|
connection = _;
|
|
630
614
|
}
|
|
631
615
|
function displayError(data) {
|
|
@@ -692,7 +676,7 @@ ${closingTagStr}`
|
|
|
692
676
|
|
|
693
677
|
// src/service/marko/complete/OpenTagName.ts
|
|
694
678
|
import path2 from "path";
|
|
695
|
-
import { URI as
|
|
679
|
+
import { URI as URI2 } from "vscode-uri";
|
|
696
680
|
import {
|
|
697
681
|
CompletionItemKind as CompletionItemKind2,
|
|
698
682
|
InsertTextFormat as InsertTextFormat2,
|
|
@@ -721,7 +705,7 @@ function OpenTagName({
|
|
|
721
705
|
return tags.filter((it) => !it.deprecated).filter((it) => it.name !== "*").filter((it) => /^[^_]/.test(it.name) || !/\/node_modules\//.test(it.filePath)).map((it) => {
|
|
722
706
|
let label = it.isNestedTag ? `@${it.name}` : it.name;
|
|
723
707
|
const fileForTag = it.template || it.renderer || it.filePath;
|
|
724
|
-
const fileURIForTag =
|
|
708
|
+
const fileURIForTag = URI2.file(fileForTag).toString();
|
|
725
709
|
const nodeModuleMatch = /\/node_modules\/((?:@[^/]+\/)?[^/]+)/.exec(fileForTag);
|
|
726
710
|
const nodeModuleName = nodeModuleMatch && nodeModuleMatch[1];
|
|
727
711
|
const isCoreTag = nodeModuleName === "marko";
|
|
@@ -904,9 +888,10 @@ var doValidate = (doc) => {
|
|
|
904
888
|
try {
|
|
905
889
|
compiler.compileSync(doc.getText(), fsPath || "untitled.marko", {
|
|
906
890
|
cache: cache2,
|
|
907
|
-
|
|
891
|
+
translator,
|
|
908
892
|
code: false,
|
|
909
|
-
|
|
893
|
+
output: "source",
|
|
894
|
+
sourceMaps: false
|
|
910
895
|
});
|
|
911
896
|
} catch (e) {
|
|
912
897
|
let match;
|
|
@@ -922,7 +907,7 @@ var doValidate = (doc) => {
|
|
|
922
907
|
|
|
923
908
|
// src/service/marko/definition/OpenTagName.ts
|
|
924
909
|
import path3 from "path";
|
|
925
|
-
import { URI as
|
|
910
|
+
import { URI as URI4 } from "vscode-uri";
|
|
926
911
|
import { Range as Range4, LocationLink } from "vscode-languageserver";
|
|
927
912
|
|
|
928
913
|
// src/utils/regexp-builder.ts
|
|
@@ -951,12 +936,12 @@ function escape(val) {
|
|
|
951
936
|
|
|
952
937
|
// src/utils/utils.ts
|
|
953
938
|
import fs from "fs";
|
|
954
|
-
import { URI as
|
|
939
|
+
import { URI as URI3 } from "vscode-uri";
|
|
955
940
|
import { Position, Range as Range3 } from "vscode-languageserver";
|
|
956
941
|
import { TextDocument } from "vscode-languageserver-textdocument";
|
|
957
942
|
var START_OF_FILE = Range3.create(Position.create(0, 0), Position.create(0, 0));
|
|
958
943
|
function createTextDocument(filename) {
|
|
959
|
-
const uri =
|
|
944
|
+
const uri = URI3.file(filename).toString();
|
|
960
945
|
const content = fs.readFileSync(filename, "utf-8");
|
|
961
946
|
return TextDocument.create(uri, "plaintext", 0, content);
|
|
962
947
|
}
|
|
@@ -993,12 +978,12 @@ function OpenTagName2({
|
|
|
993
978
|
}
|
|
994
979
|
}
|
|
995
980
|
return [
|
|
996
|
-
LocationLink.create(
|
|
981
|
+
LocationLink.create(URI4.file(tagEntryFile).toString(), range, range, parsed.locationAt(node))
|
|
997
982
|
];
|
|
998
983
|
}
|
|
999
984
|
|
|
1000
985
|
// src/service/marko/definition/AttrName.ts
|
|
1001
|
-
import { URI as
|
|
986
|
+
import { URI as URI5 } from "vscode-uri";
|
|
1002
987
|
import { Range as Range5, LocationLink as LocationLink2 } from "vscode-languageserver";
|
|
1003
988
|
function AttrName2({
|
|
1004
989
|
lookup,
|
|
@@ -1027,7 +1012,7 @@ function AttrName2({
|
|
|
1027
1012
|
}
|
|
1028
1013
|
}
|
|
1029
1014
|
return [
|
|
1030
|
-
LocationLink2.create(
|
|
1015
|
+
LocationLink2.create(URI5.file(attrEntryFile).toString(), range, range, parsed.locationAt(node))
|
|
1031
1016
|
];
|
|
1032
1017
|
}
|
|
1033
1018
|
|
|
@@ -1054,7 +1039,7 @@ var findDefinition = async (doc, params) => {
|
|
|
1054
1039
|
|
|
1055
1040
|
// src/service/marko/format.ts
|
|
1056
1041
|
import { Position as Position2, Range as Range6, TextEdit as TextEdit4 } from "vscode-languageserver";
|
|
1057
|
-
import { URI as
|
|
1042
|
+
import { URI as URI6 } from "vscode-uri";
|
|
1058
1043
|
import * as prettier from "prettier";
|
|
1059
1044
|
import * as markoPrettier from "prettier-plugin-marko";
|
|
1060
1045
|
var NO_EDIT = [
|
|
@@ -1062,7 +1047,7 @@ var NO_EDIT = [
|
|
|
1062
1047
|
];
|
|
1063
1048
|
var format2 = async (doc, params, token) => {
|
|
1064
1049
|
try {
|
|
1065
|
-
const { fsPath, scheme } =
|
|
1050
|
+
const { fsPath, scheme } = URI6.parse(doc.uri);
|
|
1066
1051
|
const text = doc.getText();
|
|
1067
1052
|
const options = {
|
|
1068
1053
|
parser: "marko",
|
|
@@ -1482,8 +1467,9 @@ if (typeof __require !== "undefined" && __require.extensions && !(".ts" in __req
|
|
|
1482
1467
|
}
|
|
1483
1468
|
var documents = new TextDocuments(TextDocument3);
|
|
1484
1469
|
var connection2 = createConnection(ProposedFeatures.all);
|
|
1485
|
-
var
|
|
1486
|
-
var
|
|
1470
|
+
var prevDiags = /* @__PURE__ */ new WeakMap();
|
|
1471
|
+
var pendingDiags = /* @__PURE__ */ new WeakSet();
|
|
1472
|
+
var diagnosticTimeout;
|
|
1487
1473
|
console.log = (...args) => {
|
|
1488
1474
|
connection2.console.log(args.map((v) => inspect2(v)).join(" "));
|
|
1489
1475
|
};
|
|
@@ -1493,8 +1479,7 @@ console.error = (...args) => {
|
|
|
1493
1479
|
process.on("uncaughtException", console.error);
|
|
1494
1480
|
process.on("unhandledRejection", console.error);
|
|
1495
1481
|
connection2.onInitialize(() => {
|
|
1496
|
-
|
|
1497
|
-
setup(connection2, documents);
|
|
1482
|
+
setup(connection2);
|
|
1498
1483
|
return {
|
|
1499
1484
|
capabilities: {
|
|
1500
1485
|
textDocumentSync: TextDocumentSyncKind.Incremental,
|
|
@@ -1527,11 +1512,12 @@ connection2.onInitialize(() => {
|
|
|
1527
1512
|
}
|
|
1528
1513
|
};
|
|
1529
1514
|
});
|
|
1530
|
-
connection2.
|
|
1531
|
-
|
|
1532
|
-
})
|
|
1533
|
-
|
|
1534
|
-
|
|
1515
|
+
connection2.onDidChangeConfiguration(validateDocs);
|
|
1516
|
+
connection2.onDidChangeWatchedFiles(validateDocs);
|
|
1517
|
+
documents.onDidChangeContent(({ document }) => {
|
|
1518
|
+
queueDiagnostic();
|
|
1519
|
+
pendingDiags.add(document);
|
|
1520
|
+
clearCompilerCache(document);
|
|
1535
1521
|
});
|
|
1536
1522
|
connection2.onCompletion(async (params, cancel) => {
|
|
1537
1523
|
return await service.doComplete(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
@@ -1545,21 +1531,38 @@ connection2.onHover(async (params, cancel) => {
|
|
|
1545
1531
|
connection2.onDocumentFormatting(async (params, cancel) => {
|
|
1546
1532
|
return await service.format(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
1547
1533
|
});
|
|
1548
|
-
function
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1534
|
+
function validateDocs() {
|
|
1535
|
+
queueDiagnostic();
|
|
1536
|
+
clearCompilerCache();
|
|
1537
|
+
for (const doc of documents.all()) {
|
|
1538
|
+
pendingDiags.add(doc);
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
function queueDiagnostic() {
|
|
1542
|
+
clearTimeout(diagnosticTimeout);
|
|
1543
|
+
const id = diagnosticTimeout = setTimeout(async () => {
|
|
1544
|
+
const results = await Promise.all(documents.all().map(async (doc) => {
|
|
1545
|
+
if (!pendingDiags.delete(doc))
|
|
1546
|
+
return;
|
|
1547
|
+
const prevDiag = prevDiags.get(doc) || [];
|
|
1548
|
+
const nextDiag = await service.doValidate(doc) || [];
|
|
1549
|
+
if (isDeepStrictEqual(prevDiag, nextDiag))
|
|
1550
|
+
return;
|
|
1551
|
+
return [doc, nextDiag];
|
|
1552
|
+
}));
|
|
1553
|
+
if (id === diagnosticTimeout) {
|
|
1554
|
+
for (const result of results) {
|
|
1555
|
+
if (result) {
|
|
1556
|
+
const [doc, diag] = result;
|
|
1557
|
+
prevDiags.set(doc, diag);
|
|
1558
|
+
connection2.sendDiagnostics({
|
|
1559
|
+
uri: doc.uri,
|
|
1560
|
+
diagnostics: diag
|
|
1561
|
+
});
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1555
1564
|
}
|
|
1556
|
-
prevDiagnostics.set(doc, nextDiag);
|
|
1557
|
-
connection2.sendDiagnostics({
|
|
1558
|
-
uri: doc.uri,
|
|
1559
|
-
diagnostics: nextDiag
|
|
1560
|
-
});
|
|
1561
1565
|
}, 400);
|
|
1562
|
-
diagnosticTimeouts.set(doc, id);
|
|
1563
1566
|
}
|
|
1564
1567
|
documents.listen(connection2);
|
|
1565
1568
|
connection2.listen();
|