@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.js +352 -109
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +356 -112
- package/dist/index.mjs.map +2 -2
- package/dist/service/stylesheet/index.d.ts +2 -2
- package/dist/service/types.d.ts +5 -1
- package/dist/utils/compiler.d.ts +1 -2
- package/package.json +5 -5
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,48 @@ var stylesheet_default = {
|
|
|
1302
1276
|
break;
|
|
1303
1277
|
}
|
|
1304
1278
|
},
|
|
1279
|
+
async findDocumentColors(doc) {
|
|
1280
|
+
const infoByExt = getStyleSheetInfo(doc);
|
|
1281
|
+
const result = [];
|
|
1282
|
+
for (const ext in infoByExt) {
|
|
1283
|
+
const info = infoByExt[ext];
|
|
1284
|
+
const { service: service2, virtualDoc } = info;
|
|
1285
|
+
for (const colorInfo of service2.findDocumentColors(virtualDoc, info.parsed)) {
|
|
1286
|
+
if (updateRange(doc, info, colorInfo.range)) {
|
|
1287
|
+
result.push(colorInfo);
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
if (result.length) {
|
|
1292
|
+
return result;
|
|
1293
|
+
}
|
|
1294
|
+
},
|
|
1295
|
+
async getColorPresentations(doc, params) {
|
|
1296
|
+
const infoByExt = getStyleSheetInfo(doc);
|
|
1297
|
+
const sourceOffset = doc.offsetAt(params.range.start);
|
|
1298
|
+
for (const ext in infoByExt) {
|
|
1299
|
+
const info = infoByExt[ext];
|
|
1300
|
+
const generatedOffsetStart = info.generatedOffsetAt(sourceOffset);
|
|
1301
|
+
if (generatedOffsetStart === void 0)
|
|
1302
|
+
continue;
|
|
1303
|
+
const generatedOffsetEnd = info.generatedOffsetAt(doc.offsetAt(params.range.end));
|
|
1304
|
+
if (generatedOffsetEnd === void 0)
|
|
1305
|
+
continue;
|
|
1306
|
+
const { service: service2, virtualDoc } = info;
|
|
1307
|
+
const result = service2.getColorPresentations(virtualDoc, info.parsed, params.color, import_vscode_languageserver10.Range.create(virtualDoc.positionAt(generatedOffsetStart), virtualDoc.positionAt(generatedOffsetEnd)));
|
|
1308
|
+
for (const colorPresentation of result) {
|
|
1309
|
+
if (colorPresentation.textEdit) {
|
|
1310
|
+
updateTextEdit(doc, info, colorPresentation.textEdit);
|
|
1311
|
+
}
|
|
1312
|
+
if (colorPresentation.additionalTextEdits) {
|
|
1313
|
+
for (const textEdit of colorPresentation.additionalTextEdits) {
|
|
1314
|
+
updateTextEdit(doc, info, textEdit);
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
return result;
|
|
1319
|
+
}
|
|
1320
|
+
},
|
|
1305
1321
|
async doHover(doc, params) {
|
|
1306
1322
|
const infoByExt = getStyleSheetInfo(doc);
|
|
1307
1323
|
const sourceOffset = doc.offsetAt(params.position);
|
|
@@ -1311,12 +1327,72 @@ var stylesheet_default = {
|
|
|
1311
1327
|
if (generatedOffset === void 0)
|
|
1312
1328
|
continue;
|
|
1313
1329
|
const { service: service2, virtualDoc } = info;
|
|
1314
|
-
const result = service2.doHover(virtualDoc, virtualDoc.positionAt(generatedOffset),
|
|
1330
|
+
const result = service2.doHover(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed);
|
|
1315
1331
|
if (result && (!result.range || updateRange(doc, info, result.range))) {
|
|
1316
1332
|
return result;
|
|
1317
1333
|
}
|
|
1318
1334
|
}
|
|
1319
1335
|
},
|
|
1336
|
+
async doRename(doc, params) {
|
|
1337
|
+
const infoByExt = getStyleSheetInfo(doc);
|
|
1338
|
+
const sourceOffset = doc.offsetAt(params.position);
|
|
1339
|
+
for (const ext in infoByExt) {
|
|
1340
|
+
const info = infoByExt[ext];
|
|
1341
|
+
const generatedOffset = info.generatedOffsetAt(sourceOffset);
|
|
1342
|
+
if (generatedOffset === void 0)
|
|
1343
|
+
continue;
|
|
1344
|
+
const { service: service2, virtualDoc } = info;
|
|
1345
|
+
const result = service2.doRename(virtualDoc, virtualDoc.positionAt(generatedOffset), params.newName, info.parsed);
|
|
1346
|
+
if (result.changes) {
|
|
1347
|
+
for (const uri in result.changes) {
|
|
1348
|
+
if (uri === doc.uri) {
|
|
1349
|
+
for (const textEdit of result.changes[uri]) {
|
|
1350
|
+
updateTextEdit(doc, info, textEdit);
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
if (result.documentChanges) {
|
|
1356
|
+
for (const change of result.documentChanges) {
|
|
1357
|
+
if (import_vscode_languageserver10.TextDocumentEdit.is(change)) {
|
|
1358
|
+
if (change.textDocument.uri === doc.uri) {
|
|
1359
|
+
for (const textEdit of change.edits) {
|
|
1360
|
+
updateTextEdit(doc, info, textEdit);
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
return result;
|
|
1367
|
+
}
|
|
1368
|
+
},
|
|
1369
|
+
async doCodeActions(doc, params) {
|
|
1370
|
+
var _a;
|
|
1371
|
+
const infoByExt = getStyleSheetInfo(doc);
|
|
1372
|
+
const sourceOffset = doc.offsetAt(params.range.start);
|
|
1373
|
+
for (const ext in infoByExt) {
|
|
1374
|
+
const info = infoByExt[ext];
|
|
1375
|
+
const generatedOffsetStart = info.generatedOffsetAt(sourceOffset);
|
|
1376
|
+
if (generatedOffsetStart === void 0)
|
|
1377
|
+
continue;
|
|
1378
|
+
const generatedOffsetEnd = info.generatedOffsetAt(doc.offsetAt(params.range.end));
|
|
1379
|
+
if (generatedOffsetEnd === void 0)
|
|
1380
|
+
continue;
|
|
1381
|
+
const { service: service2, virtualDoc } = info;
|
|
1382
|
+
const result = service2.doCodeActions(virtualDoc, import_vscode_languageserver10.Range.create(virtualDoc.positionAt(generatedOffsetStart), virtualDoc.positionAt(generatedOffsetEnd)), params.context, info.parsed);
|
|
1383
|
+
if (result) {
|
|
1384
|
+
for (const command of result) {
|
|
1385
|
+
const edits = (_a = command.arguments) == null ? void 0 : _a[2];
|
|
1386
|
+
if (edits) {
|
|
1387
|
+
for (const textEdit of edits) {
|
|
1388
|
+
updateTextEdit(doc, info, textEdit);
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
return result;
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
},
|
|
1320
1396
|
async doValidate(doc) {
|
|
1321
1397
|
const infoByExt = getStyleSheetInfo(doc);
|
|
1322
1398
|
const result = [];
|
|
@@ -1331,6 +1407,18 @@ var stylesheet_default = {
|
|
|
1331
1407
|
return result;
|
|
1332
1408
|
}
|
|
1333
1409
|
};
|
|
1410
|
+
function updateTextEdit(doc, info, textEdit) {
|
|
1411
|
+
if (!updateRange(doc, info, textEdit.range)) {
|
|
1412
|
+
textEdit.newText = "";
|
|
1413
|
+
textEdit.range = START_OF_FILE;
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
function updateInsertReplaceEdit(doc, info, insertReplaceEdit) {
|
|
1417
|
+
if (!updateRange(doc, info, insertReplaceEdit.insert)) {
|
|
1418
|
+
insertReplaceEdit.newText = "";
|
|
1419
|
+
insertReplaceEdit.insert = START_OF_FILE;
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1334
1422
|
function updateRange(doc, info, range) {
|
|
1335
1423
|
const start = info.sourceOffsetAt(info.virtualDoc.offsetAt(range.start));
|
|
1336
1424
|
const end = info.sourceOffsetAt(info.virtualDoc.offsetAt(range.end));
|
|
@@ -1368,7 +1456,7 @@ function getStyleSheetInfo(doc) {
|
|
|
1368
1456
|
}
|
|
1369
1457
|
|
|
1370
1458
|
// src/service/index.ts
|
|
1371
|
-
var plugins = [marko_default,
|
|
1459
|
+
var plugins = [marko_default, StyleSheetService];
|
|
1372
1460
|
var service = {
|
|
1373
1461
|
async doComplete(doc, params, cancel) {
|
|
1374
1462
|
const result = import_vscode_languageserver11.CompletionList.create([], false);
|
|
@@ -1380,7 +1468,7 @@ var service = {
|
|
|
1380
1468
|
for (const pending of requests) {
|
|
1381
1469
|
const cur = await pending;
|
|
1382
1470
|
if (cancel.isCancellationRequested)
|
|
1383
|
-
|
|
1471
|
+
return;
|
|
1384
1472
|
if (cur) {
|
|
1385
1473
|
let items;
|
|
1386
1474
|
if (Array.isArray(cur)) {
|
|
@@ -1408,7 +1496,7 @@ var service = {
|
|
|
1408
1496
|
for (const pending of requests) {
|
|
1409
1497
|
const cur = await pending;
|
|
1410
1498
|
if (cancel.isCancellationRequested)
|
|
1411
|
-
|
|
1499
|
+
return;
|
|
1412
1500
|
if (cur) {
|
|
1413
1501
|
if (Array.isArray(cur)) {
|
|
1414
1502
|
result.push(...cur);
|
|
@@ -1422,6 +1510,54 @@ var service = {
|
|
|
1422
1510
|
}
|
|
1423
1511
|
return result;
|
|
1424
1512
|
},
|
|
1513
|
+
async findDocumentColors(doc, params, cancel) {
|
|
1514
|
+
let result;
|
|
1515
|
+
try {
|
|
1516
|
+
const requests = plugins.map((plugin) => {
|
|
1517
|
+
var _a;
|
|
1518
|
+
return (_a = plugin.findDocumentColors) == null ? void 0 : _a.call(plugin, doc, params, cancel);
|
|
1519
|
+
});
|
|
1520
|
+
for (const pending of requests) {
|
|
1521
|
+
const cur = await pending;
|
|
1522
|
+
if (cancel.isCancellationRequested)
|
|
1523
|
+
return;
|
|
1524
|
+
if (cur) {
|
|
1525
|
+
if (result) {
|
|
1526
|
+
result.push(...cur);
|
|
1527
|
+
} else {
|
|
1528
|
+
result = cur;
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
} catch (err) {
|
|
1533
|
+
displayError(err);
|
|
1534
|
+
}
|
|
1535
|
+
return result;
|
|
1536
|
+
},
|
|
1537
|
+
async getColorPresentations(doc, params, cancel) {
|
|
1538
|
+
let result;
|
|
1539
|
+
try {
|
|
1540
|
+
const requests = plugins.map((plugin) => {
|
|
1541
|
+
var _a;
|
|
1542
|
+
return (_a = plugin.getColorPresentations) == null ? void 0 : _a.call(plugin, doc, params, cancel);
|
|
1543
|
+
});
|
|
1544
|
+
for (const pending of requests) {
|
|
1545
|
+
const cur = await pending;
|
|
1546
|
+
if (cancel.isCancellationRequested)
|
|
1547
|
+
return;
|
|
1548
|
+
if (cur) {
|
|
1549
|
+
if (result) {
|
|
1550
|
+
result.push(...cur);
|
|
1551
|
+
} else {
|
|
1552
|
+
result = cur;
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
} catch (err) {
|
|
1557
|
+
displayError(err);
|
|
1558
|
+
}
|
|
1559
|
+
return result;
|
|
1560
|
+
},
|
|
1425
1561
|
async doHover(doc, params, cancel) {
|
|
1426
1562
|
var _a;
|
|
1427
1563
|
try {
|
|
@@ -1436,6 +1572,80 @@ var service = {
|
|
|
1436
1572
|
displayError(err);
|
|
1437
1573
|
}
|
|
1438
1574
|
},
|
|
1575
|
+
async doRename(doc, params, cancel) {
|
|
1576
|
+
let changes;
|
|
1577
|
+
let changeAnnotations;
|
|
1578
|
+
let documentChanges;
|
|
1579
|
+
try {
|
|
1580
|
+
const requests = plugins.map((plugin) => {
|
|
1581
|
+
var _a;
|
|
1582
|
+
return (_a = plugin.doRename) == null ? void 0 : _a.call(plugin, doc, params, cancel);
|
|
1583
|
+
});
|
|
1584
|
+
for (const pending of requests) {
|
|
1585
|
+
const cur = await pending;
|
|
1586
|
+
if (cancel.isCancellationRequested)
|
|
1587
|
+
return;
|
|
1588
|
+
if (cur) {
|
|
1589
|
+
if (cur.changes) {
|
|
1590
|
+
if (changes) {
|
|
1591
|
+
for (const uri in cur.changes) {
|
|
1592
|
+
if (changes[uri]) {
|
|
1593
|
+
changes[uri].push(...cur.changes[uri]);
|
|
1594
|
+
} else {
|
|
1595
|
+
changes[uri] = cur.changes[uri];
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
} else {
|
|
1599
|
+
changes = cur.changes;
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
if (cur.changeAnnotations) {
|
|
1603
|
+
if (changeAnnotations) {
|
|
1604
|
+
Object.assign(changeAnnotations, cur.changeAnnotations);
|
|
1605
|
+
} else {
|
|
1606
|
+
changeAnnotations = cur.changeAnnotations;
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
if (cur.documentChanges) {
|
|
1610
|
+
if (documentChanges) {
|
|
1611
|
+
documentChanges.push(...cur.documentChanges);
|
|
1612
|
+
} else {
|
|
1613
|
+
documentChanges = cur.documentChanges;
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
} catch (err) {
|
|
1619
|
+
displayError(err);
|
|
1620
|
+
}
|
|
1621
|
+
if (changes || changeAnnotations || documentChanges) {
|
|
1622
|
+
return {
|
|
1623
|
+
changes,
|
|
1624
|
+
changeAnnotations,
|
|
1625
|
+
documentChanges
|
|
1626
|
+
};
|
|
1627
|
+
}
|
|
1628
|
+
},
|
|
1629
|
+
async doCodeActions(doc, params, cancel) {
|
|
1630
|
+
const result = [];
|
|
1631
|
+
try {
|
|
1632
|
+
const requests = plugins.map((plugin) => {
|
|
1633
|
+
var _a;
|
|
1634
|
+
return (_a = plugin.doCodeActions) == null ? void 0 : _a.call(plugin, doc, params, cancel);
|
|
1635
|
+
});
|
|
1636
|
+
for (const pending of requests) {
|
|
1637
|
+
const cur = await pending;
|
|
1638
|
+
if (cancel.isCancellationRequested)
|
|
1639
|
+
return;
|
|
1640
|
+
if (cur) {
|
|
1641
|
+
result.push(...cur);
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
} catch (err) {
|
|
1645
|
+
displayError(err);
|
|
1646
|
+
}
|
|
1647
|
+
return result;
|
|
1648
|
+
},
|
|
1439
1649
|
async doValidate(doc) {
|
|
1440
1650
|
const result = [];
|
|
1441
1651
|
try {
|
|
@@ -1462,8 +1672,9 @@ if (typeof require !== "undefined" && require.extensions && !(".ts" in require.e
|
|
|
1462
1672
|
}
|
|
1463
1673
|
var documents = new import_node.TextDocuments(import_vscode_languageserver_textdocument3.TextDocument);
|
|
1464
1674
|
var connection2 = (0, import_node.createConnection)(import_node.ProposedFeatures.all);
|
|
1465
|
-
var
|
|
1466
|
-
var
|
|
1675
|
+
var prevDiags = /* @__PURE__ */ new WeakMap();
|
|
1676
|
+
var pendingDiags = /* @__PURE__ */ new WeakSet();
|
|
1677
|
+
var diagnosticTimeout;
|
|
1467
1678
|
console.log = (...args) => {
|
|
1468
1679
|
connection2.console.log(args.map((v) => (0, import_util2.inspect)(v)).join(" "));
|
|
1469
1680
|
};
|
|
@@ -1473,14 +1684,16 @@ console.error = (...args) => {
|
|
|
1473
1684
|
process.on("uncaughtException", console.error);
|
|
1474
1685
|
process.on("unhandledRejection", console.error);
|
|
1475
1686
|
connection2.onInitialize(() => {
|
|
1476
|
-
|
|
1477
|
-
setup(connection2, documents);
|
|
1687
|
+
setup(connection2);
|
|
1478
1688
|
return {
|
|
1479
1689
|
capabilities: {
|
|
1480
1690
|
textDocumentSync: import_node.TextDocumentSyncKind.Incremental,
|
|
1481
1691
|
documentFormattingProvider: true,
|
|
1482
1692
|
definitionProvider: true,
|
|
1483
1693
|
hoverProvider: true,
|
|
1694
|
+
renameProvider: true,
|
|
1695
|
+
codeActionProvider: true,
|
|
1696
|
+
colorProvider: true,
|
|
1484
1697
|
completionProvider: {
|
|
1485
1698
|
triggerCharacters: [
|
|
1486
1699
|
".",
|
|
@@ -1507,11 +1720,12 @@ connection2.onInitialize(() => {
|
|
|
1507
1720
|
}
|
|
1508
1721
|
};
|
|
1509
1722
|
});
|
|
1510
|
-
connection2.
|
|
1511
|
-
|
|
1512
|
-
})
|
|
1513
|
-
|
|
1514
|
-
|
|
1723
|
+
connection2.onDidChangeConfiguration(validateDocs);
|
|
1724
|
+
connection2.onDidChangeWatchedFiles(validateDocs);
|
|
1725
|
+
documents.onDidChangeContent(({ document }) => {
|
|
1726
|
+
queueDiagnostic();
|
|
1727
|
+
pendingDiags.add(document);
|
|
1728
|
+
clearCompilerCache(document);
|
|
1515
1729
|
});
|
|
1516
1730
|
connection2.onCompletion(async (params, cancel) => {
|
|
1517
1731
|
return await service.doComplete(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
@@ -1519,27 +1733,56 @@ connection2.onCompletion(async (params, cancel) => {
|
|
|
1519
1733
|
connection2.onDefinition(async (params, cancel) => {
|
|
1520
1734
|
return await service.findDefinition(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
1521
1735
|
});
|
|
1736
|
+
connection2.onDocumentColor(async (params, cancel) => {
|
|
1737
|
+
return await service.findDocumentColors(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
1738
|
+
});
|
|
1739
|
+
connection2.onColorPresentation(async (params, cancel) => {
|
|
1740
|
+
return await service.getColorPresentations(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
1741
|
+
});
|
|
1522
1742
|
connection2.onHover(async (params, cancel) => {
|
|
1523
1743
|
return await service.doHover(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
1524
1744
|
});
|
|
1745
|
+
connection2.onRenameRequest(async (params, cancel) => {
|
|
1746
|
+
return await service.doRename(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
1747
|
+
});
|
|
1748
|
+
connection2.onCodeAction(async (params, cancel) => {
|
|
1749
|
+
return await service.doCodeActions(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
1750
|
+
});
|
|
1525
1751
|
connection2.onDocumentFormatting(async (params, cancel) => {
|
|
1526
1752
|
return await service.format(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
1527
1753
|
});
|
|
1528
|
-
function
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1754
|
+
function validateDocs() {
|
|
1755
|
+
queueDiagnostic();
|
|
1756
|
+
clearCompilerCache();
|
|
1757
|
+
for (const doc of documents.all()) {
|
|
1758
|
+
pendingDiags.add(doc);
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
function queueDiagnostic() {
|
|
1762
|
+
clearTimeout(diagnosticTimeout);
|
|
1763
|
+
const id = diagnosticTimeout = setTimeout(async () => {
|
|
1764
|
+
const results = await Promise.all(documents.all().map(async (doc) => {
|
|
1765
|
+
if (!pendingDiags.delete(doc))
|
|
1766
|
+
return;
|
|
1767
|
+
const prevDiag = prevDiags.get(doc) || [];
|
|
1768
|
+
const nextDiag = await service.doValidate(doc) || [];
|
|
1769
|
+
if ((0, import_util2.isDeepStrictEqual)(prevDiag, nextDiag))
|
|
1770
|
+
return;
|
|
1771
|
+
return [doc, nextDiag];
|
|
1772
|
+
}));
|
|
1773
|
+
if (id === diagnosticTimeout) {
|
|
1774
|
+
for (const result of results) {
|
|
1775
|
+
if (result) {
|
|
1776
|
+
const [doc, diag] = result;
|
|
1777
|
+
prevDiags.set(doc, diag);
|
|
1778
|
+
connection2.sendDiagnostics({
|
|
1779
|
+
uri: doc.uri,
|
|
1780
|
+
diagnostics: diag
|
|
1781
|
+
});
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1535
1784
|
}
|
|
1536
|
-
prevDiagnostics.set(doc, nextDiag);
|
|
1537
|
-
connection2.sendDiagnostics({
|
|
1538
|
-
uri: doc.uri,
|
|
1539
|
-
diagnostics: nextDiag
|
|
1540
|
-
});
|
|
1541
1785
|
}, 400);
|
|
1542
|
-
diagnosticTimeouts.set(doc, id);
|
|
1543
1786
|
}
|
|
1544
1787
|
documents.listen(connection2);
|
|
1545
1788
|
connection2.listen();
|