@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.js +444 -109
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +448 -111
- package/dist/index.mjs.map +2 -2
- package/dist/service/stylesheet/index.d.ts +2 -2
- package/dist/service/types.d.ts +7 -1
- package/dist/utils/compiler.d.ts +1 -2
- package/package.json +1 -1
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
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
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
|
|
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
|
|
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 =
|
|
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
|
-
|
|
877
|
+
translator,
|
|
894
878
|
code: false,
|
|
895
|
-
|
|
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
|
|
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
|
|
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 =
|
|
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(
|
|
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
|
|
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(
|
|
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,15 +1025,12 @@ 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
|
|
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
|
-
var
|
|
1047
|
-
import_vscode_languageserver9.TextEdit.replace(import_vscode_languageserver9.Range.create(import_vscode_languageserver9.Position.create(0, 0), import_vscode_languageserver9.Position.create(0, 0)), "")
|
|
1048
|
-
];
|
|
1049
|
-
var format2 = async (doc, params, token) => {
|
|
1031
|
+
var format2 = async (doc, params, cancel) => {
|
|
1050
1032
|
try {
|
|
1051
|
-
const { fsPath, scheme } =
|
|
1033
|
+
const { fsPath, scheme } = import_vscode_uri6.URI.parse(doc.uri);
|
|
1052
1034
|
const text = doc.getText();
|
|
1053
1035
|
const options = {
|
|
1054
1036
|
parser: "marko",
|
|
@@ -1060,15 +1042,14 @@ var format2 = async (doc, params, token) => {
|
|
|
1060
1042
|
editorconfig: true
|
|
1061
1043
|
}).catch(() => null) : null
|
|
1062
1044
|
};
|
|
1063
|
-
if (
|
|
1064
|
-
return
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1045
|
+
if (cancel.isCancellationRequested)
|
|
1046
|
+
return;
|
|
1047
|
+
return [
|
|
1048
|
+
import_vscode_languageserver9.TextEdit.replace(import_vscode_languageserver9.Range.create(doc.positionAt(0), doc.positionAt(text.length)), prettier.format(text, options))
|
|
1049
|
+
];
|
|
1068
1050
|
} catch (e) {
|
|
1069
1051
|
displayError(e);
|
|
1070
1052
|
}
|
|
1071
|
-
return NO_EDIT;
|
|
1072
1053
|
};
|
|
1073
1054
|
|
|
1074
1055
|
// src/service/marko/index.ts
|
|
@@ -1144,7 +1125,7 @@ function createExtractor(code) {
|
|
|
1144
1125
|
const generatedStart = generatedMap[key];
|
|
1145
1126
|
const sourceStart = generatedMap[key + 1];
|
|
1146
1127
|
const sourceEnd = generatedMap[key + 2];
|
|
1147
|
-
return sourceEnd - sourceStart
|
|
1128
|
+
return sourceEnd - sourceStart < generatedOffset - generatedStart ? void 0 : sourceStart + (generatedOffset - generatedStart);
|
|
1148
1129
|
},
|
|
1149
1130
|
generatedOffsetAt(sourceOffset) {
|
|
1150
1131
|
let max = sourceMap.length / 3;
|
|
@@ -1184,10 +1165,20 @@ function extractStyleSheets(code, program, lookup) {
|
|
|
1184
1165
|
}).replace(/^.*\./, "") : "css";
|
|
1185
1166
|
};
|
|
1186
1167
|
const visit = (node) => {
|
|
1187
|
-
var _a, _b
|
|
1168
|
+
var _a, _b;
|
|
1188
1169
|
switch (node.type) {
|
|
1189
1170
|
case 1 /* Tag */:
|
|
1190
|
-
if (
|
|
1171
|
+
if (node.nameText === "style" && node.concise && node.attrs) {
|
|
1172
|
+
const block = node.attrs.at(-1);
|
|
1173
|
+
if (block.type === 8 /* AttrNamed */ && code[block.start] === "{") {
|
|
1174
|
+
getExtractor(getFileExtFromTag(node)).write`${{
|
|
1175
|
+
start: block.start + 1,
|
|
1176
|
+
end: block.end - 1
|
|
1177
|
+
}}`;
|
|
1178
|
+
break;
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
if (node.body) {
|
|
1191
1182
|
if (node.nameText === "style") {
|
|
1192
1183
|
const ext = getFileExtFromTag(node);
|
|
1193
1184
|
for (const child of node.body) {
|
|
@@ -1201,30 +1192,22 @@ function extractStyleSheets(code, program, lookup) {
|
|
|
1201
1192
|
}
|
|
1202
1193
|
}
|
|
1203
1194
|
} else {
|
|
1204
|
-
if (node.attrs) {
|
|
1205
|
-
for (const attr of node.attrs) {
|
|
1206
|
-
if (attr.type === 8 /* AttrNamed */ && ((_b = attr.value) == null ? void 0 : _b.type) === 11 /* AttrValue */ && /^['"]$/.test(code[attr.value.value.start])) {
|
|
1207
|
-
const name = read(attr.name);
|
|
1208
|
-
if (name === "#style" || name === "style" && lookup && node.nameText && name === "style" && ((_c = lookup.getTag(node.nameText)) == null ? void 0 : _c.html)) {
|
|
1209
|
-
getExtractor("css").write`:root{${{
|
|
1210
|
-
start: attr.value.value.start + 1,
|
|
1211
|
-
end: attr.value.value.end - 1
|
|
1212
|
-
}}}`;
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
1195
|
for (const child of node.body) {
|
|
1218
1196
|
visit(child);
|
|
1219
1197
|
}
|
|
1220
1198
|
}
|
|
1221
|
-
}
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1199
|
+
}
|
|
1200
|
+
if (node.attrs) {
|
|
1201
|
+
for (const attr of node.attrs) {
|
|
1202
|
+
if (attr.type === 8 /* AttrNamed */ && ((_a = attr.value) == null ? void 0 : _a.type) === 11 /* AttrValue */ && /^['"]$/.test(code[attr.value.value.start])) {
|
|
1203
|
+
const name = read(attr.name);
|
|
1204
|
+
if (name === "#style" || name === "style" && lookup && node.nameText && name === "style" && ((_b = lookup.getTag(node.nameText)) == null ? void 0 : _b.html)) {
|
|
1205
|
+
getExtractor("css").write`:root{${{
|
|
1206
|
+
start: attr.value.value.start + 1,
|
|
1207
|
+
end: attr.value.value.end - 1
|
|
1208
|
+
}}}`;
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1228
1211
|
}
|
|
1229
1212
|
}
|
|
1230
1213
|
break;
|
|
@@ -1246,7 +1229,7 @@ var services = {
|
|
|
1246
1229
|
less: import_vscode_css_languageservice.getLESSLanguageService,
|
|
1247
1230
|
scss: import_vscode_css_languageservice.getSCSSLanguageService
|
|
1248
1231
|
};
|
|
1249
|
-
var
|
|
1232
|
+
var StyleSheetService = {
|
|
1250
1233
|
async doComplete(doc, params) {
|
|
1251
1234
|
const infoByExt = getStyleSheetInfo(doc);
|
|
1252
1235
|
const sourceOffset = doc.offsetAt(params.position);
|
|
@@ -1259,26 +1242,17 @@ var stylesheet_default = {
|
|
|
1259
1242
|
const result = service2.doComplete(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed);
|
|
1260
1243
|
for (const item of result.items) {
|
|
1261
1244
|
if (item.additionalTextEdits) {
|
|
1262
|
-
for (const
|
|
1263
|
-
|
|
1264
|
-
edit.newText = "";
|
|
1265
|
-
edit.range = START_OF_FILE;
|
|
1266
|
-
}
|
|
1245
|
+
for (const textEdit2 of item.additionalTextEdits) {
|
|
1246
|
+
updateTextEdit(doc, info, textEdit2);
|
|
1267
1247
|
}
|
|
1268
1248
|
}
|
|
1269
1249
|
const { textEdit } = item;
|
|
1270
1250
|
if (textEdit) {
|
|
1271
1251
|
if (textEdit.range) {
|
|
1272
|
-
|
|
1273
|
-
textEdit.newText = "";
|
|
1274
|
-
textEdit.range = START_OF_FILE;
|
|
1275
|
-
}
|
|
1252
|
+
updateTextEdit(doc, info, textEdit);
|
|
1276
1253
|
}
|
|
1277
1254
|
if (textEdit.insert) {
|
|
1278
|
-
|
|
1279
|
-
textEdit.newText = "";
|
|
1280
|
-
textEdit.insert = START_OF_FILE;
|
|
1281
|
-
}
|
|
1255
|
+
updateInsertReplaceEdit(doc, info, textEdit);
|
|
1282
1256
|
}
|
|
1283
1257
|
}
|
|
1284
1258
|
}
|
|
@@ -1302,6 +1276,84 @@ var stylesheet_default = {
|
|
|
1302
1276
|
break;
|
|
1303
1277
|
}
|
|
1304
1278
|
},
|
|
1279
|
+
async findReferences(doc, params) {
|
|
1280
|
+
const infoByExt = getStyleSheetInfo(doc);
|
|
1281
|
+
const sourceOffset = doc.offsetAt(params.position);
|
|
1282
|
+
for (const ext in infoByExt) {
|
|
1283
|
+
const info = infoByExt[ext];
|
|
1284
|
+
const generatedOffset = info.generatedOffsetAt(sourceOffset);
|
|
1285
|
+
if (generatedOffset === void 0)
|
|
1286
|
+
continue;
|
|
1287
|
+
const { service: service2, virtualDoc } = info;
|
|
1288
|
+
const result = [];
|
|
1289
|
+
for (const location of service2.findReferences(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed)) {
|
|
1290
|
+
if (updateRange(doc, info, location.range)) {
|
|
1291
|
+
result.push(location);
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
return result.length ? result : void 0;
|
|
1295
|
+
}
|
|
1296
|
+
},
|
|
1297
|
+
async findDocumentHighlights(doc, params) {
|
|
1298
|
+
const infoByExt = getStyleSheetInfo(doc);
|
|
1299
|
+
const sourceOffset = doc.offsetAt(params.position);
|
|
1300
|
+
for (const ext in infoByExt) {
|
|
1301
|
+
const info = infoByExt[ext];
|
|
1302
|
+
const generatedOffset = info.generatedOffsetAt(sourceOffset);
|
|
1303
|
+
if (generatedOffset === void 0)
|
|
1304
|
+
continue;
|
|
1305
|
+
const { service: service2, virtualDoc } = info;
|
|
1306
|
+
const result = [];
|
|
1307
|
+
for (const highlight of service2.findDocumentHighlights(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed)) {
|
|
1308
|
+
if (updateRange(doc, info, highlight.range)) {
|
|
1309
|
+
result.push(highlight);
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
return result.length ? result : void 0;
|
|
1313
|
+
}
|
|
1314
|
+
},
|
|
1315
|
+
async findDocumentColors(doc) {
|
|
1316
|
+
const infoByExt = getStyleSheetInfo(doc);
|
|
1317
|
+
const result = [];
|
|
1318
|
+
for (const ext in infoByExt) {
|
|
1319
|
+
const info = infoByExt[ext];
|
|
1320
|
+
const { service: service2, virtualDoc } = info;
|
|
1321
|
+
for (const colorInfo of service2.findDocumentColors(virtualDoc, info.parsed)) {
|
|
1322
|
+
if (updateRange(doc, info, colorInfo.range)) {
|
|
1323
|
+
result.push(colorInfo);
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
if (result.length) {
|
|
1328
|
+
return result;
|
|
1329
|
+
}
|
|
1330
|
+
},
|
|
1331
|
+
async getColorPresentations(doc, params) {
|
|
1332
|
+
const infoByExt = getStyleSheetInfo(doc);
|
|
1333
|
+
const sourceOffset = doc.offsetAt(params.range.start);
|
|
1334
|
+
for (const ext in infoByExt) {
|
|
1335
|
+
const info = infoByExt[ext];
|
|
1336
|
+
const generatedOffsetStart = info.generatedOffsetAt(sourceOffset);
|
|
1337
|
+
if (generatedOffsetStart === void 0)
|
|
1338
|
+
continue;
|
|
1339
|
+
const generatedOffsetEnd = info.generatedOffsetAt(doc.offsetAt(params.range.end));
|
|
1340
|
+
if (generatedOffsetEnd === void 0)
|
|
1341
|
+
continue;
|
|
1342
|
+
const { service: service2, virtualDoc } = info;
|
|
1343
|
+
const result = service2.getColorPresentations(virtualDoc, info.parsed, params.color, import_vscode_languageserver10.Range.create(virtualDoc.positionAt(generatedOffsetStart), virtualDoc.positionAt(generatedOffsetEnd)));
|
|
1344
|
+
for (const colorPresentation of result) {
|
|
1345
|
+
if (colorPresentation.textEdit) {
|
|
1346
|
+
updateTextEdit(doc, info, colorPresentation.textEdit);
|
|
1347
|
+
}
|
|
1348
|
+
if (colorPresentation.additionalTextEdits) {
|
|
1349
|
+
for (const textEdit of colorPresentation.additionalTextEdits) {
|
|
1350
|
+
updateTextEdit(doc, info, textEdit);
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
return result;
|
|
1355
|
+
}
|
|
1356
|
+
},
|
|
1305
1357
|
async doHover(doc, params) {
|
|
1306
1358
|
const infoByExt = getStyleSheetInfo(doc);
|
|
1307
1359
|
const sourceOffset = doc.offsetAt(params.position);
|
|
@@ -1311,12 +1363,72 @@ var stylesheet_default = {
|
|
|
1311
1363
|
if (generatedOffset === void 0)
|
|
1312
1364
|
continue;
|
|
1313
1365
|
const { service: service2, virtualDoc } = info;
|
|
1314
|
-
const result = service2.doHover(virtualDoc, virtualDoc.positionAt(generatedOffset),
|
|
1366
|
+
const result = service2.doHover(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed);
|
|
1315
1367
|
if (result && (!result.range || updateRange(doc, info, result.range))) {
|
|
1316
1368
|
return result;
|
|
1317
1369
|
}
|
|
1318
1370
|
}
|
|
1319
1371
|
},
|
|
1372
|
+
async doRename(doc, params) {
|
|
1373
|
+
const infoByExt = getStyleSheetInfo(doc);
|
|
1374
|
+
const sourceOffset = doc.offsetAt(params.position);
|
|
1375
|
+
for (const ext in infoByExt) {
|
|
1376
|
+
const info = infoByExt[ext];
|
|
1377
|
+
const generatedOffset = info.generatedOffsetAt(sourceOffset);
|
|
1378
|
+
if (generatedOffset === void 0)
|
|
1379
|
+
continue;
|
|
1380
|
+
const { service: service2, virtualDoc } = info;
|
|
1381
|
+
const result = service2.doRename(virtualDoc, virtualDoc.positionAt(generatedOffset), params.newName, info.parsed);
|
|
1382
|
+
if (result.changes) {
|
|
1383
|
+
for (const uri in result.changes) {
|
|
1384
|
+
if (uri === doc.uri) {
|
|
1385
|
+
for (const textEdit of result.changes[uri]) {
|
|
1386
|
+
updateTextEdit(doc, info, textEdit);
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
if (result.documentChanges) {
|
|
1392
|
+
for (const change of result.documentChanges) {
|
|
1393
|
+
if (import_vscode_languageserver10.TextDocumentEdit.is(change)) {
|
|
1394
|
+
if (change.textDocument.uri === doc.uri) {
|
|
1395
|
+
for (const textEdit of change.edits) {
|
|
1396
|
+
updateTextEdit(doc, info, textEdit);
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
return result;
|
|
1403
|
+
}
|
|
1404
|
+
},
|
|
1405
|
+
async doCodeActions(doc, params) {
|
|
1406
|
+
var _a;
|
|
1407
|
+
const infoByExt = getStyleSheetInfo(doc);
|
|
1408
|
+
const sourceOffset = doc.offsetAt(params.range.start);
|
|
1409
|
+
for (const ext in infoByExt) {
|
|
1410
|
+
const info = infoByExt[ext];
|
|
1411
|
+
const generatedOffsetStart = info.generatedOffsetAt(sourceOffset);
|
|
1412
|
+
if (generatedOffsetStart === void 0)
|
|
1413
|
+
continue;
|
|
1414
|
+
const generatedOffsetEnd = info.generatedOffsetAt(doc.offsetAt(params.range.end));
|
|
1415
|
+
if (generatedOffsetEnd === void 0)
|
|
1416
|
+
continue;
|
|
1417
|
+
const { service: service2, virtualDoc } = info;
|
|
1418
|
+
const result = service2.doCodeActions(virtualDoc, import_vscode_languageserver10.Range.create(virtualDoc.positionAt(generatedOffsetStart), virtualDoc.positionAt(generatedOffsetEnd)), params.context, info.parsed);
|
|
1419
|
+
if (result) {
|
|
1420
|
+
for (const command of result) {
|
|
1421
|
+
const edits = (_a = command.arguments) == null ? void 0 : _a[2];
|
|
1422
|
+
if (edits) {
|
|
1423
|
+
for (const textEdit of edits) {
|
|
1424
|
+
updateTextEdit(doc, info, textEdit);
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
return result;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
},
|
|
1320
1432
|
async doValidate(doc) {
|
|
1321
1433
|
const infoByExt = getStyleSheetInfo(doc);
|
|
1322
1434
|
const result = [];
|
|
@@ -1331,6 +1443,18 @@ var stylesheet_default = {
|
|
|
1331
1443
|
return result;
|
|
1332
1444
|
}
|
|
1333
1445
|
};
|
|
1446
|
+
function updateTextEdit(doc, info, textEdit) {
|
|
1447
|
+
if (!updateRange(doc, info, textEdit.range)) {
|
|
1448
|
+
textEdit.newText = "";
|
|
1449
|
+
textEdit.range = START_OF_FILE;
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
function updateInsertReplaceEdit(doc, info, insertReplaceEdit) {
|
|
1453
|
+
if (!updateRange(doc, info, insertReplaceEdit.insert)) {
|
|
1454
|
+
insertReplaceEdit.newText = "";
|
|
1455
|
+
insertReplaceEdit.insert = START_OF_FILE;
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1334
1458
|
function updateRange(doc, info, range) {
|
|
1335
1459
|
const start = info.sourceOffsetAt(info.virtualDoc.offsetAt(range.start));
|
|
1336
1460
|
const end = info.sourceOffsetAt(info.virtualDoc.offsetAt(range.end));
|
|
@@ -1368,7 +1492,7 @@ function getStyleSheetInfo(doc) {
|
|
|
1368
1492
|
}
|
|
1369
1493
|
|
|
1370
1494
|
// src/service/index.ts
|
|
1371
|
-
var plugins = [marko_default,
|
|
1495
|
+
var plugins = [marko_default, StyleSheetService];
|
|
1372
1496
|
var service = {
|
|
1373
1497
|
async doComplete(doc, params, cancel) {
|
|
1374
1498
|
const result = import_vscode_languageserver11.CompletionList.create([], false);
|
|
@@ -1380,7 +1504,7 @@ var service = {
|
|
|
1380
1504
|
for (const pending of requests) {
|
|
1381
1505
|
const cur = await pending;
|
|
1382
1506
|
if (cancel.isCancellationRequested)
|
|
1383
|
-
|
|
1507
|
+
return;
|
|
1384
1508
|
if (cur) {
|
|
1385
1509
|
let items;
|
|
1386
1510
|
if (Array.isArray(cur)) {
|
|
@@ -1408,7 +1532,7 @@ var service = {
|
|
|
1408
1532
|
for (const pending of requests) {
|
|
1409
1533
|
const cur = await pending;
|
|
1410
1534
|
if (cancel.isCancellationRequested)
|
|
1411
|
-
|
|
1535
|
+
return;
|
|
1412
1536
|
if (cur) {
|
|
1413
1537
|
if (Array.isArray(cur)) {
|
|
1414
1538
|
result.push(...cur);
|
|
@@ -1422,6 +1546,102 @@ var service = {
|
|
|
1422
1546
|
}
|
|
1423
1547
|
return result;
|
|
1424
1548
|
},
|
|
1549
|
+
async findReferences(doc, params, cancel) {
|
|
1550
|
+
let result;
|
|
1551
|
+
try {
|
|
1552
|
+
const requests = plugins.map((plugin) => {
|
|
1553
|
+
var _a;
|
|
1554
|
+
return (_a = plugin.findReferences) == null ? void 0 : _a.call(plugin, doc, params, cancel);
|
|
1555
|
+
});
|
|
1556
|
+
for (const pending of requests) {
|
|
1557
|
+
const cur = await pending;
|
|
1558
|
+
if (cancel.isCancellationRequested)
|
|
1559
|
+
return;
|
|
1560
|
+
if (cur) {
|
|
1561
|
+
if (result) {
|
|
1562
|
+
result.push(...cur);
|
|
1563
|
+
} else {
|
|
1564
|
+
result = cur;
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
} catch (err) {
|
|
1569
|
+
displayError(err);
|
|
1570
|
+
}
|
|
1571
|
+
return result;
|
|
1572
|
+
},
|
|
1573
|
+
async findDocumentHighlights(doc, params, cancel) {
|
|
1574
|
+
let result;
|
|
1575
|
+
try {
|
|
1576
|
+
const requests = plugins.map((plugin) => {
|
|
1577
|
+
var _a;
|
|
1578
|
+
return (_a = plugin.findDocumentHighlights) == null ? void 0 : _a.call(plugin, doc, params, cancel);
|
|
1579
|
+
});
|
|
1580
|
+
for (const pending of requests) {
|
|
1581
|
+
const cur = await pending;
|
|
1582
|
+
if (cancel.isCancellationRequested)
|
|
1583
|
+
return;
|
|
1584
|
+
if (cur) {
|
|
1585
|
+
if (result) {
|
|
1586
|
+
result.push(...cur);
|
|
1587
|
+
} else {
|
|
1588
|
+
result = cur;
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
} catch (err) {
|
|
1593
|
+
displayError(err);
|
|
1594
|
+
}
|
|
1595
|
+
return result;
|
|
1596
|
+
},
|
|
1597
|
+
async findDocumentColors(doc, params, cancel) {
|
|
1598
|
+
let result;
|
|
1599
|
+
try {
|
|
1600
|
+
const requests = plugins.map((plugin) => {
|
|
1601
|
+
var _a;
|
|
1602
|
+
return (_a = plugin.findDocumentColors) == null ? void 0 : _a.call(plugin, doc, params, cancel);
|
|
1603
|
+
});
|
|
1604
|
+
for (const pending of requests) {
|
|
1605
|
+
const cur = await pending;
|
|
1606
|
+
if (cancel.isCancellationRequested)
|
|
1607
|
+
return;
|
|
1608
|
+
if (cur) {
|
|
1609
|
+
if (result) {
|
|
1610
|
+
result.push(...cur);
|
|
1611
|
+
} else {
|
|
1612
|
+
result = cur;
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
} catch (err) {
|
|
1617
|
+
displayError(err);
|
|
1618
|
+
}
|
|
1619
|
+
return result;
|
|
1620
|
+
},
|
|
1621
|
+
async getColorPresentations(doc, params, cancel) {
|
|
1622
|
+
let result;
|
|
1623
|
+
try {
|
|
1624
|
+
const requests = plugins.map((plugin) => {
|
|
1625
|
+
var _a;
|
|
1626
|
+
return (_a = plugin.getColorPresentations) == null ? void 0 : _a.call(plugin, doc, params, cancel);
|
|
1627
|
+
});
|
|
1628
|
+
for (const pending of requests) {
|
|
1629
|
+
const cur = await pending;
|
|
1630
|
+
if (cancel.isCancellationRequested)
|
|
1631
|
+
return;
|
|
1632
|
+
if (cur) {
|
|
1633
|
+
if (result) {
|
|
1634
|
+
result.push(...cur);
|
|
1635
|
+
} else {
|
|
1636
|
+
result = cur;
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
} catch (err) {
|
|
1641
|
+
displayError(err);
|
|
1642
|
+
}
|
|
1643
|
+
return result;
|
|
1644
|
+
},
|
|
1425
1645
|
async doHover(doc, params, cancel) {
|
|
1426
1646
|
var _a;
|
|
1427
1647
|
try {
|
|
@@ -1436,6 +1656,80 @@ var service = {
|
|
|
1436
1656
|
displayError(err);
|
|
1437
1657
|
}
|
|
1438
1658
|
},
|
|
1659
|
+
async doRename(doc, params, cancel) {
|
|
1660
|
+
let changes;
|
|
1661
|
+
let changeAnnotations;
|
|
1662
|
+
let documentChanges;
|
|
1663
|
+
try {
|
|
1664
|
+
const requests = plugins.map((plugin) => {
|
|
1665
|
+
var _a;
|
|
1666
|
+
return (_a = plugin.doRename) == null ? void 0 : _a.call(plugin, doc, params, cancel);
|
|
1667
|
+
});
|
|
1668
|
+
for (const pending of requests) {
|
|
1669
|
+
const cur = await pending;
|
|
1670
|
+
if (cancel.isCancellationRequested)
|
|
1671
|
+
return;
|
|
1672
|
+
if (cur) {
|
|
1673
|
+
if (cur.changes) {
|
|
1674
|
+
if (changes) {
|
|
1675
|
+
for (const uri in cur.changes) {
|
|
1676
|
+
if (changes[uri]) {
|
|
1677
|
+
changes[uri].push(...cur.changes[uri]);
|
|
1678
|
+
} else {
|
|
1679
|
+
changes[uri] = cur.changes[uri];
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
} else {
|
|
1683
|
+
changes = cur.changes;
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
if (cur.changeAnnotations) {
|
|
1687
|
+
if (changeAnnotations) {
|
|
1688
|
+
Object.assign(changeAnnotations, cur.changeAnnotations);
|
|
1689
|
+
} else {
|
|
1690
|
+
changeAnnotations = cur.changeAnnotations;
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
if (cur.documentChanges) {
|
|
1694
|
+
if (documentChanges) {
|
|
1695
|
+
documentChanges.push(...cur.documentChanges);
|
|
1696
|
+
} else {
|
|
1697
|
+
documentChanges = cur.documentChanges;
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
} catch (err) {
|
|
1703
|
+
displayError(err);
|
|
1704
|
+
}
|
|
1705
|
+
if (changes || changeAnnotations || documentChanges) {
|
|
1706
|
+
return {
|
|
1707
|
+
changes,
|
|
1708
|
+
changeAnnotations,
|
|
1709
|
+
documentChanges
|
|
1710
|
+
};
|
|
1711
|
+
}
|
|
1712
|
+
},
|
|
1713
|
+
async doCodeActions(doc, params, cancel) {
|
|
1714
|
+
const result = [];
|
|
1715
|
+
try {
|
|
1716
|
+
const requests = plugins.map((plugin) => {
|
|
1717
|
+
var _a;
|
|
1718
|
+
return (_a = plugin.doCodeActions) == null ? void 0 : _a.call(plugin, doc, params, cancel);
|
|
1719
|
+
});
|
|
1720
|
+
for (const pending of requests) {
|
|
1721
|
+
const cur = await pending;
|
|
1722
|
+
if (cancel.isCancellationRequested)
|
|
1723
|
+
return;
|
|
1724
|
+
if (cur) {
|
|
1725
|
+
result.push(...cur);
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
} catch (err) {
|
|
1729
|
+
displayError(err);
|
|
1730
|
+
}
|
|
1731
|
+
return result;
|
|
1732
|
+
},
|
|
1439
1733
|
async doValidate(doc) {
|
|
1440
1734
|
const result = [];
|
|
1441
1735
|
try {
|
|
@@ -1462,8 +1756,9 @@ if (typeof require !== "undefined" && require.extensions && !(".ts" in require.e
|
|
|
1462
1756
|
}
|
|
1463
1757
|
var documents = new import_node.TextDocuments(import_vscode_languageserver_textdocument3.TextDocument);
|
|
1464
1758
|
var connection2 = (0, import_node.createConnection)(import_node.ProposedFeatures.all);
|
|
1465
|
-
var
|
|
1466
|
-
var
|
|
1759
|
+
var prevDiags = /* @__PURE__ */ new WeakMap();
|
|
1760
|
+
var pendingDiags = /* @__PURE__ */ new WeakSet();
|
|
1761
|
+
var diagnosticTimeout;
|
|
1467
1762
|
console.log = (...args) => {
|
|
1468
1763
|
connection2.console.log(args.map((v) => (0, import_util2.inspect)(v)).join(" "));
|
|
1469
1764
|
};
|
|
@@ -1473,14 +1768,18 @@ console.error = (...args) => {
|
|
|
1473
1768
|
process.on("uncaughtException", console.error);
|
|
1474
1769
|
process.on("unhandledRejection", console.error);
|
|
1475
1770
|
connection2.onInitialize(() => {
|
|
1476
|
-
|
|
1477
|
-
setup(connection2, documents);
|
|
1771
|
+
setup(connection2);
|
|
1478
1772
|
return {
|
|
1479
1773
|
capabilities: {
|
|
1480
1774
|
textDocumentSync: import_node.TextDocumentSyncKind.Incremental,
|
|
1481
1775
|
documentFormattingProvider: true,
|
|
1482
1776
|
definitionProvider: true,
|
|
1483
1777
|
hoverProvider: true,
|
|
1778
|
+
renameProvider: true,
|
|
1779
|
+
codeActionProvider: true,
|
|
1780
|
+
referencesProvider: true,
|
|
1781
|
+
colorProvider: true,
|
|
1782
|
+
documentHighlightProvider: true,
|
|
1484
1783
|
completionProvider: {
|
|
1485
1784
|
triggerCharacters: [
|
|
1486
1785
|
".",
|
|
@@ -1507,11 +1806,12 @@ connection2.onInitialize(() => {
|
|
|
1507
1806
|
}
|
|
1508
1807
|
};
|
|
1509
1808
|
});
|
|
1510
|
-
connection2.
|
|
1511
|
-
|
|
1512
|
-
})
|
|
1513
|
-
|
|
1514
|
-
|
|
1809
|
+
connection2.onDidChangeConfiguration(validateDocs);
|
|
1810
|
+
connection2.onDidChangeWatchedFiles(validateDocs);
|
|
1811
|
+
documents.onDidChangeContent(({ document }) => {
|
|
1812
|
+
queueDiagnostic();
|
|
1813
|
+
pendingDiags.add(document);
|
|
1814
|
+
clearCompilerCache(document);
|
|
1515
1815
|
});
|
|
1516
1816
|
connection2.onCompletion(async (params, cancel) => {
|
|
1517
1817
|
return await service.doComplete(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
@@ -1519,27 +1819,62 @@ connection2.onCompletion(async (params, cancel) => {
|
|
|
1519
1819
|
connection2.onDefinition(async (params, cancel) => {
|
|
1520
1820
|
return await service.findDefinition(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
1521
1821
|
});
|
|
1822
|
+
connection2.onReferences(async (params, cancel) => {
|
|
1823
|
+
return await service.findReferences(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
1824
|
+
});
|
|
1825
|
+
connection2.onDocumentHighlight(async (params, cancel) => {
|
|
1826
|
+
return await service.findDocumentHighlights(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
1827
|
+
});
|
|
1828
|
+
connection2.onDocumentColor(async (params, cancel) => {
|
|
1829
|
+
return await service.findDocumentColors(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
1830
|
+
});
|
|
1831
|
+
connection2.onColorPresentation(async (params, cancel) => {
|
|
1832
|
+
return await service.getColorPresentations(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
1833
|
+
});
|
|
1522
1834
|
connection2.onHover(async (params, cancel) => {
|
|
1523
1835
|
return await service.doHover(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
1524
1836
|
});
|
|
1837
|
+
connection2.onRenameRequest(async (params, cancel) => {
|
|
1838
|
+
return await service.doRename(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
1839
|
+
});
|
|
1840
|
+
connection2.onCodeAction(async (params, cancel) => {
|
|
1841
|
+
return await service.doCodeActions(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
1842
|
+
});
|
|
1525
1843
|
connection2.onDocumentFormatting(async (params, cancel) => {
|
|
1526
1844
|
return await service.format(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
1527
1845
|
});
|
|
1528
|
-
function
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1846
|
+
function validateDocs() {
|
|
1847
|
+
queueDiagnostic();
|
|
1848
|
+
clearCompilerCache();
|
|
1849
|
+
for (const doc of documents.all()) {
|
|
1850
|
+
pendingDiags.add(doc);
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
function queueDiagnostic() {
|
|
1854
|
+
clearTimeout(diagnosticTimeout);
|
|
1855
|
+
const id = diagnosticTimeout = setTimeout(async () => {
|
|
1856
|
+
const results = await Promise.all(documents.all().map(async (doc) => {
|
|
1857
|
+
if (!pendingDiags.delete(doc))
|
|
1858
|
+
return;
|
|
1859
|
+
const prevDiag = prevDiags.get(doc) || [];
|
|
1860
|
+
const nextDiag = await service.doValidate(doc) || [];
|
|
1861
|
+
if ((0, import_util2.isDeepStrictEqual)(prevDiag, nextDiag))
|
|
1862
|
+
return;
|
|
1863
|
+
return [doc, nextDiag];
|
|
1864
|
+
}));
|
|
1865
|
+
if (id === diagnosticTimeout) {
|
|
1866
|
+
for (const result of results) {
|
|
1867
|
+
if (result) {
|
|
1868
|
+
const [doc, diag] = result;
|
|
1869
|
+
prevDiags.set(doc, diag);
|
|
1870
|
+
connection2.sendDiagnostics({
|
|
1871
|
+
uri: doc.uri,
|
|
1872
|
+
diagnostics: diag
|
|
1873
|
+
});
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1535
1876
|
}
|
|
1536
|
-
prevDiagnostics.set(doc, nextDiag);
|
|
1537
|
-
connection2.sendDiagnostics({
|
|
1538
|
-
uri: doc.uri,
|
|
1539
|
-
diagnostics: nextDiag
|
|
1540
|
-
});
|
|
1541
1877
|
}, 400);
|
|
1542
|
-
diagnosticTimeouts.set(doc, id);
|
|
1543
1878
|
}
|
|
1544
1879
|
documents.listen(connection2);
|
|
1545
1880
|
connection2.listen();
|