@marko/language-server 0.12.6 → 0.12.9

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.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 setup(connection3, documents2) {
562
- connection3.onDidChangeWatchedFiles(() => {
563
- clearAllCaches();
564
- });
565
- documents2.onDidChangeContent(({ document }) => {
566
- if (document.version > 1) {
567
- if (document.languageId === "marko") {
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 setup2(_) {
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 URI3 } from "vscode-uri";
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 = URI3.file(fileForTag).toString();
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
- output: "source",
891
+ translator,
908
892
  code: false,
909
- translator
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 URI5 } from "vscode-uri";
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 URI4 } from "vscode-uri";
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 = URI4.file(filename).toString();
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(URI5.file(tagEntryFile).toString(), range, range, parsed.locationAt(node))
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 URI6 } from "vscode-uri";
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(URI6.file(attrEntryFile).toString(), range, range, parsed.locationAt(node))
1015
+ LocationLink2.create(URI5.file(attrEntryFile).toString(), range, range, parsed.locationAt(node))
1031
1016
  ];
1032
1017
  }
1033
1018
 
@@ -1053,16 +1038,13 @@ var findDefinition = async (doc, params) => {
1053
1038
  };
1054
1039
 
1055
1040
  // src/service/marko/format.ts
1056
- import { Position as Position2, Range as Range6, TextEdit as TextEdit4 } from "vscode-languageserver";
1057
- import { URI as URI7 } from "vscode-uri";
1041
+ import { Range as Range6, TextEdit as TextEdit4 } from "vscode-languageserver";
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
- var NO_EDIT = [
1061
- TextEdit4.replace(Range6.create(Position2.create(0, 0), Position2.create(0, 0)), "")
1062
- ];
1063
- var format2 = async (doc, params, token) => {
1045
+ var format2 = async (doc, params, cancel) => {
1064
1046
  try {
1065
- const { fsPath, scheme } = URI7.parse(doc.uri);
1047
+ const { fsPath, scheme } = URI6.parse(doc.uri);
1066
1048
  const text = doc.getText();
1067
1049
  const options = {
1068
1050
  parser: "marko",
@@ -1074,15 +1056,14 @@ var format2 = async (doc, params, token) => {
1074
1056
  editorconfig: true
1075
1057
  }).catch(() => null) : null
1076
1058
  };
1077
- if (!token.isCancellationRequested) {
1078
- return [
1079
- TextEdit4.replace(Range6.create(doc.positionAt(0), doc.positionAt(text.length)), prettier.format(text, options))
1080
- ];
1081
- }
1059
+ if (cancel.isCancellationRequested)
1060
+ return;
1061
+ return [
1062
+ TextEdit4.replace(Range6.create(doc.positionAt(0), doc.positionAt(text.length)), prettier.format(text, options))
1063
+ ];
1082
1064
  } catch (e) {
1083
1065
  displayError(e);
1084
1066
  }
1085
- return NO_EDIT;
1086
1067
  };
1087
1068
 
1088
1069
  // src/service/marko/index.ts
@@ -1095,7 +1076,9 @@ var marko_default = {
1095
1076
 
1096
1077
  // src/service/stylesheet/index.ts
1097
1078
  import {
1098
- CompletionList as CompletionList2
1079
+ CompletionList as CompletionList2,
1080
+ Range as Range8,
1081
+ TextDocumentEdit
1099
1082
  } from "vscode-languageserver";
1100
1083
  import {
1101
1084
  getCSSLanguageService,
@@ -1164,7 +1147,7 @@ function createExtractor(code) {
1164
1147
  const generatedStart = generatedMap[key];
1165
1148
  const sourceStart = generatedMap[key + 1];
1166
1149
  const sourceEnd = generatedMap[key + 2];
1167
- return sourceEnd - sourceStart <= generatedOffset - generatedStart ? void 0 : sourceStart + (generatedOffset - generatedStart);
1150
+ return sourceEnd - sourceStart < generatedOffset - generatedStart ? void 0 : sourceStart + (generatedOffset - generatedStart);
1168
1151
  },
1169
1152
  generatedOffsetAt(sourceOffset) {
1170
1153
  let max = sourceMap.length / 3;
@@ -1204,10 +1187,20 @@ function extractStyleSheets(code, program, lookup) {
1204
1187
  }).replace(/^.*\./, "") : "css";
1205
1188
  };
1206
1189
  const visit = (node) => {
1207
- var _a, _b, _c;
1190
+ var _a, _b;
1208
1191
  switch (node.type) {
1209
1192
  case 1 /* Tag */:
1210
- if ((_a = node.body) == null ? void 0 : _a.length) {
1193
+ if (node.nameText === "style" && node.concise && node.attrs) {
1194
+ const block = node.attrs.at(-1);
1195
+ if (block.type === 8 /* AttrNamed */ && code[block.start] === "{") {
1196
+ getExtractor(getFileExtFromTag(node)).write`${{
1197
+ start: block.start + 1,
1198
+ end: block.end - 1
1199
+ }}`;
1200
+ break;
1201
+ }
1202
+ }
1203
+ if (node.body) {
1211
1204
  if (node.nameText === "style") {
1212
1205
  const ext = getFileExtFromTag(node);
1213
1206
  for (const child of node.body) {
@@ -1221,30 +1214,22 @@ function extractStyleSheets(code, program, lookup) {
1221
1214
  }
1222
1215
  }
1223
1216
  } else {
1224
- if (node.attrs) {
1225
- for (const attr of node.attrs) {
1226
- if (attr.type === 8 /* AttrNamed */ && ((_b = attr.value) == null ? void 0 : _b.type) === 11 /* AttrValue */ && /^['"]$/.test(code[attr.value.value.start])) {
1227
- const name = read(attr.name);
1228
- if (name === "#style" || name === "style" && lookup && node.nameText && name === "style" && ((_c = lookup.getTag(node.nameText)) == null ? void 0 : _c.html)) {
1229
- getExtractor("css").write`:root{${{
1230
- start: attr.value.value.start + 1,
1231
- end: attr.value.value.end - 1
1232
- }}}`;
1233
- }
1234
- }
1235
- }
1236
- }
1237
1217
  for (const child of node.body) {
1238
1218
  visit(child);
1239
1219
  }
1240
1220
  }
1241
- } else if (node.nameText === "style" && node.concise && node.attrs) {
1242
- const block = node.attrs.at(-1);
1243
- if (block.type === 8 /* AttrNamed */ && code[block.start] === "{") {
1244
- getExtractor(getFileExtFromTag(node)).write`${{
1245
- start: block.start + 1,
1246
- end: block.end - 1
1247
- }}`;
1221
+ }
1222
+ if (node.attrs) {
1223
+ for (const attr of node.attrs) {
1224
+ if (attr.type === 8 /* AttrNamed */ && ((_a = attr.value) == null ? void 0 : _a.type) === 11 /* AttrValue */ && /^['"]$/.test(code[attr.value.value.start])) {
1225
+ const name = read(attr.name);
1226
+ if (name === "#style" || name === "style" && lookup && node.nameText && name === "style" && ((_b = lookup.getTag(node.nameText)) == null ? void 0 : _b.html)) {
1227
+ getExtractor("css").write`:root{${{
1228
+ start: attr.value.value.start + 1,
1229
+ end: attr.value.value.end - 1
1230
+ }}}`;
1231
+ }
1232
+ }
1248
1233
  }
1249
1234
  }
1250
1235
  break;
@@ -1266,7 +1251,7 @@ var services = {
1266
1251
  less: getLESSLanguageService,
1267
1252
  scss: getSCSSLanguageService
1268
1253
  };
1269
- var stylesheet_default = {
1254
+ var StyleSheetService = {
1270
1255
  async doComplete(doc, params) {
1271
1256
  const infoByExt = getStyleSheetInfo(doc);
1272
1257
  const sourceOffset = doc.offsetAt(params.position);
@@ -1279,26 +1264,17 @@ var stylesheet_default = {
1279
1264
  const result = service2.doComplete(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed);
1280
1265
  for (const item of result.items) {
1281
1266
  if (item.additionalTextEdits) {
1282
- for (const edit of item.additionalTextEdits) {
1283
- if (!updateRange(doc, info, edit.range)) {
1284
- edit.newText = "";
1285
- edit.range = START_OF_FILE;
1286
- }
1267
+ for (const textEdit2 of item.additionalTextEdits) {
1268
+ updateTextEdit(doc, info, textEdit2);
1287
1269
  }
1288
1270
  }
1289
1271
  const { textEdit } = item;
1290
1272
  if (textEdit) {
1291
1273
  if (textEdit.range) {
1292
- if (!updateRange(doc, info, textEdit.range)) {
1293
- textEdit.newText = "";
1294
- textEdit.range = START_OF_FILE;
1295
- }
1274
+ updateTextEdit(doc, info, textEdit);
1296
1275
  }
1297
1276
  if (textEdit.insert) {
1298
- if (!updateRange(doc, info, textEdit.insert)) {
1299
- textEdit.newText = "";
1300
- textEdit.insert = START_OF_FILE;
1301
- }
1277
+ updateInsertReplaceEdit(doc, info, textEdit);
1302
1278
  }
1303
1279
  }
1304
1280
  }
@@ -1322,6 +1298,84 @@ var stylesheet_default = {
1322
1298
  break;
1323
1299
  }
1324
1300
  },
1301
+ async findReferences(doc, params) {
1302
+ const infoByExt = getStyleSheetInfo(doc);
1303
+ const sourceOffset = doc.offsetAt(params.position);
1304
+ for (const ext in infoByExt) {
1305
+ const info = infoByExt[ext];
1306
+ const generatedOffset = info.generatedOffsetAt(sourceOffset);
1307
+ if (generatedOffset === void 0)
1308
+ continue;
1309
+ const { service: service2, virtualDoc } = info;
1310
+ const result = [];
1311
+ for (const location of service2.findReferences(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed)) {
1312
+ if (updateRange(doc, info, location.range)) {
1313
+ result.push(location);
1314
+ }
1315
+ }
1316
+ return result.length ? result : void 0;
1317
+ }
1318
+ },
1319
+ async findDocumentHighlights(doc, params) {
1320
+ const infoByExt = getStyleSheetInfo(doc);
1321
+ const sourceOffset = doc.offsetAt(params.position);
1322
+ for (const ext in infoByExt) {
1323
+ const info = infoByExt[ext];
1324
+ const generatedOffset = info.generatedOffsetAt(sourceOffset);
1325
+ if (generatedOffset === void 0)
1326
+ continue;
1327
+ const { service: service2, virtualDoc } = info;
1328
+ const result = [];
1329
+ for (const highlight of service2.findDocumentHighlights(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed)) {
1330
+ if (updateRange(doc, info, highlight.range)) {
1331
+ result.push(highlight);
1332
+ }
1333
+ }
1334
+ return result.length ? result : void 0;
1335
+ }
1336
+ },
1337
+ async findDocumentColors(doc) {
1338
+ const infoByExt = getStyleSheetInfo(doc);
1339
+ const result = [];
1340
+ for (const ext in infoByExt) {
1341
+ const info = infoByExt[ext];
1342
+ const { service: service2, virtualDoc } = info;
1343
+ for (const colorInfo of service2.findDocumentColors(virtualDoc, info.parsed)) {
1344
+ if (updateRange(doc, info, colorInfo.range)) {
1345
+ result.push(colorInfo);
1346
+ }
1347
+ }
1348
+ }
1349
+ if (result.length) {
1350
+ return result;
1351
+ }
1352
+ },
1353
+ async getColorPresentations(doc, params) {
1354
+ const infoByExt = getStyleSheetInfo(doc);
1355
+ const sourceOffset = doc.offsetAt(params.range.start);
1356
+ for (const ext in infoByExt) {
1357
+ const info = infoByExt[ext];
1358
+ const generatedOffsetStart = info.generatedOffsetAt(sourceOffset);
1359
+ if (generatedOffsetStart === void 0)
1360
+ continue;
1361
+ const generatedOffsetEnd = info.generatedOffsetAt(doc.offsetAt(params.range.end));
1362
+ if (generatedOffsetEnd === void 0)
1363
+ continue;
1364
+ const { service: service2, virtualDoc } = info;
1365
+ const result = service2.getColorPresentations(virtualDoc, info.parsed, params.color, Range8.create(virtualDoc.positionAt(generatedOffsetStart), virtualDoc.positionAt(generatedOffsetEnd)));
1366
+ for (const colorPresentation of result) {
1367
+ if (colorPresentation.textEdit) {
1368
+ updateTextEdit(doc, info, colorPresentation.textEdit);
1369
+ }
1370
+ if (colorPresentation.additionalTextEdits) {
1371
+ for (const textEdit of colorPresentation.additionalTextEdits) {
1372
+ updateTextEdit(doc, info, textEdit);
1373
+ }
1374
+ }
1375
+ }
1376
+ return result;
1377
+ }
1378
+ },
1325
1379
  async doHover(doc, params) {
1326
1380
  const infoByExt = getStyleSheetInfo(doc);
1327
1381
  const sourceOffset = doc.offsetAt(params.position);
@@ -1331,12 +1385,72 @@ var stylesheet_default = {
1331
1385
  if (generatedOffset === void 0)
1332
1386
  continue;
1333
1387
  const { service: service2, virtualDoc } = info;
1334
- const result = service2.doHover(virtualDoc, virtualDoc.positionAt(generatedOffset), service2.parseStylesheet(virtualDoc));
1388
+ const result = service2.doHover(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed);
1335
1389
  if (result && (!result.range || updateRange(doc, info, result.range))) {
1336
1390
  return result;
1337
1391
  }
1338
1392
  }
1339
1393
  },
1394
+ async doRename(doc, params) {
1395
+ const infoByExt = getStyleSheetInfo(doc);
1396
+ const sourceOffset = doc.offsetAt(params.position);
1397
+ for (const ext in infoByExt) {
1398
+ const info = infoByExt[ext];
1399
+ const generatedOffset = info.generatedOffsetAt(sourceOffset);
1400
+ if (generatedOffset === void 0)
1401
+ continue;
1402
+ const { service: service2, virtualDoc } = info;
1403
+ const result = service2.doRename(virtualDoc, virtualDoc.positionAt(generatedOffset), params.newName, info.parsed);
1404
+ if (result.changes) {
1405
+ for (const uri in result.changes) {
1406
+ if (uri === doc.uri) {
1407
+ for (const textEdit of result.changes[uri]) {
1408
+ updateTextEdit(doc, info, textEdit);
1409
+ }
1410
+ }
1411
+ }
1412
+ }
1413
+ if (result.documentChanges) {
1414
+ for (const change of result.documentChanges) {
1415
+ if (TextDocumentEdit.is(change)) {
1416
+ if (change.textDocument.uri === doc.uri) {
1417
+ for (const textEdit of change.edits) {
1418
+ updateTextEdit(doc, info, textEdit);
1419
+ }
1420
+ }
1421
+ }
1422
+ }
1423
+ }
1424
+ return result;
1425
+ }
1426
+ },
1427
+ async doCodeActions(doc, params) {
1428
+ var _a;
1429
+ const infoByExt = getStyleSheetInfo(doc);
1430
+ const sourceOffset = doc.offsetAt(params.range.start);
1431
+ for (const ext in infoByExt) {
1432
+ const info = infoByExt[ext];
1433
+ const generatedOffsetStart = info.generatedOffsetAt(sourceOffset);
1434
+ if (generatedOffsetStart === void 0)
1435
+ continue;
1436
+ const generatedOffsetEnd = info.generatedOffsetAt(doc.offsetAt(params.range.end));
1437
+ if (generatedOffsetEnd === void 0)
1438
+ continue;
1439
+ const { service: service2, virtualDoc } = info;
1440
+ const result = service2.doCodeActions(virtualDoc, Range8.create(virtualDoc.positionAt(generatedOffsetStart), virtualDoc.positionAt(generatedOffsetEnd)), params.context, info.parsed);
1441
+ if (result) {
1442
+ for (const command of result) {
1443
+ const edits = (_a = command.arguments) == null ? void 0 : _a[2];
1444
+ if (edits) {
1445
+ for (const textEdit of edits) {
1446
+ updateTextEdit(doc, info, textEdit);
1447
+ }
1448
+ }
1449
+ }
1450
+ return result;
1451
+ }
1452
+ }
1453
+ },
1340
1454
  async doValidate(doc) {
1341
1455
  const infoByExt = getStyleSheetInfo(doc);
1342
1456
  const result = [];
@@ -1351,6 +1465,18 @@ var stylesheet_default = {
1351
1465
  return result;
1352
1466
  }
1353
1467
  };
1468
+ function updateTextEdit(doc, info, textEdit) {
1469
+ if (!updateRange(doc, info, textEdit.range)) {
1470
+ textEdit.newText = "";
1471
+ textEdit.range = START_OF_FILE;
1472
+ }
1473
+ }
1474
+ function updateInsertReplaceEdit(doc, info, insertReplaceEdit) {
1475
+ if (!updateRange(doc, info, insertReplaceEdit.insert)) {
1476
+ insertReplaceEdit.newText = "";
1477
+ insertReplaceEdit.insert = START_OF_FILE;
1478
+ }
1479
+ }
1354
1480
  function updateRange(doc, info, range) {
1355
1481
  const start = info.sourceOffsetAt(info.virtualDoc.offsetAt(range.start));
1356
1482
  const end = info.sourceOffsetAt(info.virtualDoc.offsetAt(range.end));
@@ -1388,7 +1514,7 @@ function getStyleSheetInfo(doc) {
1388
1514
  }
1389
1515
 
1390
1516
  // src/service/index.ts
1391
- var plugins = [marko_default, stylesheet_default];
1517
+ var plugins = [marko_default, StyleSheetService];
1392
1518
  var service = {
1393
1519
  async doComplete(doc, params, cancel) {
1394
1520
  const result = CompletionList3.create([], false);
@@ -1400,7 +1526,7 @@ var service = {
1400
1526
  for (const pending of requests) {
1401
1527
  const cur = await pending;
1402
1528
  if (cancel.isCancellationRequested)
1403
- break;
1529
+ return;
1404
1530
  if (cur) {
1405
1531
  let items;
1406
1532
  if (Array.isArray(cur)) {
@@ -1428,7 +1554,7 @@ var service = {
1428
1554
  for (const pending of requests) {
1429
1555
  const cur = await pending;
1430
1556
  if (cancel.isCancellationRequested)
1431
- break;
1557
+ return;
1432
1558
  if (cur) {
1433
1559
  if (Array.isArray(cur)) {
1434
1560
  result.push(...cur);
@@ -1442,6 +1568,102 @@ var service = {
1442
1568
  }
1443
1569
  return result;
1444
1570
  },
1571
+ async findReferences(doc, params, cancel) {
1572
+ let result;
1573
+ try {
1574
+ const requests = plugins.map((plugin) => {
1575
+ var _a;
1576
+ return (_a = plugin.findReferences) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1577
+ });
1578
+ for (const pending of requests) {
1579
+ const cur = await pending;
1580
+ if (cancel.isCancellationRequested)
1581
+ return;
1582
+ if (cur) {
1583
+ if (result) {
1584
+ result.push(...cur);
1585
+ } else {
1586
+ result = cur;
1587
+ }
1588
+ }
1589
+ }
1590
+ } catch (err) {
1591
+ displayError(err);
1592
+ }
1593
+ return result;
1594
+ },
1595
+ async findDocumentHighlights(doc, params, cancel) {
1596
+ let result;
1597
+ try {
1598
+ const requests = plugins.map((plugin) => {
1599
+ var _a;
1600
+ return (_a = plugin.findDocumentHighlights) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1601
+ });
1602
+ for (const pending of requests) {
1603
+ const cur = await pending;
1604
+ if (cancel.isCancellationRequested)
1605
+ return;
1606
+ if (cur) {
1607
+ if (result) {
1608
+ result.push(...cur);
1609
+ } else {
1610
+ result = cur;
1611
+ }
1612
+ }
1613
+ }
1614
+ } catch (err) {
1615
+ displayError(err);
1616
+ }
1617
+ return result;
1618
+ },
1619
+ async findDocumentColors(doc, params, cancel) {
1620
+ let result;
1621
+ try {
1622
+ const requests = plugins.map((plugin) => {
1623
+ var _a;
1624
+ return (_a = plugin.findDocumentColors) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1625
+ });
1626
+ for (const pending of requests) {
1627
+ const cur = await pending;
1628
+ if (cancel.isCancellationRequested)
1629
+ return;
1630
+ if (cur) {
1631
+ if (result) {
1632
+ result.push(...cur);
1633
+ } else {
1634
+ result = cur;
1635
+ }
1636
+ }
1637
+ }
1638
+ } catch (err) {
1639
+ displayError(err);
1640
+ }
1641
+ return result;
1642
+ },
1643
+ async getColorPresentations(doc, params, cancel) {
1644
+ let result;
1645
+ try {
1646
+ const requests = plugins.map((plugin) => {
1647
+ var _a;
1648
+ return (_a = plugin.getColorPresentations) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1649
+ });
1650
+ for (const pending of requests) {
1651
+ const cur = await pending;
1652
+ if (cancel.isCancellationRequested)
1653
+ return;
1654
+ if (cur) {
1655
+ if (result) {
1656
+ result.push(...cur);
1657
+ } else {
1658
+ result = cur;
1659
+ }
1660
+ }
1661
+ }
1662
+ } catch (err) {
1663
+ displayError(err);
1664
+ }
1665
+ return result;
1666
+ },
1445
1667
  async doHover(doc, params, cancel) {
1446
1668
  var _a;
1447
1669
  try {
@@ -1456,6 +1678,80 @@ var service = {
1456
1678
  displayError(err);
1457
1679
  }
1458
1680
  },
1681
+ async doRename(doc, params, cancel) {
1682
+ let changes;
1683
+ let changeAnnotations;
1684
+ let documentChanges;
1685
+ try {
1686
+ const requests = plugins.map((plugin) => {
1687
+ var _a;
1688
+ return (_a = plugin.doRename) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1689
+ });
1690
+ for (const pending of requests) {
1691
+ const cur = await pending;
1692
+ if (cancel.isCancellationRequested)
1693
+ return;
1694
+ if (cur) {
1695
+ if (cur.changes) {
1696
+ if (changes) {
1697
+ for (const uri in cur.changes) {
1698
+ if (changes[uri]) {
1699
+ changes[uri].push(...cur.changes[uri]);
1700
+ } else {
1701
+ changes[uri] = cur.changes[uri];
1702
+ }
1703
+ }
1704
+ } else {
1705
+ changes = cur.changes;
1706
+ }
1707
+ }
1708
+ if (cur.changeAnnotations) {
1709
+ if (changeAnnotations) {
1710
+ Object.assign(changeAnnotations, cur.changeAnnotations);
1711
+ } else {
1712
+ changeAnnotations = cur.changeAnnotations;
1713
+ }
1714
+ }
1715
+ if (cur.documentChanges) {
1716
+ if (documentChanges) {
1717
+ documentChanges.push(...cur.documentChanges);
1718
+ } else {
1719
+ documentChanges = cur.documentChanges;
1720
+ }
1721
+ }
1722
+ }
1723
+ }
1724
+ } catch (err) {
1725
+ displayError(err);
1726
+ }
1727
+ if (changes || changeAnnotations || documentChanges) {
1728
+ return {
1729
+ changes,
1730
+ changeAnnotations,
1731
+ documentChanges
1732
+ };
1733
+ }
1734
+ },
1735
+ async doCodeActions(doc, params, cancel) {
1736
+ const result = [];
1737
+ try {
1738
+ const requests = plugins.map((plugin) => {
1739
+ var _a;
1740
+ return (_a = plugin.doCodeActions) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1741
+ });
1742
+ for (const pending of requests) {
1743
+ const cur = await pending;
1744
+ if (cancel.isCancellationRequested)
1745
+ return;
1746
+ if (cur) {
1747
+ result.push(...cur);
1748
+ }
1749
+ }
1750
+ } catch (err) {
1751
+ displayError(err);
1752
+ }
1753
+ return result;
1754
+ },
1459
1755
  async doValidate(doc) {
1460
1756
  const result = [];
1461
1757
  try {
@@ -1482,8 +1778,9 @@ if (typeof __require !== "undefined" && __require.extensions && !(".ts" in __req
1482
1778
  }
1483
1779
  var documents = new TextDocuments(TextDocument3);
1484
1780
  var connection2 = createConnection(ProposedFeatures.all);
1485
- var prevDiagnostics = /* @__PURE__ */ new WeakMap();
1486
- var diagnosticTimeouts = /* @__PURE__ */ new WeakMap();
1781
+ var prevDiags = /* @__PURE__ */ new WeakMap();
1782
+ var pendingDiags = /* @__PURE__ */ new WeakSet();
1783
+ var diagnosticTimeout;
1487
1784
  console.log = (...args) => {
1488
1785
  connection2.console.log(args.map((v) => inspect2(v)).join(" "));
1489
1786
  };
@@ -1493,14 +1790,18 @@ console.error = (...args) => {
1493
1790
  process.on("uncaughtException", console.error);
1494
1791
  process.on("unhandledRejection", console.error);
1495
1792
  connection2.onInitialize(() => {
1496
- setup2(connection2);
1497
- setup(connection2, documents);
1793
+ setup(connection2);
1498
1794
  return {
1499
1795
  capabilities: {
1500
1796
  textDocumentSync: TextDocumentSyncKind.Incremental,
1501
1797
  documentFormattingProvider: true,
1502
1798
  definitionProvider: true,
1503
1799
  hoverProvider: true,
1800
+ renameProvider: true,
1801
+ codeActionProvider: true,
1802
+ referencesProvider: true,
1803
+ colorProvider: true,
1804
+ documentHighlightProvider: true,
1504
1805
  completionProvider: {
1505
1806
  triggerCharacters: [
1506
1807
  ".",
@@ -1527,11 +1828,12 @@ connection2.onInitialize(() => {
1527
1828
  }
1528
1829
  };
1529
1830
  });
1530
- connection2.onInitialized(() => {
1531
- documents.all().forEach((doc) => queueValidation(doc));
1532
- });
1533
- documents.onDidChangeContent((change) => {
1534
- queueValidation(change.document);
1831
+ connection2.onDidChangeConfiguration(validateDocs);
1832
+ connection2.onDidChangeWatchedFiles(validateDocs);
1833
+ documents.onDidChangeContent(({ document }) => {
1834
+ queueDiagnostic();
1835
+ pendingDiags.add(document);
1836
+ clearCompilerCache(document);
1535
1837
  });
1536
1838
  connection2.onCompletion(async (params, cancel) => {
1537
1839
  return await service.doComplete(documents.get(params.textDocument.uri), params, cancel) || null;
@@ -1539,27 +1841,62 @@ connection2.onCompletion(async (params, cancel) => {
1539
1841
  connection2.onDefinition(async (params, cancel) => {
1540
1842
  return await service.findDefinition(documents.get(params.textDocument.uri), params, cancel) || null;
1541
1843
  });
1844
+ connection2.onReferences(async (params, cancel) => {
1845
+ return await service.findReferences(documents.get(params.textDocument.uri), params, cancel) || null;
1846
+ });
1847
+ connection2.onDocumentHighlight(async (params, cancel) => {
1848
+ return await service.findDocumentHighlights(documents.get(params.textDocument.uri), params, cancel) || null;
1849
+ });
1850
+ connection2.onDocumentColor(async (params, cancel) => {
1851
+ return await service.findDocumentColors(documents.get(params.textDocument.uri), params, cancel) || null;
1852
+ });
1853
+ connection2.onColorPresentation(async (params, cancel) => {
1854
+ return await service.getColorPresentations(documents.get(params.textDocument.uri), params, cancel) || null;
1855
+ });
1542
1856
  connection2.onHover(async (params, cancel) => {
1543
1857
  return await service.doHover(documents.get(params.textDocument.uri), params, cancel) || null;
1544
1858
  });
1859
+ connection2.onRenameRequest(async (params, cancel) => {
1860
+ return await service.doRename(documents.get(params.textDocument.uri), params, cancel) || null;
1861
+ });
1862
+ connection2.onCodeAction(async (params, cancel) => {
1863
+ return await service.doCodeActions(documents.get(params.textDocument.uri), params, cancel) || null;
1864
+ });
1545
1865
  connection2.onDocumentFormatting(async (params, cancel) => {
1546
1866
  return await service.format(documents.get(params.textDocument.uri), params, cancel) || null;
1547
1867
  });
1548
- function queueValidation(doc) {
1549
- clearTimeout(diagnosticTimeouts.get(doc));
1550
- const id = setTimeout(async () => {
1551
- const prevDiag = prevDiagnostics.get(doc);
1552
- const nextDiag = await service.doValidate(doc) || [];
1553
- if (diagnosticTimeouts.get(doc) !== id || prevDiag && isDeepStrictEqual(prevDiag, nextDiag)) {
1554
- return;
1868
+ function validateDocs() {
1869
+ queueDiagnostic();
1870
+ clearCompilerCache();
1871
+ for (const doc of documents.all()) {
1872
+ pendingDiags.add(doc);
1873
+ }
1874
+ }
1875
+ function queueDiagnostic() {
1876
+ clearTimeout(diagnosticTimeout);
1877
+ const id = diagnosticTimeout = setTimeout(async () => {
1878
+ const results = await Promise.all(documents.all().map(async (doc) => {
1879
+ if (!pendingDiags.delete(doc))
1880
+ return;
1881
+ const prevDiag = prevDiags.get(doc) || [];
1882
+ const nextDiag = await service.doValidate(doc) || [];
1883
+ if (isDeepStrictEqual(prevDiag, nextDiag))
1884
+ return;
1885
+ return [doc, nextDiag];
1886
+ }));
1887
+ if (id === diagnosticTimeout) {
1888
+ for (const result of results) {
1889
+ if (result) {
1890
+ const [doc, diag] = result;
1891
+ prevDiags.set(doc, diag);
1892
+ connection2.sendDiagnostics({
1893
+ uri: doc.uri,
1894
+ diagnostics: diag
1895
+ });
1896
+ }
1897
+ }
1555
1898
  }
1556
- prevDiagnostics.set(doc, nextDiag);
1557
- connection2.sendDiagnostics({
1558
- uri: doc.uri,
1559
- diagnostics: nextDiag
1560
- });
1561
1899
  }, 400);
1562
- diagnosticTimeouts.set(doc, id);
1563
1900
  }
1564
1901
  documents.listen(connection2);
1565
1902
  connection2.listen();