@marko/language-server 0.12.5 → 0.12.8

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
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
2
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
3
  }) : x)(function(x) {
@@ -18,7 +17,6 @@ import { TextDocument as TextDocument3 } from "vscode-languageserver-textdocumen
18
17
  import { inspect as inspect2, isDeepStrictEqual } from "util";
19
18
 
20
19
  // src/utils/compiler.ts
21
- import { URI as URI2 } from "vscode-uri";
22
20
  import resolveFrom from "resolve-from";
23
21
  import lassoPackageRoot from "lasso-package-root";
24
22
  import * as builtinCompiler from "@marko/compiler";
@@ -559,29 +557,14 @@ function getCompilerInfo(doc) {
559
557
  }
560
558
  return info;
561
559
  }
562
- function setup(connection3, documents2) {
563
- connection3.onDidChangeWatchedFiles(() => {
564
- clearAllCaches();
565
- });
566
- documents2.onDidChangeContent(({ document }) => {
567
- if (document.version > 1) {
568
- if (document.languageId === "marko") {
569
- getCompilerInfo(document).cache.delete(document);
570
- } else if (/[./\\]marko(?:-tag)?\.json$/.test(document.uri)) {
571
- clearAllCaches();
572
- }
573
- }
574
- });
575
- documents2.onDidClose(({ document }) => {
576
- if (document.languageId === "marko" && URI2.parse(document.uri).scheme !== "file") {
577
- 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();
578
567
  }
579
- });
580
- }
581
- function clearAllCaches() {
582
- for (const [, info] of compilerInfoByDir) {
583
- info.cache.clear();
584
- info.compiler.taglib.clearCaches();
585
568
  }
586
569
  }
587
570
  function loadCompilerInfo(dir) {
@@ -626,7 +609,7 @@ function loadCompilerInfo(dir) {
626
609
  // src/utils/messages.ts
627
610
  import { inspect } from "util";
628
611
  var connection;
629
- function setup2(_) {
612
+ function setup(_) {
630
613
  connection = _;
631
614
  }
632
615
  function displayError(data) {
@@ -693,7 +676,7 @@ ${closingTagStr}`
693
676
 
694
677
  // src/service/marko/complete/OpenTagName.ts
695
678
  import path2 from "path";
696
- import { URI as URI3 } from "vscode-uri";
679
+ import { URI as URI2 } from "vscode-uri";
697
680
  import {
698
681
  CompletionItemKind as CompletionItemKind2,
699
682
  InsertTextFormat as InsertTextFormat2,
@@ -722,7 +705,7 @@ function OpenTagName({
722
705
  return tags.filter((it) => !it.deprecated).filter((it) => it.name !== "*").filter((it) => /^[^_]/.test(it.name) || !/\/node_modules\//.test(it.filePath)).map((it) => {
723
706
  let label = it.isNestedTag ? `@${it.name}` : it.name;
724
707
  const fileForTag = it.template || it.renderer || it.filePath;
725
- const fileURIForTag = URI3.file(fileForTag).toString();
708
+ const fileURIForTag = URI2.file(fileForTag).toString();
726
709
  const nodeModuleMatch = /\/node_modules\/((?:@[^/]+\/)?[^/]+)/.exec(fileForTag);
727
710
  const nodeModuleName = nodeModuleMatch && nodeModuleMatch[1];
728
711
  const isCoreTag = nodeModuleName === "marko";
@@ -905,9 +888,10 @@ var doValidate = (doc) => {
905
888
  try {
906
889
  compiler.compileSync(doc.getText(), fsPath || "untitled.marko", {
907
890
  cache: cache2,
908
- output: "source",
891
+ translator,
909
892
  code: false,
910
- translator
893
+ output: "source",
894
+ sourceMaps: false
911
895
  });
912
896
  } catch (e) {
913
897
  let match;
@@ -923,7 +907,7 @@ var doValidate = (doc) => {
923
907
 
924
908
  // src/service/marko/definition/OpenTagName.ts
925
909
  import path3 from "path";
926
- import { URI as URI5 } from "vscode-uri";
910
+ import { URI as URI4 } from "vscode-uri";
927
911
  import { Range as Range4, LocationLink } from "vscode-languageserver";
928
912
 
929
913
  // src/utils/regexp-builder.ts
@@ -952,12 +936,12 @@ function escape(val) {
952
936
 
953
937
  // src/utils/utils.ts
954
938
  import fs from "fs";
955
- import { URI as URI4 } from "vscode-uri";
939
+ import { URI as URI3 } from "vscode-uri";
956
940
  import { Position, Range as Range3 } from "vscode-languageserver";
957
941
  import { TextDocument } from "vscode-languageserver-textdocument";
958
942
  var START_OF_FILE = Range3.create(Position.create(0, 0), Position.create(0, 0));
959
943
  function createTextDocument(filename) {
960
- const uri = URI4.file(filename).toString();
944
+ const uri = URI3.file(filename).toString();
961
945
  const content = fs.readFileSync(filename, "utf-8");
962
946
  return TextDocument.create(uri, "plaintext", 0, content);
963
947
  }
@@ -994,12 +978,12 @@ function OpenTagName2({
994
978
  }
995
979
  }
996
980
  return [
997
- LocationLink.create(URI5.file(tagEntryFile).toString(), range, range, parsed.locationAt(node))
981
+ LocationLink.create(URI4.file(tagEntryFile).toString(), range, range, parsed.locationAt(node))
998
982
  ];
999
983
  }
1000
984
 
1001
985
  // src/service/marko/definition/AttrName.ts
1002
- import { URI as URI6 } from "vscode-uri";
986
+ import { URI as URI5 } from "vscode-uri";
1003
987
  import { Range as Range5, LocationLink as LocationLink2 } from "vscode-languageserver";
1004
988
  function AttrName2({
1005
989
  lookup,
@@ -1028,7 +1012,7 @@ function AttrName2({
1028
1012
  }
1029
1013
  }
1030
1014
  return [
1031
- LocationLink2.create(URI6.file(attrEntryFile).toString(), range, range, parsed.locationAt(node))
1015
+ LocationLink2.create(URI5.file(attrEntryFile).toString(), range, range, parsed.locationAt(node))
1032
1016
  ];
1033
1017
  }
1034
1018
 
@@ -1054,16 +1038,13 @@ var findDefinition = async (doc, params) => {
1054
1038
  };
1055
1039
 
1056
1040
  // src/service/marko/format.ts
1057
- import { Position as Position2, Range as Range6, TextEdit as TextEdit4 } from "vscode-languageserver";
1058
- 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";
1059
1043
  import * as prettier from "prettier";
1060
1044
  import * as markoPrettier from "prettier-plugin-marko";
1061
- var NO_EDIT = [
1062
- TextEdit4.replace(Range6.create(Position2.create(0, 0), Position2.create(0, 0)), "")
1063
- ];
1064
- var format2 = async (doc, params, token) => {
1045
+ var format2 = async (doc, params, cancel) => {
1065
1046
  try {
1066
- const { fsPath, scheme } = URI7.parse(doc.uri);
1047
+ const { fsPath, scheme } = URI6.parse(doc.uri);
1067
1048
  const text = doc.getText();
1068
1049
  const options = {
1069
1050
  parser: "marko",
@@ -1075,15 +1056,14 @@ var format2 = async (doc, params, token) => {
1075
1056
  editorconfig: true
1076
1057
  }).catch(() => null) : null
1077
1058
  };
1078
- if (!token.isCancellationRequested) {
1079
- return [
1080
- TextEdit4.replace(Range6.create(doc.positionAt(0), doc.positionAt(text.length)), prettier.format(text, options))
1081
- ];
1082
- }
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
+ ];
1083
1064
  } catch (e) {
1084
1065
  displayError(e);
1085
1066
  }
1086
- return NO_EDIT;
1087
1067
  };
1088
1068
 
1089
1069
  // src/service/marko/index.ts
@@ -1096,7 +1076,9 @@ var marko_default = {
1096
1076
 
1097
1077
  // src/service/stylesheet/index.ts
1098
1078
  import {
1099
- CompletionList as CompletionList2
1079
+ CompletionList as CompletionList2,
1080
+ Range as Range8,
1081
+ TextDocumentEdit
1100
1082
  } from "vscode-languageserver";
1101
1083
  import {
1102
1084
  getCSSLanguageService,
@@ -1165,7 +1147,7 @@ function createExtractor(code) {
1165
1147
  const generatedStart = generatedMap[key];
1166
1148
  const sourceStart = generatedMap[key + 1];
1167
1149
  const sourceEnd = generatedMap[key + 2];
1168
- return sourceEnd - sourceStart <= generatedOffset - generatedStart ? void 0 : sourceStart + (generatedOffset - generatedStart);
1150
+ return sourceEnd - sourceStart < generatedOffset - generatedStart ? void 0 : sourceStart + (generatedOffset - generatedStart);
1169
1151
  },
1170
1152
  generatedOffsetAt(sourceOffset) {
1171
1153
  let max = sourceMap.length / 3;
@@ -1205,10 +1187,20 @@ function extractStyleSheets(code, program, lookup) {
1205
1187
  }).replace(/^.*\./, "") : "css";
1206
1188
  };
1207
1189
  const visit = (node) => {
1208
- var _a, _b, _c;
1190
+ var _a, _b;
1209
1191
  switch (node.type) {
1210
1192
  case 1 /* Tag */:
1211
- 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) {
1212
1204
  if (node.nameText === "style") {
1213
1205
  const ext = getFileExtFromTag(node);
1214
1206
  for (const child of node.body) {
@@ -1222,30 +1214,22 @@ function extractStyleSheets(code, program, lookup) {
1222
1214
  }
1223
1215
  }
1224
1216
  } else {
1225
- if (node.attrs) {
1226
- for (const attr of node.attrs) {
1227
- if (attr.type === 8 /* AttrNamed */ && ((_b = attr.value) == null ? void 0 : _b.type) === 11 /* AttrValue */ && /^['"]$/.test(code[attr.value.value.start])) {
1228
- const name = read(attr.name);
1229
- if (name === "#style" || name === "style" && lookup && node.nameText && name === "style" && ((_c = lookup.getTag(node.nameText)) == null ? void 0 : _c.html)) {
1230
- getExtractor("css").write`:root{${{
1231
- start: attr.value.value.start + 1,
1232
- end: attr.value.value.end - 1
1233
- }}}`;
1234
- }
1235
- }
1236
- }
1237
- }
1238
1217
  for (const child of node.body) {
1239
1218
  visit(child);
1240
1219
  }
1241
1220
  }
1242
- } else if (node.nameText === "style" && node.concise && node.attrs) {
1243
- const block = node.attrs.at(-1);
1244
- if (block.type === 8 /* AttrNamed */ && code[block.start] === "{") {
1245
- getExtractor(getFileExtFromTag(node)).write`${{
1246
- start: block.start + 1,
1247
- end: block.end - 1
1248
- }}`;
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
+ }
1249
1233
  }
1250
1234
  }
1251
1235
  break;
@@ -1267,7 +1251,7 @@ var services = {
1267
1251
  less: getLESSLanguageService,
1268
1252
  scss: getSCSSLanguageService
1269
1253
  };
1270
- var stylesheet_default = {
1254
+ var StyleSheetService = {
1271
1255
  async doComplete(doc, params) {
1272
1256
  const infoByExt = getStyleSheetInfo(doc);
1273
1257
  const sourceOffset = doc.offsetAt(params.position);
@@ -1280,26 +1264,17 @@ var stylesheet_default = {
1280
1264
  const result = service2.doComplete(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed);
1281
1265
  for (const item of result.items) {
1282
1266
  if (item.additionalTextEdits) {
1283
- for (const edit of item.additionalTextEdits) {
1284
- if (!updateRange(doc, info, edit.range)) {
1285
- edit.newText = "";
1286
- edit.range = START_OF_FILE;
1287
- }
1267
+ for (const textEdit2 of item.additionalTextEdits) {
1268
+ updateTextEdit(doc, info, textEdit2);
1288
1269
  }
1289
1270
  }
1290
1271
  const { textEdit } = item;
1291
1272
  if (textEdit) {
1292
1273
  if (textEdit.range) {
1293
- if (!updateRange(doc, info, textEdit.range)) {
1294
- textEdit.newText = "";
1295
- textEdit.range = START_OF_FILE;
1296
- }
1274
+ updateTextEdit(doc, info, textEdit);
1297
1275
  }
1298
1276
  if (textEdit.insert) {
1299
- if (!updateRange(doc, info, textEdit.insert)) {
1300
- textEdit.newText = "";
1301
- textEdit.insert = START_OF_FILE;
1302
- }
1277
+ updateInsertReplaceEdit(doc, info, textEdit);
1303
1278
  }
1304
1279
  }
1305
1280
  }
@@ -1323,6 +1298,48 @@ var stylesheet_default = {
1323
1298
  break;
1324
1299
  }
1325
1300
  },
1301
+ async findDocumentColors(doc) {
1302
+ const infoByExt = getStyleSheetInfo(doc);
1303
+ const result = [];
1304
+ for (const ext in infoByExt) {
1305
+ const info = infoByExt[ext];
1306
+ const { service: service2, virtualDoc } = info;
1307
+ for (const colorInfo of service2.findDocumentColors(virtualDoc, info.parsed)) {
1308
+ if (updateRange(doc, info, colorInfo.range)) {
1309
+ result.push(colorInfo);
1310
+ }
1311
+ }
1312
+ }
1313
+ if (result.length) {
1314
+ return result;
1315
+ }
1316
+ },
1317
+ async getColorPresentations(doc, params) {
1318
+ const infoByExt = getStyleSheetInfo(doc);
1319
+ const sourceOffset = doc.offsetAt(params.range.start);
1320
+ for (const ext in infoByExt) {
1321
+ const info = infoByExt[ext];
1322
+ const generatedOffsetStart = info.generatedOffsetAt(sourceOffset);
1323
+ if (generatedOffsetStart === void 0)
1324
+ continue;
1325
+ const generatedOffsetEnd = info.generatedOffsetAt(doc.offsetAt(params.range.end));
1326
+ if (generatedOffsetEnd === void 0)
1327
+ continue;
1328
+ const { service: service2, virtualDoc } = info;
1329
+ const result = service2.getColorPresentations(virtualDoc, info.parsed, params.color, Range8.create(virtualDoc.positionAt(generatedOffsetStart), virtualDoc.positionAt(generatedOffsetEnd)));
1330
+ for (const colorPresentation of result) {
1331
+ if (colorPresentation.textEdit) {
1332
+ updateTextEdit(doc, info, colorPresentation.textEdit);
1333
+ }
1334
+ if (colorPresentation.additionalTextEdits) {
1335
+ for (const textEdit of colorPresentation.additionalTextEdits) {
1336
+ updateTextEdit(doc, info, textEdit);
1337
+ }
1338
+ }
1339
+ }
1340
+ return result;
1341
+ }
1342
+ },
1326
1343
  async doHover(doc, params) {
1327
1344
  const infoByExt = getStyleSheetInfo(doc);
1328
1345
  const sourceOffset = doc.offsetAt(params.position);
@@ -1332,12 +1349,72 @@ var stylesheet_default = {
1332
1349
  if (generatedOffset === void 0)
1333
1350
  continue;
1334
1351
  const { service: service2, virtualDoc } = info;
1335
- const result = service2.doHover(virtualDoc, virtualDoc.positionAt(generatedOffset), service2.parseStylesheet(virtualDoc));
1352
+ const result = service2.doHover(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed);
1336
1353
  if (result && (!result.range || updateRange(doc, info, result.range))) {
1337
1354
  return result;
1338
1355
  }
1339
1356
  }
1340
1357
  },
1358
+ async doRename(doc, params) {
1359
+ const infoByExt = getStyleSheetInfo(doc);
1360
+ const sourceOffset = doc.offsetAt(params.position);
1361
+ for (const ext in infoByExt) {
1362
+ const info = infoByExt[ext];
1363
+ const generatedOffset = info.generatedOffsetAt(sourceOffset);
1364
+ if (generatedOffset === void 0)
1365
+ continue;
1366
+ const { service: service2, virtualDoc } = info;
1367
+ const result = service2.doRename(virtualDoc, virtualDoc.positionAt(generatedOffset), params.newName, info.parsed);
1368
+ if (result.changes) {
1369
+ for (const uri in result.changes) {
1370
+ if (uri === doc.uri) {
1371
+ for (const textEdit of result.changes[uri]) {
1372
+ updateTextEdit(doc, info, textEdit);
1373
+ }
1374
+ }
1375
+ }
1376
+ }
1377
+ if (result.documentChanges) {
1378
+ for (const change of result.documentChanges) {
1379
+ if (TextDocumentEdit.is(change)) {
1380
+ if (change.textDocument.uri === doc.uri) {
1381
+ for (const textEdit of change.edits) {
1382
+ updateTextEdit(doc, info, textEdit);
1383
+ }
1384
+ }
1385
+ }
1386
+ }
1387
+ }
1388
+ return result;
1389
+ }
1390
+ },
1391
+ async doCodeActions(doc, params) {
1392
+ var _a;
1393
+ const infoByExt = getStyleSheetInfo(doc);
1394
+ const sourceOffset = doc.offsetAt(params.range.start);
1395
+ for (const ext in infoByExt) {
1396
+ const info = infoByExt[ext];
1397
+ const generatedOffsetStart = info.generatedOffsetAt(sourceOffset);
1398
+ if (generatedOffsetStart === void 0)
1399
+ continue;
1400
+ const generatedOffsetEnd = info.generatedOffsetAt(doc.offsetAt(params.range.end));
1401
+ if (generatedOffsetEnd === void 0)
1402
+ continue;
1403
+ const { service: service2, virtualDoc } = info;
1404
+ const result = service2.doCodeActions(virtualDoc, Range8.create(virtualDoc.positionAt(generatedOffsetStart), virtualDoc.positionAt(generatedOffsetEnd)), params.context, info.parsed);
1405
+ if (result) {
1406
+ for (const command of result) {
1407
+ const edits = (_a = command.arguments) == null ? void 0 : _a[2];
1408
+ if (edits) {
1409
+ for (const textEdit of edits) {
1410
+ updateTextEdit(doc, info, textEdit);
1411
+ }
1412
+ }
1413
+ }
1414
+ return result;
1415
+ }
1416
+ }
1417
+ },
1341
1418
  async doValidate(doc) {
1342
1419
  const infoByExt = getStyleSheetInfo(doc);
1343
1420
  const result = [];
@@ -1352,6 +1429,18 @@ var stylesheet_default = {
1352
1429
  return result;
1353
1430
  }
1354
1431
  };
1432
+ function updateTextEdit(doc, info, textEdit) {
1433
+ if (!updateRange(doc, info, textEdit.range)) {
1434
+ textEdit.newText = "";
1435
+ textEdit.range = START_OF_FILE;
1436
+ }
1437
+ }
1438
+ function updateInsertReplaceEdit(doc, info, insertReplaceEdit) {
1439
+ if (!updateRange(doc, info, insertReplaceEdit.insert)) {
1440
+ insertReplaceEdit.newText = "";
1441
+ insertReplaceEdit.insert = START_OF_FILE;
1442
+ }
1443
+ }
1355
1444
  function updateRange(doc, info, range) {
1356
1445
  const start = info.sourceOffsetAt(info.virtualDoc.offsetAt(range.start));
1357
1446
  const end = info.sourceOffsetAt(info.virtualDoc.offsetAt(range.end));
@@ -1389,7 +1478,7 @@ function getStyleSheetInfo(doc) {
1389
1478
  }
1390
1479
 
1391
1480
  // src/service/index.ts
1392
- var plugins = [marko_default, stylesheet_default];
1481
+ var plugins = [marko_default, StyleSheetService];
1393
1482
  var service = {
1394
1483
  async doComplete(doc, params, cancel) {
1395
1484
  const result = CompletionList3.create([], false);
@@ -1401,7 +1490,7 @@ var service = {
1401
1490
  for (const pending of requests) {
1402
1491
  const cur = await pending;
1403
1492
  if (cancel.isCancellationRequested)
1404
- break;
1493
+ return;
1405
1494
  if (cur) {
1406
1495
  let items;
1407
1496
  if (Array.isArray(cur)) {
@@ -1429,7 +1518,7 @@ var service = {
1429
1518
  for (const pending of requests) {
1430
1519
  const cur = await pending;
1431
1520
  if (cancel.isCancellationRequested)
1432
- break;
1521
+ return;
1433
1522
  if (cur) {
1434
1523
  if (Array.isArray(cur)) {
1435
1524
  result.push(...cur);
@@ -1443,6 +1532,54 @@ var service = {
1443
1532
  }
1444
1533
  return result;
1445
1534
  },
1535
+ async findDocumentColors(doc, params, cancel) {
1536
+ let result;
1537
+ try {
1538
+ const requests = plugins.map((plugin) => {
1539
+ var _a;
1540
+ return (_a = plugin.findDocumentColors) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1541
+ });
1542
+ for (const pending of requests) {
1543
+ const cur = await pending;
1544
+ if (cancel.isCancellationRequested)
1545
+ return;
1546
+ if (cur) {
1547
+ if (result) {
1548
+ result.push(...cur);
1549
+ } else {
1550
+ result = cur;
1551
+ }
1552
+ }
1553
+ }
1554
+ } catch (err) {
1555
+ displayError(err);
1556
+ }
1557
+ return result;
1558
+ },
1559
+ async getColorPresentations(doc, params, cancel) {
1560
+ let result;
1561
+ try {
1562
+ const requests = plugins.map((plugin) => {
1563
+ var _a;
1564
+ return (_a = plugin.getColorPresentations) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1565
+ });
1566
+ for (const pending of requests) {
1567
+ const cur = await pending;
1568
+ if (cancel.isCancellationRequested)
1569
+ return;
1570
+ if (cur) {
1571
+ if (result) {
1572
+ result.push(...cur);
1573
+ } else {
1574
+ result = cur;
1575
+ }
1576
+ }
1577
+ }
1578
+ } catch (err) {
1579
+ displayError(err);
1580
+ }
1581
+ return result;
1582
+ },
1446
1583
  async doHover(doc, params, cancel) {
1447
1584
  var _a;
1448
1585
  try {
@@ -1457,6 +1594,80 @@ var service = {
1457
1594
  displayError(err);
1458
1595
  }
1459
1596
  },
1597
+ async doRename(doc, params, cancel) {
1598
+ let changes;
1599
+ let changeAnnotations;
1600
+ let documentChanges;
1601
+ try {
1602
+ const requests = plugins.map((plugin) => {
1603
+ var _a;
1604
+ return (_a = plugin.doRename) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1605
+ });
1606
+ for (const pending of requests) {
1607
+ const cur = await pending;
1608
+ if (cancel.isCancellationRequested)
1609
+ return;
1610
+ if (cur) {
1611
+ if (cur.changes) {
1612
+ if (changes) {
1613
+ for (const uri in cur.changes) {
1614
+ if (changes[uri]) {
1615
+ changes[uri].push(...cur.changes[uri]);
1616
+ } else {
1617
+ changes[uri] = cur.changes[uri];
1618
+ }
1619
+ }
1620
+ } else {
1621
+ changes = cur.changes;
1622
+ }
1623
+ }
1624
+ if (cur.changeAnnotations) {
1625
+ if (changeAnnotations) {
1626
+ Object.assign(changeAnnotations, cur.changeAnnotations);
1627
+ } else {
1628
+ changeAnnotations = cur.changeAnnotations;
1629
+ }
1630
+ }
1631
+ if (cur.documentChanges) {
1632
+ if (documentChanges) {
1633
+ documentChanges.push(...cur.documentChanges);
1634
+ } else {
1635
+ documentChanges = cur.documentChanges;
1636
+ }
1637
+ }
1638
+ }
1639
+ }
1640
+ } catch (err) {
1641
+ displayError(err);
1642
+ }
1643
+ if (changes || changeAnnotations || documentChanges) {
1644
+ return {
1645
+ changes,
1646
+ changeAnnotations,
1647
+ documentChanges
1648
+ };
1649
+ }
1650
+ },
1651
+ async doCodeActions(doc, params, cancel) {
1652
+ const result = [];
1653
+ try {
1654
+ const requests = plugins.map((plugin) => {
1655
+ var _a;
1656
+ return (_a = plugin.doCodeActions) == null ? void 0 : _a.call(plugin, doc, params, cancel);
1657
+ });
1658
+ for (const pending of requests) {
1659
+ const cur = await pending;
1660
+ if (cancel.isCancellationRequested)
1661
+ return;
1662
+ if (cur) {
1663
+ result.push(...cur);
1664
+ }
1665
+ }
1666
+ } catch (err) {
1667
+ displayError(err);
1668
+ }
1669
+ return result;
1670
+ },
1460
1671
  async doValidate(doc) {
1461
1672
  const result = [];
1462
1673
  try {
@@ -1483,8 +1694,9 @@ if (typeof __require !== "undefined" && __require.extensions && !(".ts" in __req
1483
1694
  }
1484
1695
  var documents = new TextDocuments(TextDocument3);
1485
1696
  var connection2 = createConnection(ProposedFeatures.all);
1486
- var prevDiagnostics = /* @__PURE__ */ new WeakMap();
1487
- var diagnosticTimeouts = /* @__PURE__ */ new WeakMap();
1697
+ var prevDiags = /* @__PURE__ */ new WeakMap();
1698
+ var pendingDiags = /* @__PURE__ */ new WeakSet();
1699
+ var diagnosticTimeout;
1488
1700
  console.log = (...args) => {
1489
1701
  connection2.console.log(args.map((v) => inspect2(v)).join(" "));
1490
1702
  };
@@ -1494,14 +1706,16 @@ console.error = (...args) => {
1494
1706
  process.on("uncaughtException", console.error);
1495
1707
  process.on("unhandledRejection", console.error);
1496
1708
  connection2.onInitialize(() => {
1497
- setup2(connection2);
1498
- setup(connection2, documents);
1709
+ setup(connection2);
1499
1710
  return {
1500
1711
  capabilities: {
1501
1712
  textDocumentSync: TextDocumentSyncKind.Incremental,
1502
1713
  documentFormattingProvider: true,
1503
1714
  definitionProvider: true,
1504
1715
  hoverProvider: true,
1716
+ renameProvider: true,
1717
+ codeActionProvider: true,
1718
+ colorProvider: true,
1505
1719
  completionProvider: {
1506
1720
  triggerCharacters: [
1507
1721
  ".",
@@ -1528,11 +1742,12 @@ connection2.onInitialize(() => {
1528
1742
  }
1529
1743
  };
1530
1744
  });
1531
- connection2.onInitialized(() => {
1532
- documents.all().forEach((doc) => queueValidation(doc));
1533
- });
1534
- documents.onDidChangeContent((change) => {
1535
- queueValidation(change.document);
1745
+ connection2.onDidChangeConfiguration(validateDocs);
1746
+ connection2.onDidChangeWatchedFiles(validateDocs);
1747
+ documents.onDidChangeContent(({ document }) => {
1748
+ queueDiagnostic();
1749
+ pendingDiags.add(document);
1750
+ clearCompilerCache(document);
1536
1751
  });
1537
1752
  connection2.onCompletion(async (params, cancel) => {
1538
1753
  return await service.doComplete(documents.get(params.textDocument.uri), params, cancel) || null;
@@ -1540,27 +1755,56 @@ connection2.onCompletion(async (params, cancel) => {
1540
1755
  connection2.onDefinition(async (params, cancel) => {
1541
1756
  return await service.findDefinition(documents.get(params.textDocument.uri), params, cancel) || null;
1542
1757
  });
1758
+ connection2.onDocumentColor(async (params, cancel) => {
1759
+ return await service.findDocumentColors(documents.get(params.textDocument.uri), params, cancel) || null;
1760
+ });
1761
+ connection2.onColorPresentation(async (params, cancel) => {
1762
+ return await service.getColorPresentations(documents.get(params.textDocument.uri), params, cancel) || null;
1763
+ });
1543
1764
  connection2.onHover(async (params, cancel) => {
1544
1765
  return await service.doHover(documents.get(params.textDocument.uri), params, cancel) || null;
1545
1766
  });
1767
+ connection2.onRenameRequest(async (params, cancel) => {
1768
+ return await service.doRename(documents.get(params.textDocument.uri), params, cancel) || null;
1769
+ });
1770
+ connection2.onCodeAction(async (params, cancel) => {
1771
+ return await service.doCodeActions(documents.get(params.textDocument.uri), params, cancel) || null;
1772
+ });
1546
1773
  connection2.onDocumentFormatting(async (params, cancel) => {
1547
1774
  return await service.format(documents.get(params.textDocument.uri), params, cancel) || null;
1548
1775
  });
1549
- function queueValidation(doc) {
1550
- clearTimeout(diagnosticTimeouts.get(doc));
1551
- const id = setTimeout(async () => {
1552
- const prevDiag = prevDiagnostics.get(doc);
1553
- const nextDiag = await service.doValidate(doc) || [];
1554
- if (diagnosticTimeouts.get(doc) !== id || prevDiag && isDeepStrictEqual(prevDiag, nextDiag)) {
1555
- return;
1776
+ function validateDocs() {
1777
+ queueDiagnostic();
1778
+ clearCompilerCache();
1779
+ for (const doc of documents.all()) {
1780
+ pendingDiags.add(doc);
1781
+ }
1782
+ }
1783
+ function queueDiagnostic() {
1784
+ clearTimeout(diagnosticTimeout);
1785
+ const id = diagnosticTimeout = setTimeout(async () => {
1786
+ const results = await Promise.all(documents.all().map(async (doc) => {
1787
+ if (!pendingDiags.delete(doc))
1788
+ return;
1789
+ const prevDiag = prevDiags.get(doc) || [];
1790
+ const nextDiag = await service.doValidate(doc) || [];
1791
+ if (isDeepStrictEqual(prevDiag, nextDiag))
1792
+ return;
1793
+ return [doc, nextDiag];
1794
+ }));
1795
+ if (id === diagnosticTimeout) {
1796
+ for (const result of results) {
1797
+ if (result) {
1798
+ const [doc, diag] = result;
1799
+ prevDiags.set(doc, diag);
1800
+ connection2.sendDiagnostics({
1801
+ uri: doc.uri,
1802
+ diagnostics: diag
1803
+ });
1804
+ }
1805
+ }
1556
1806
  }
1557
- prevDiagnostics.set(doc, nextDiag);
1558
- connection2.sendDiagnostics({
1559
- uri: doc.uri,
1560
- diagnostics: nextDiag
1561
- });
1562
1807
  }, 400);
1563
- diagnosticTimeouts.set(doc, id);
1564
1808
  }
1565
1809
  documents.listen(connection2);
1566
1810
  connection2.listen();