@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 CHANGED
@@ -21,7 +21,6 @@ var import_vscode_languageserver_textdocument3 = require("vscode-languageserver-
21
21
  var import_util2 = require("util");
22
22
 
23
23
  // src/utils/compiler.ts
24
- var import_vscode_uri2 = require("vscode-uri");
25
24
  var import_resolve_from = __toESM(require("resolve-from"));
26
25
  var import_lasso_package_root = __toESM(require("lasso-package-root"));
27
26
  var builtinCompiler = __toESM(require("@marko/compiler"));
@@ -562,29 +561,14 @@ function getCompilerInfo(doc) {
562
561
  }
563
562
  return info;
564
563
  }
565
- function setup(connection3, documents2) {
566
- connection3.onDidChangeWatchedFiles(() => {
567
- clearAllCaches();
568
- });
569
- documents2.onDidChangeContent(({ document }) => {
570
- if (document.version > 1) {
571
- if (document.languageId === "marko") {
572
- getCompilerInfo(document).cache.delete(document);
573
- } else if (/[./\\]marko(?:-tag)?\.json$/.test(document.uri)) {
574
- clearAllCaches();
575
- }
576
- }
577
- });
578
- documents2.onDidClose(({ document }) => {
579
- if (document.languageId === "marko" && import_vscode_uri2.URI.parse(document.uri).scheme !== "file") {
580
- getCompilerInfo(document).cache.delete(document);
564
+ function clearCompilerCache(doc) {
565
+ if (doc) {
566
+ getCompilerInfo(doc).cache.delete(doc);
567
+ } else {
568
+ for (const [, info] of compilerInfoByDir) {
569
+ info.cache.clear();
570
+ info.compiler.taglib.clearCaches();
581
571
  }
582
- });
583
- }
584
- function clearAllCaches() {
585
- for (const [, info] of compilerInfoByDir) {
586
- info.cache.clear();
587
- info.compiler.taglib.clearCaches();
588
572
  }
589
573
  }
590
574
  function loadCompilerInfo(dir) {
@@ -629,7 +613,7 @@ function loadCompilerInfo(dir) {
629
613
  // src/utils/messages.ts
630
614
  var import_util = require("util");
631
615
  var connection;
632
- function setup2(_) {
616
+ function setup(_) {
633
617
  connection = _;
634
618
  }
635
619
  function displayError(data) {
@@ -688,7 +672,7 @@ ${closingTagStr}`
688
672
 
689
673
  // src/service/marko/complete/OpenTagName.ts
690
674
  var import_path2 = __toESM(require("path"));
691
- var import_vscode_uri3 = require("vscode-uri");
675
+ var import_vscode_uri2 = require("vscode-uri");
692
676
  var import_vscode_languageserver2 = require("vscode-languageserver");
693
677
  function OpenTagName({
694
678
  document,
@@ -712,7 +696,7 @@ function OpenTagName({
712
696
  return tags.filter((it) => !it.deprecated).filter((it) => it.name !== "*").filter((it) => /^[^_]/.test(it.name) || !/\/node_modules\//.test(it.filePath)).map((it) => {
713
697
  let label = it.isNestedTag ? `@${it.name}` : it.name;
714
698
  const fileForTag = it.template || it.renderer || it.filePath;
715
- const fileURIForTag = import_vscode_uri3.URI.file(fileForTag).toString();
699
+ const fileURIForTag = import_vscode_uri2.URI.file(fileForTag).toString();
716
700
  const nodeModuleMatch = /\/node_modules\/((?:@[^/]+\/)?[^/]+)/.exec(fileForTag);
717
701
  const nodeModuleName = nodeModuleMatch && nodeModuleMatch[1];
718
702
  const isCoreTag = nodeModuleName === "marko";
@@ -890,9 +874,10 @@ var doValidate = (doc) => {
890
874
  try {
891
875
  compiler.compileSync(doc.getText(), fsPath || "untitled.marko", {
892
876
  cache: cache2,
893
- output: "source",
877
+ translator,
894
878
  code: false,
895
- translator
879
+ output: "source",
880
+ sourceMaps: false
896
881
  });
897
882
  } catch (e) {
898
883
  let match;
@@ -908,7 +893,7 @@ var doValidate = (doc) => {
908
893
 
909
894
  // src/service/marko/definition/OpenTagName.ts
910
895
  var import_path3 = __toESM(require("path"));
911
- var import_vscode_uri5 = require("vscode-uri");
896
+ var import_vscode_uri4 = require("vscode-uri");
912
897
  var import_vscode_languageserver7 = require("vscode-languageserver");
913
898
 
914
899
  // src/utils/regexp-builder.ts
@@ -937,12 +922,12 @@ function escape(val) {
937
922
 
938
923
  // src/utils/utils.ts
939
924
  var import_fs = __toESM(require("fs"));
940
- var import_vscode_uri4 = require("vscode-uri");
925
+ var import_vscode_uri3 = require("vscode-uri");
941
926
  var import_vscode_languageserver6 = require("vscode-languageserver");
942
927
  var import_vscode_languageserver_textdocument = require("vscode-languageserver-textdocument");
943
928
  var START_OF_FILE = import_vscode_languageserver6.Range.create(import_vscode_languageserver6.Position.create(0, 0), import_vscode_languageserver6.Position.create(0, 0));
944
929
  function createTextDocument(filename) {
945
- const uri = import_vscode_uri4.URI.file(filename).toString();
930
+ const uri = import_vscode_uri3.URI.file(filename).toString();
946
931
  const content = import_fs.default.readFileSync(filename, "utf-8");
947
932
  return import_vscode_languageserver_textdocument.TextDocument.create(uri, "plaintext", 0, content);
948
933
  }
@@ -979,12 +964,12 @@ function OpenTagName2({
979
964
  }
980
965
  }
981
966
  return [
982
- import_vscode_languageserver7.LocationLink.create(import_vscode_uri5.URI.file(tagEntryFile).toString(), range, range, parsed.locationAt(node))
967
+ import_vscode_languageserver7.LocationLink.create(import_vscode_uri4.URI.file(tagEntryFile).toString(), range, range, parsed.locationAt(node))
983
968
  ];
984
969
  }
985
970
 
986
971
  // src/service/marko/definition/AttrName.ts
987
- var import_vscode_uri6 = require("vscode-uri");
972
+ var import_vscode_uri5 = require("vscode-uri");
988
973
  var import_vscode_languageserver8 = require("vscode-languageserver");
989
974
  function AttrName2({
990
975
  lookup,
@@ -1013,7 +998,7 @@ function AttrName2({
1013
998
  }
1014
999
  }
1015
1000
  return [
1016
- import_vscode_languageserver8.LocationLink.create(import_vscode_uri6.URI.file(attrEntryFile).toString(), range, range, parsed.locationAt(node))
1001
+ import_vscode_languageserver8.LocationLink.create(import_vscode_uri5.URI.file(attrEntryFile).toString(), range, range, parsed.locationAt(node))
1017
1002
  ];
1018
1003
  }
1019
1004
 
@@ -1040,7 +1025,7 @@ var findDefinition = async (doc, params) => {
1040
1025
 
1041
1026
  // src/service/marko/format.ts
1042
1027
  var import_vscode_languageserver9 = require("vscode-languageserver");
1043
- var import_vscode_uri7 = require("vscode-uri");
1028
+ var import_vscode_uri6 = require("vscode-uri");
1044
1029
  var prettier = __toESM(require("prettier"));
1045
1030
  var markoPrettier = __toESM(require("prettier-plugin-marko"));
1046
1031
  var NO_EDIT = [
@@ -1048,7 +1033,7 @@ var NO_EDIT = [
1048
1033
  ];
1049
1034
  var format2 = async (doc, params, token) => {
1050
1035
  try {
1051
- const { fsPath, scheme } = import_vscode_uri7.URI.parse(doc.uri);
1036
+ const { fsPath, scheme } = import_vscode_uri6.URI.parse(doc.uri);
1052
1037
  const text = doc.getText();
1053
1038
  const options = {
1054
1039
  parser: "marko",
@@ -1462,8 +1447,9 @@ if (typeof require !== "undefined" && require.extensions && !(".ts" in require.e
1462
1447
  }
1463
1448
  var documents = new import_node.TextDocuments(import_vscode_languageserver_textdocument3.TextDocument);
1464
1449
  var connection2 = (0, import_node.createConnection)(import_node.ProposedFeatures.all);
1465
- var prevDiagnostics = /* @__PURE__ */ new WeakMap();
1466
- var diagnosticTimeouts = /* @__PURE__ */ new WeakMap();
1450
+ var prevDiags = /* @__PURE__ */ new WeakMap();
1451
+ var pendingDiags = /* @__PURE__ */ new WeakSet();
1452
+ var diagnosticTimeout;
1467
1453
  console.log = (...args) => {
1468
1454
  connection2.console.log(args.map((v) => (0, import_util2.inspect)(v)).join(" "));
1469
1455
  };
@@ -1473,8 +1459,7 @@ console.error = (...args) => {
1473
1459
  process.on("uncaughtException", console.error);
1474
1460
  process.on("unhandledRejection", console.error);
1475
1461
  connection2.onInitialize(() => {
1476
- setup2(connection2);
1477
- setup(connection2, documents);
1462
+ setup(connection2);
1478
1463
  return {
1479
1464
  capabilities: {
1480
1465
  textDocumentSync: import_node.TextDocumentSyncKind.Incremental,
@@ -1507,11 +1492,12 @@ connection2.onInitialize(() => {
1507
1492
  }
1508
1493
  };
1509
1494
  });
1510
- connection2.onInitialized(() => {
1511
- documents.all().forEach((doc) => queueValidation(doc));
1512
- });
1513
- documents.onDidChangeContent((change) => {
1514
- queueValidation(change.document);
1495
+ connection2.onDidChangeConfiguration(validateDocs);
1496
+ connection2.onDidChangeWatchedFiles(validateDocs);
1497
+ documents.onDidChangeContent(({ document }) => {
1498
+ queueDiagnostic();
1499
+ pendingDiags.add(document);
1500
+ clearCompilerCache(document);
1515
1501
  });
1516
1502
  connection2.onCompletion(async (params, cancel) => {
1517
1503
  return await service.doComplete(documents.get(params.textDocument.uri), params, cancel) || null;
@@ -1525,21 +1511,38 @@ connection2.onHover(async (params, cancel) => {
1525
1511
  connection2.onDocumentFormatting(async (params, cancel) => {
1526
1512
  return await service.format(documents.get(params.textDocument.uri), params, cancel) || null;
1527
1513
  });
1528
- function queueValidation(doc) {
1529
- clearTimeout(diagnosticTimeouts.get(doc));
1530
- const id = setTimeout(async () => {
1531
- const prevDiag = prevDiagnostics.get(doc);
1532
- const nextDiag = await service.doValidate(doc) || [];
1533
- if (diagnosticTimeouts.get(doc) !== id || prevDiag && (0, import_util2.isDeepStrictEqual)(prevDiag, nextDiag)) {
1534
- return;
1514
+ function validateDocs() {
1515
+ queueDiagnostic();
1516
+ clearCompilerCache();
1517
+ for (const doc of documents.all()) {
1518
+ pendingDiags.add(doc);
1519
+ }
1520
+ }
1521
+ function queueDiagnostic() {
1522
+ clearTimeout(diagnosticTimeout);
1523
+ const id = diagnosticTimeout = setTimeout(async () => {
1524
+ const results = await Promise.all(documents.all().map(async (doc) => {
1525
+ if (!pendingDiags.delete(doc))
1526
+ return;
1527
+ const prevDiag = prevDiags.get(doc) || [];
1528
+ const nextDiag = await service.doValidate(doc) || [];
1529
+ if ((0, import_util2.isDeepStrictEqual)(prevDiag, nextDiag))
1530
+ return;
1531
+ return [doc, nextDiag];
1532
+ }));
1533
+ if (id === diagnosticTimeout) {
1534
+ for (const result of results) {
1535
+ if (result) {
1536
+ const [doc, diag] = result;
1537
+ prevDiags.set(doc, diag);
1538
+ connection2.sendDiagnostics({
1539
+ uri: doc.uri,
1540
+ diagnostics: diag
1541
+ });
1542
+ }
1543
+ }
1535
1544
  }
1536
- prevDiagnostics.set(doc, nextDiag);
1537
- connection2.sendDiagnostics({
1538
- uri: doc.uri,
1539
- diagnostics: nextDiag
1540
- });
1541
1545
  }, 400);
1542
- diagnosticTimeouts.set(doc, id);
1543
1546
  }
1544
1547
  documents.listen(connection2);
1545
1548
  connection2.listen();