@marko/language-server 0.12.7 → 0.12.10
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 +768 -113
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +765 -104
- package/dist/index.mjs.map +3 -3
- package/dist/service/marko/complete/AttrValue.d.ts +4 -0
- package/dist/service/marko/document-links/extract.d.ts +8 -0
- package/dist/service/marko/document-links/index.d.ts +2 -0
- package/dist/service/marko/util/is-document-link-attr.d.ts +5 -0
- package/dist/service/stylesheet/extract.d.ts +1 -1
- package/dist/service/stylesheet/index.d.ts +2 -2
- package/dist/service/types.d.ts +9 -1
- package/dist/utils/file-system.d.ts +9 -0
- package/dist/utils/resolve-url.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -575,7 +575,7 @@ function loadCompilerInfo(dir) {
|
|
|
575
575
|
const rootDir = import_lasso_package_root.default.getRootDir(dir);
|
|
576
576
|
const pkgPath = rootDir && import_resolve_from.default.silent(rootDir, "@marko/compiler/package.json");
|
|
577
577
|
const pkg = pkgPath && require(pkgPath);
|
|
578
|
-
const
|
|
578
|
+
const cache3 = /* @__PURE__ */ new Map();
|
|
579
579
|
let translator = builtinTranslator;
|
|
580
580
|
let compiler = builtinCompiler;
|
|
581
581
|
if (pkg && /^5\./.test(pkg.version)) {
|
|
@@ -592,16 +592,16 @@ function loadCompilerInfo(dir) {
|
|
|
592
592
|
}
|
|
593
593
|
}
|
|
594
594
|
return {
|
|
595
|
-
cache:
|
|
595
|
+
cache: cache3,
|
|
596
596
|
get lookup() {
|
|
597
|
-
let lookup =
|
|
597
|
+
let lookup = cache3.get(lookupKey);
|
|
598
598
|
if (lookup === void 0) {
|
|
599
599
|
try {
|
|
600
600
|
lookup = compiler.taglib.buildLookup(dir, translator);
|
|
601
601
|
} catch {
|
|
602
602
|
lookup = builtinInfo.lookup;
|
|
603
603
|
}
|
|
604
|
-
|
|
604
|
+
cache3.set(lookupKey, lookup);
|
|
605
605
|
}
|
|
606
606
|
return lookup;
|
|
607
607
|
},
|
|
@@ -625,10 +625,10 @@ function display(type, data) {
|
|
|
625
625
|
}
|
|
626
626
|
|
|
627
627
|
// src/service/index.ts
|
|
628
|
-
var
|
|
628
|
+
var import_vscode_languageserver13 = require("vscode-languageserver");
|
|
629
629
|
|
|
630
630
|
// src/service/marko/complete/index.ts
|
|
631
|
-
var
|
|
631
|
+
var import_vscode_languageserver5 = require("vscode-languageserver");
|
|
632
632
|
|
|
633
633
|
// src/service/marko/complete/Tag.ts
|
|
634
634
|
var import_vscode_languageserver = require("vscode-languageserver");
|
|
@@ -842,18 +842,146 @@ function AttrName({
|
|
|
842
842
|
return completions;
|
|
843
843
|
}
|
|
844
844
|
|
|
845
|
+
// src/service/marko/complete/AttrValue.ts
|
|
846
|
+
var import_path4 = __toESM(require("path"));
|
|
847
|
+
var import_vscode_languageserver4 = require("vscode-languageserver");
|
|
848
|
+
|
|
849
|
+
// src/service/marko/util/is-document-link-attr.ts
|
|
850
|
+
var linkedAttrs = /* @__PURE__ */ new Map([
|
|
851
|
+
[
|
|
852
|
+
"src",
|
|
853
|
+
/* @__PURE__ */ new Set([
|
|
854
|
+
"audio",
|
|
855
|
+
"embed",
|
|
856
|
+
"iframe",
|
|
857
|
+
"img",
|
|
858
|
+
"input",
|
|
859
|
+
"script",
|
|
860
|
+
"source",
|
|
861
|
+
"track",
|
|
862
|
+
"video"
|
|
863
|
+
])
|
|
864
|
+
],
|
|
865
|
+
["href", /* @__PURE__ */ new Set(["a", "area", "link"])],
|
|
866
|
+
["data", /* @__PURE__ */ new Set(["object"])],
|
|
867
|
+
["poster", /* @__PURE__ */ new Set(["video"])]
|
|
868
|
+
]);
|
|
869
|
+
function isDocumentLinkAttr(doc, tag, attr) {
|
|
870
|
+
var _a, _b;
|
|
871
|
+
return tag.nameText && attr.type === 8 /* AttrNamed */ && ((_a = attr.value) == null ? void 0 : _a.type) === 11 /* AttrValue */ && /^['"]$/.test(doc.getText()[attr.value.value.start]) && ((_b = linkedAttrs.get(doc.getText().slice(attr.name.start, attr.name.end))) == null ? void 0 : _b.has(tag.nameText)) || false;
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
// src/utils/file-system.ts
|
|
875
|
+
var import_path3 = __toESM(require("path"));
|
|
876
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
877
|
+
var import_vscode_css_languageservice = require("vscode-css-languageservice");
|
|
878
|
+
var file_system_default = {
|
|
879
|
+
stat,
|
|
880
|
+
readDirectory
|
|
881
|
+
};
|
|
882
|
+
async function stat(fileName) {
|
|
883
|
+
const stat2 = await import_promises.default.stat(fileName).catch(() => null);
|
|
884
|
+
let type = import_vscode_css_languageservice.FileType.Unknown;
|
|
885
|
+
let ctime = 0;
|
|
886
|
+
let mtime = 0;
|
|
887
|
+
let size = 0;
|
|
888
|
+
if (stat2) {
|
|
889
|
+
if (stat2.isDirectory())
|
|
890
|
+
type = import_vscode_css_languageservice.FileType.Directory;
|
|
891
|
+
else if (stat2.isFile())
|
|
892
|
+
type = import_vscode_css_languageservice.FileType.File;
|
|
893
|
+
ctime = stat2.ctimeMs;
|
|
894
|
+
mtime = stat2.mtimeMs;
|
|
895
|
+
size = stat2.size;
|
|
896
|
+
}
|
|
897
|
+
return {
|
|
898
|
+
type,
|
|
899
|
+
ctime,
|
|
900
|
+
mtime,
|
|
901
|
+
size
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
async function readDirectory(dir) {
|
|
905
|
+
return (await Promise.all((await import_promises.default.readdir(dir).catch(() => [])).map(async (entry) => [entry, (await stat(import_path3.default.join(dir, entry))).type]))).filter(([, type]) => type !== import_vscode_css_languageservice.FileType.Unknown);
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// src/utils/resolve-url.ts
|
|
909
|
+
function resolveUrl(to, base) {
|
|
910
|
+
try {
|
|
911
|
+
const baseUrl = new URL(base, "file://");
|
|
912
|
+
const resolved = new URL(to, baseUrl);
|
|
913
|
+
const { origin, protocol } = baseUrl;
|
|
914
|
+
if (resolved.origin === origin && resolved.protocol === protocol) {
|
|
915
|
+
return resolved.pathname + resolved.search + resolved.hash;
|
|
916
|
+
}
|
|
917
|
+
return resolved.toString();
|
|
918
|
+
} catch {
|
|
919
|
+
return void 0;
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
// src/service/marko/complete/AttrValue.ts
|
|
924
|
+
async function AttrValue({
|
|
925
|
+
document,
|
|
926
|
+
offset,
|
|
927
|
+
node,
|
|
928
|
+
parsed,
|
|
929
|
+
code
|
|
930
|
+
}) {
|
|
931
|
+
const attr = node.parent;
|
|
932
|
+
if (isDocumentLinkAttr(document, attr.parent, attr)) {
|
|
933
|
+
const start = node.value.start + 1;
|
|
934
|
+
if (code[start] !== ".")
|
|
935
|
+
return;
|
|
936
|
+
const end = node.value.end - 1;
|
|
937
|
+
const relativeOffset = offset - start;
|
|
938
|
+
const rawValue = parsed.read({
|
|
939
|
+
start,
|
|
940
|
+
end
|
|
941
|
+
});
|
|
942
|
+
let segmentStart = rawValue.lastIndexOf("/", relativeOffset);
|
|
943
|
+
if (segmentStart === -1)
|
|
944
|
+
segmentStart = relativeOffset;
|
|
945
|
+
const resolveRequest = rawValue.slice(0, segmentStart) || ".";
|
|
946
|
+
const dir = resolveUrl(resolveRequest, document.uri);
|
|
947
|
+
if ((dir == null ? void 0 : dir[0]) === "/") {
|
|
948
|
+
const result = [];
|
|
949
|
+
const curDir = resolveRequest === "." ? dir : resolveUrl(".", document.uri);
|
|
950
|
+
const curFile = curDir === dir ? import_path4.default.basename(document.uri) : void 0;
|
|
951
|
+
const replaceRange = import_vscode_languageserver4.Range.create(document.positionAt(start + segmentStart + 1), document.positionAt(start + rawValue.length));
|
|
952
|
+
for (const [entry, type] of await file_system_default.readDirectory(dir)) {
|
|
953
|
+
if (entry[0] !== "." && entry !== curFile) {
|
|
954
|
+
const isDir = type === import_vscode_css_languageservice.FileType.Directory;
|
|
955
|
+
const label = isDir ? `${entry}/` : entry;
|
|
956
|
+
result.push({
|
|
957
|
+
label,
|
|
958
|
+
kind: isDir ? import_vscode_languageserver4.CompletionItemKind.Folder : import_vscode_languageserver4.CompletionItemKind.File,
|
|
959
|
+
textEdit: import_vscode_languageserver4.TextEdit.replace(replaceRange, label),
|
|
960
|
+
command: isDir ? {
|
|
961
|
+
title: "Suggest",
|
|
962
|
+
command: "editor.action.triggerSuggest"
|
|
963
|
+
} : void 0
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
return result;
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
|
|
845
972
|
// src/service/marko/complete/index.ts
|
|
846
973
|
var handlers = {
|
|
847
974
|
Tag,
|
|
848
975
|
OpenTagName,
|
|
849
|
-
AttrName
|
|
976
|
+
AttrName,
|
|
977
|
+
AttrValue
|
|
850
978
|
};
|
|
851
979
|
var doComplete = async (doc, params) => {
|
|
852
980
|
var _a;
|
|
853
981
|
const parsed = parse2(doc);
|
|
854
982
|
const offset = doc.offsetAt(params.position);
|
|
855
983
|
const node = parsed.nodeAt(offset);
|
|
856
|
-
return
|
|
984
|
+
return import_vscode_languageserver5.CompletionList.create(await ((_a = handlers[NodeType[node.type]]) == null ? void 0 : _a.call(handlers, {
|
|
857
985
|
document: doc,
|
|
858
986
|
params,
|
|
859
987
|
parsed,
|
|
@@ -865,15 +993,15 @@ var doComplete = async (doc, params) => {
|
|
|
865
993
|
};
|
|
866
994
|
|
|
867
995
|
// src/service/marko/validate.ts
|
|
868
|
-
var
|
|
996
|
+
var import_vscode_languageserver6 = require("vscode-languageserver");
|
|
869
997
|
var markoErrorRegExp = /^(.+?)(?:\((\d+)(?:\s*,\s*(\d+))?\))?: (.*)$/gm;
|
|
870
998
|
var doValidate = (doc) => {
|
|
871
999
|
const fsPath = getDocFile(doc);
|
|
872
1000
|
const diagnostics = [];
|
|
873
|
-
const { compiler, translator, cache:
|
|
1001
|
+
const { compiler, translator, cache: cache3 } = getCompilerInfo(doc);
|
|
874
1002
|
try {
|
|
875
1003
|
compiler.compileSync(doc.getText(), fsPath || "untitled.marko", {
|
|
876
|
-
cache:
|
|
1004
|
+
cache: cache3,
|
|
877
1005
|
translator,
|
|
878
1006
|
code: false,
|
|
879
1007
|
output: "source",
|
|
@@ -885,16 +1013,16 @@ var doValidate = (doc) => {
|
|
|
885
1013
|
const [, fileName, rawLine, rawCol, msg] = match;
|
|
886
1014
|
const line = (parseInt(rawLine, 10) || 1) - 1;
|
|
887
1015
|
const col = (parseInt(rawCol, 10) || 1) - 1;
|
|
888
|
-
diagnostics.push(
|
|
1016
|
+
diagnostics.push(import_vscode_languageserver6.Diagnostic.create(import_vscode_languageserver6.Range.create(line, col, line, col), msg, import_vscode_languageserver6.DiagnosticSeverity.Error, void 0, fileName));
|
|
889
1017
|
}
|
|
890
1018
|
}
|
|
891
1019
|
return diagnostics;
|
|
892
1020
|
};
|
|
893
1021
|
|
|
894
1022
|
// src/service/marko/definition/OpenTagName.ts
|
|
895
|
-
var
|
|
1023
|
+
var import_path5 = __toESM(require("path"));
|
|
896
1024
|
var import_vscode_uri4 = require("vscode-uri");
|
|
897
|
-
var
|
|
1025
|
+
var import_vscode_languageserver8 = require("vscode-languageserver");
|
|
898
1026
|
|
|
899
1027
|
// src/utils/regexp-builder.ts
|
|
900
1028
|
function RegExpBuilder(strings, ...expressions) {
|
|
@@ -923,9 +1051,9 @@ function escape(val) {
|
|
|
923
1051
|
// src/utils/utils.ts
|
|
924
1052
|
var import_fs = __toESM(require("fs"));
|
|
925
1053
|
var import_vscode_uri3 = require("vscode-uri");
|
|
926
|
-
var
|
|
1054
|
+
var import_vscode_languageserver7 = require("vscode-languageserver");
|
|
927
1055
|
var import_vscode_languageserver_textdocument = require("vscode-languageserver-textdocument");
|
|
928
|
-
var START_OF_FILE =
|
|
1056
|
+
var START_OF_FILE = import_vscode_languageserver7.Range.create(import_vscode_languageserver7.Position.create(0, 0), import_vscode_languageserver7.Position.create(0, 0));
|
|
929
1057
|
function createTextDocument(filename) {
|
|
930
1058
|
const uri = import_vscode_uri3.URI.file(filename).toString();
|
|
931
1059
|
const content = import_fs.default.readFileSync(filename, "utf-8");
|
|
@@ -953,24 +1081,24 @@ function OpenTagName2({
|
|
|
953
1081
|
return;
|
|
954
1082
|
}
|
|
955
1083
|
const tagEntryFile = tagDef.template || tagDef.renderer || tagDef.filePath;
|
|
956
|
-
if (!
|
|
1084
|
+
if (!import_path5.default.isAbsolute(tagEntryFile)) {
|
|
957
1085
|
return;
|
|
958
1086
|
}
|
|
959
1087
|
if (/\/marko(?:-tag)?\.json$/.test(tagEntryFile)) {
|
|
960
1088
|
const tagDefDoc = createTextDocument(tagEntryFile);
|
|
961
1089
|
const match = RegExpBuilder`/"(?:<${tag.nameText}>|${tag.nameText})"\s*:\s*[^\r\n,]+/g`.exec(tagDefDoc.getText());
|
|
962
1090
|
if (match && match.index) {
|
|
963
|
-
range =
|
|
1091
|
+
range = import_vscode_languageserver8.Range.create(tagDefDoc.positionAt(match.index), tagDefDoc.positionAt(match.index + match[0].length));
|
|
964
1092
|
}
|
|
965
1093
|
}
|
|
966
1094
|
return [
|
|
967
|
-
|
|
1095
|
+
import_vscode_languageserver8.LocationLink.create(import_vscode_uri4.URI.file(tagEntryFile).toString(), range, range, parsed.locationAt(node))
|
|
968
1096
|
];
|
|
969
1097
|
}
|
|
970
1098
|
|
|
971
1099
|
// src/service/marko/definition/AttrName.ts
|
|
972
1100
|
var import_vscode_uri5 = require("vscode-uri");
|
|
973
|
-
var
|
|
1101
|
+
var import_vscode_languageserver9 = require("vscode-languageserver");
|
|
974
1102
|
function AttrName2({
|
|
975
1103
|
lookup,
|
|
976
1104
|
parsed,
|
|
@@ -994,11 +1122,11 @@ function AttrName2({
|
|
|
994
1122
|
const tagDefDoc = createTextDocument(attrEntryFile);
|
|
995
1123
|
const match = RegExpBuilder`/"@${attrName}"\s*:\s*[^\r\n,]+/g`.exec(tagDefDoc.getText());
|
|
996
1124
|
if (match && match.index) {
|
|
997
|
-
range =
|
|
1125
|
+
range = import_vscode_languageserver9.Range.create(tagDefDoc.positionAt(match.index), tagDefDoc.positionAt(match.index + match[0].length));
|
|
998
1126
|
}
|
|
999
1127
|
}
|
|
1000
1128
|
return [
|
|
1001
|
-
|
|
1129
|
+
import_vscode_languageserver9.LocationLink.create(import_vscode_uri5.URI.file(attrEntryFile).toString(), range, range, parsed.locationAt(node))
|
|
1002
1130
|
];
|
|
1003
1131
|
}
|
|
1004
1132
|
|
|
@@ -1023,17 +1151,83 @@ var findDefinition = async (doc, params) => {
|
|
|
1023
1151
|
})) || [];
|
|
1024
1152
|
};
|
|
1025
1153
|
|
|
1026
|
-
// src/service/marko/
|
|
1027
|
-
var
|
|
1154
|
+
// src/service/marko/document-links/extract.ts
|
|
1155
|
+
var import_vscode_languageserver10 = require("vscode-languageserver");
|
|
1028
1156
|
var import_vscode_uri6 = require("vscode-uri");
|
|
1157
|
+
var importTagReg = /(['"])<((?:[^\1\\>]+|\\.)*)>?\1/g;
|
|
1158
|
+
function extractDocumentLinks(doc, parsed, lookup) {
|
|
1159
|
+
if (import_vscode_uri6.URI.parse(doc.uri).scheme === "untitled") {
|
|
1160
|
+
return [];
|
|
1161
|
+
}
|
|
1162
|
+
const links = [];
|
|
1163
|
+
const { program } = parsed;
|
|
1164
|
+
const code = doc.getText();
|
|
1165
|
+
const read = (range) => code.slice(range.start, range.end);
|
|
1166
|
+
const visit = (node) => {
|
|
1167
|
+
switch (node.type) {
|
|
1168
|
+
case 1 /* Tag */:
|
|
1169
|
+
if (node.attrs && node.nameText) {
|
|
1170
|
+
for (const attr of node.attrs) {
|
|
1171
|
+
if (isDocumentLinkAttr(doc, node, attr)) {
|
|
1172
|
+
links.push(import_vscode_languageserver10.DocumentLink.create({
|
|
1173
|
+
start: parsed.positionAt(attr.value.value.start),
|
|
1174
|
+
end: parsed.positionAt(attr.value.value.end)
|
|
1175
|
+
}, resolveUrl(read(attr.value.value).slice(1, -1), doc.uri)));
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
if (node.body) {
|
|
1180
|
+
for (const child of node.body) {
|
|
1181
|
+
visit(child);
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
break;
|
|
1185
|
+
}
|
|
1186
|
+
};
|
|
1187
|
+
for (const item of program.static) {
|
|
1188
|
+
if (item.type === 20 /* Statement */ && code[item.start] === "i") {
|
|
1189
|
+
importTagReg.lastIndex = 0;
|
|
1190
|
+
const value = parsed.read(item);
|
|
1191
|
+
const match = importTagReg.exec(value);
|
|
1192
|
+
if (match) {
|
|
1193
|
+
const [{ length }, , tagName] = match;
|
|
1194
|
+
const tagDef = lookup.getTag(tagName);
|
|
1195
|
+
const fileForTag = tagDef && (tagDef.template || tagDef.renderer);
|
|
1196
|
+
if (fileForTag) {
|
|
1197
|
+
links.push(import_vscode_languageserver10.DocumentLink.create({
|
|
1198
|
+
start: parsed.positionAt(item.start + match.index),
|
|
1199
|
+
end: parsed.positionAt(item.start + match.index + length)
|
|
1200
|
+
}, fileForTag));
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
for (const item of program.body) {
|
|
1206
|
+
visit(item);
|
|
1207
|
+
}
|
|
1208
|
+
return links;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
// src/service/marko/document-links/index.ts
|
|
1212
|
+
var cache = /* @__PURE__ */ new WeakMap();
|
|
1213
|
+
var findDocumentLinks = async (doc) => {
|
|
1214
|
+
const parsed = parse2(doc);
|
|
1215
|
+
let result = cache.get(parsed);
|
|
1216
|
+
if (!result) {
|
|
1217
|
+
result = extractDocumentLinks(doc, parsed, getCompilerInfo(doc).lookup);
|
|
1218
|
+
cache.set(parsed, result);
|
|
1219
|
+
}
|
|
1220
|
+
return result;
|
|
1221
|
+
};
|
|
1222
|
+
|
|
1223
|
+
// src/service/marko/format.ts
|
|
1224
|
+
var import_vscode_languageserver11 = require("vscode-languageserver");
|
|
1225
|
+
var import_vscode_uri7 = require("vscode-uri");
|
|
1029
1226
|
var prettier = __toESM(require("prettier"));
|
|
1030
1227
|
var markoPrettier = __toESM(require("prettier-plugin-marko"));
|
|
1031
|
-
var
|
|
1032
|
-
import_vscode_languageserver9.TextEdit.replace(import_vscode_languageserver9.Range.create(import_vscode_languageserver9.Position.create(0, 0), import_vscode_languageserver9.Position.create(0, 0)), "")
|
|
1033
|
-
];
|
|
1034
|
-
var format2 = async (doc, params, token) => {
|
|
1228
|
+
var format2 = async (doc, params, cancel) => {
|
|
1035
1229
|
try {
|
|
1036
|
-
const { fsPath, scheme } =
|
|
1230
|
+
const { fsPath, scheme } = import_vscode_uri7.URI.parse(doc.uri);
|
|
1037
1231
|
const text = doc.getText();
|
|
1038
1232
|
const options = {
|
|
1039
1233
|
parser: "marko",
|
|
@@ -1045,15 +1239,14 @@ var format2 = async (doc, params, token) => {
|
|
|
1045
1239
|
editorconfig: true
|
|
1046
1240
|
}).catch(() => null) : null
|
|
1047
1241
|
};
|
|
1048
|
-
if (
|
|
1049
|
-
return
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1242
|
+
if (cancel.isCancellationRequested)
|
|
1243
|
+
return;
|
|
1244
|
+
return [
|
|
1245
|
+
import_vscode_languageserver11.TextEdit.replace(import_vscode_languageserver11.Range.create(doc.positionAt(0), doc.positionAt(text.length)), prettier.format(text, options))
|
|
1246
|
+
];
|
|
1053
1247
|
} catch (e) {
|
|
1054
1248
|
displayError(e);
|
|
1055
1249
|
}
|
|
1056
|
-
return NO_EDIT;
|
|
1057
1250
|
};
|
|
1058
1251
|
|
|
1059
1252
|
// src/service/marko/index.ts
|
|
@@ -1061,12 +1254,13 @@ var marko_default = {
|
|
|
1061
1254
|
doComplete,
|
|
1062
1255
|
doValidate,
|
|
1063
1256
|
findDefinition,
|
|
1257
|
+
findDocumentLinks,
|
|
1064
1258
|
format: format2
|
|
1065
1259
|
};
|
|
1066
1260
|
|
|
1067
1261
|
// src/service/stylesheet/index.ts
|
|
1068
|
-
var
|
|
1069
|
-
var
|
|
1262
|
+
var import_vscode_languageserver12 = require("vscode-languageserver");
|
|
1263
|
+
var import_vscode_css_languageservice2 = require("vscode-css-languageservice");
|
|
1070
1264
|
var import_vscode_languageserver_textdocument2 = require("vscode-languageserver-textdocument");
|
|
1071
1265
|
|
|
1072
1266
|
// src/utils/extractor.ts
|
|
@@ -1129,7 +1323,7 @@ function createExtractor(code) {
|
|
|
1129
1323
|
const generatedStart = generatedMap[key];
|
|
1130
1324
|
const sourceStart = generatedMap[key + 1];
|
|
1131
1325
|
const sourceEnd = generatedMap[key + 2];
|
|
1132
|
-
return sourceEnd - sourceStart
|
|
1326
|
+
return sourceEnd - sourceStart < generatedOffset - generatedStart ? void 0 : sourceStart + (generatedOffset - generatedStart);
|
|
1133
1327
|
},
|
|
1134
1328
|
generatedOffsetAt(sourceOffset) {
|
|
1135
1329
|
let max = sourceMap.length / 3;
|
|
@@ -1169,10 +1363,20 @@ function extractStyleSheets(code, program, lookup) {
|
|
|
1169
1363
|
}).replace(/^.*\./, "") : "css";
|
|
1170
1364
|
};
|
|
1171
1365
|
const visit = (node) => {
|
|
1172
|
-
var _a, _b
|
|
1366
|
+
var _a, _b;
|
|
1173
1367
|
switch (node.type) {
|
|
1174
1368
|
case 1 /* Tag */:
|
|
1175
|
-
if (
|
|
1369
|
+
if (node.nameText === "style" && node.concise && node.attrs) {
|
|
1370
|
+
const block = node.attrs.at(-1);
|
|
1371
|
+
if (block.type === 8 /* AttrNamed */ && code[block.start] === "{") {
|
|
1372
|
+
getExtractor(getFileExtFromTag(node)).write`${{
|
|
1373
|
+
start: block.start + 1,
|
|
1374
|
+
end: block.end - 1
|
|
1375
|
+
}}`;
|
|
1376
|
+
break;
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
if (node.body) {
|
|
1176
1380
|
if (node.nameText === "style") {
|
|
1177
1381
|
const ext = getFileExtFromTag(node);
|
|
1178
1382
|
for (const child of node.body) {
|
|
@@ -1186,30 +1390,22 @@ function extractStyleSheets(code, program, lookup) {
|
|
|
1186
1390
|
}
|
|
1187
1391
|
}
|
|
1188
1392
|
} else {
|
|
1189
|
-
if (node.attrs) {
|
|
1190
|
-
for (const attr of node.attrs) {
|
|
1191
|
-
if (attr.type === 8 /* AttrNamed */ && ((_b = attr.value) == null ? void 0 : _b.type) === 11 /* AttrValue */ && /^['"]$/.test(code[attr.value.value.start])) {
|
|
1192
|
-
const name = read(attr.name);
|
|
1193
|
-
if (name === "#style" || name === "style" && lookup && node.nameText && name === "style" && ((_c = lookup.getTag(node.nameText)) == null ? void 0 : _c.html)) {
|
|
1194
|
-
getExtractor("css").write`:root{${{
|
|
1195
|
-
start: attr.value.value.start + 1,
|
|
1196
|
-
end: attr.value.value.end - 1
|
|
1197
|
-
}}}`;
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
1393
|
for (const child of node.body) {
|
|
1203
1394
|
visit(child);
|
|
1204
1395
|
}
|
|
1205
1396
|
}
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1397
|
+
}
|
|
1398
|
+
if (node.attrs) {
|
|
1399
|
+
for (const attr of node.attrs) {
|
|
1400
|
+
if (attr.type === 8 /* AttrNamed */ && ((_a = attr.value) == null ? void 0 : _a.type) === 11 /* AttrValue */ && /^['"]$/.test(code[attr.value.value.start])) {
|
|
1401
|
+
const name = read(attr.name);
|
|
1402
|
+
if (name === "#style" || name === "style" && node.nameText && name === "style" && ((_b = lookup.getTag(node.nameText)) == null ? void 0 : _b.html)) {
|
|
1403
|
+
getExtractor("css").write`:root{${{
|
|
1404
|
+
start: attr.value.value.start + 1,
|
|
1405
|
+
end: attr.value.value.end - 1
|
|
1406
|
+
}}}`;
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1213
1409
|
}
|
|
1214
1410
|
}
|
|
1215
1411
|
break;
|
|
@@ -1225,13 +1421,17 @@ function extractStyleSheets(code, program, lookup) {
|
|
|
1225
1421
|
}
|
|
1226
1422
|
|
|
1227
1423
|
// src/service/stylesheet/index.ts
|
|
1228
|
-
var
|
|
1424
|
+
var cache2 = /* @__PURE__ */ new WeakMap();
|
|
1229
1425
|
var services = {
|
|
1230
|
-
css:
|
|
1231
|
-
less:
|
|
1232
|
-
scss:
|
|
1426
|
+
css: import_vscode_css_languageservice2.getCSSLanguageService,
|
|
1427
|
+
less: import_vscode_css_languageservice2.getLESSLanguageService,
|
|
1428
|
+
scss: import_vscode_css_languageservice2.getSCSSLanguageService
|
|
1233
1429
|
};
|
|
1234
|
-
var
|
|
1430
|
+
var clientCapabilities;
|
|
1431
|
+
var StyleSheetService = {
|
|
1432
|
+
initialize(params) {
|
|
1433
|
+
clientCapabilities = params.capabilities;
|
|
1434
|
+
},
|
|
1235
1435
|
async doComplete(doc, params) {
|
|
1236
1436
|
const infoByExt = getStyleSheetInfo(doc);
|
|
1237
1437
|
const sourceOffset = doc.offsetAt(params.position);
|
|
@@ -1241,37 +1441,31 @@ var stylesheet_default = {
|
|
|
1241
1441
|
if (generatedOffset === void 0)
|
|
1242
1442
|
continue;
|
|
1243
1443
|
const { service: service2, virtualDoc } = info;
|
|
1244
|
-
const result = service2.
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1444
|
+
const result = await service2.doComplete2(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed, { resolveReference: resolveUrl });
|
|
1445
|
+
if (result.itemDefaults) {
|
|
1446
|
+
const { editRange } = result.itemDefaults;
|
|
1447
|
+
if (editRange) {
|
|
1448
|
+
if ("start" in editRange) {
|
|
1449
|
+
result.itemDefaults.editRange = getSourceRange(doc, info, editRange);
|
|
1450
|
+
} else {
|
|
1451
|
+
editRange.insert = getSourceRange(doc, info, editRange.insert);
|
|
1452
|
+
editRange.replace = getSourceRange(doc, info, editRange.replace);
|
|
1252
1453
|
}
|
|
1253
1454
|
}
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
}
|
|
1262
|
-
if (textEdit.insert) {
|
|
1263
|
-
if (!updateRange(doc, info, textEdit.insert)) {
|
|
1264
|
-
textEdit.newText = "";
|
|
1265
|
-
textEdit.insert = START_OF_FILE;
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1455
|
+
}
|
|
1456
|
+
for (const item of result.items) {
|
|
1457
|
+
if (item.textEdit) {
|
|
1458
|
+
item.textEdit = getSourceInsertReplaceEdit(doc, info, item.textEdit);
|
|
1459
|
+
}
|
|
1460
|
+
if (item.additionalTextEdits) {
|
|
1461
|
+
item.additionalTextEdits = getSourceEdits(doc, info, item.additionalTextEdits);
|
|
1268
1462
|
}
|
|
1269
1463
|
}
|
|
1270
1464
|
return result;
|
|
1271
1465
|
}
|
|
1272
|
-
return
|
|
1466
|
+
return import_vscode_languageserver12.CompletionList.create([], true);
|
|
1273
1467
|
},
|
|
1274
|
-
|
|
1468
|
+
findDefinition(doc, params) {
|
|
1275
1469
|
const infoByExt = getStyleSheetInfo(doc);
|
|
1276
1470
|
const sourceOffset = doc.offsetAt(params.position);
|
|
1277
1471
|
for (const ext in infoByExt) {
|
|
@@ -1281,13 +1475,19 @@ var stylesheet_default = {
|
|
|
1281
1475
|
continue;
|
|
1282
1476
|
const { service: service2, virtualDoc } = info;
|
|
1283
1477
|
const result = service2.findDefinition(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed);
|
|
1284
|
-
if (result
|
|
1285
|
-
|
|
1478
|
+
if (result) {
|
|
1479
|
+
const range = getSourceRange(doc, info, result.range);
|
|
1480
|
+
if (range) {
|
|
1481
|
+
return {
|
|
1482
|
+
range,
|
|
1483
|
+
uri: doc.uri
|
|
1484
|
+
};
|
|
1485
|
+
}
|
|
1286
1486
|
}
|
|
1287
1487
|
break;
|
|
1288
1488
|
}
|
|
1289
1489
|
},
|
|
1290
|
-
|
|
1490
|
+
findReferences(doc, params) {
|
|
1291
1491
|
const infoByExt = getStyleSheetInfo(doc);
|
|
1292
1492
|
const sourceOffset = doc.offsetAt(params.position);
|
|
1293
1493
|
for (const ext in infoByExt) {
|
|
@@ -1296,45 +1496,269 @@ var stylesheet_default = {
|
|
|
1296
1496
|
if (generatedOffset === void 0)
|
|
1297
1497
|
continue;
|
|
1298
1498
|
const { service: service2, virtualDoc } = info;
|
|
1299
|
-
const result =
|
|
1300
|
-
|
|
1301
|
-
|
|
1499
|
+
const result = [];
|
|
1500
|
+
for (const location of service2.findReferences(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed)) {
|
|
1501
|
+
const range = getSourceRange(doc, info, location.range);
|
|
1502
|
+
if (range) {
|
|
1503
|
+
result.push({
|
|
1504
|
+
range,
|
|
1505
|
+
uri: location.uri
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
1302
1508
|
}
|
|
1509
|
+
return result.length ? result : void 0;
|
|
1303
1510
|
}
|
|
1304
1511
|
},
|
|
1305
|
-
|
|
1512
|
+
findDocumentLinks(doc) {
|
|
1513
|
+
const infoByExt = getStyleSheetInfo(doc);
|
|
1514
|
+
const result = [];
|
|
1515
|
+
for (const ext in infoByExt) {
|
|
1516
|
+
const info = infoByExt[ext];
|
|
1517
|
+
const { service: service2, virtualDoc } = info;
|
|
1518
|
+
for (const link of service2.findDocumentLinks(virtualDoc, info.parsed, {
|
|
1519
|
+
resolveReference: resolveUrl
|
|
1520
|
+
})) {
|
|
1521
|
+
const range = getSourceRange(doc, info, link.range);
|
|
1522
|
+
if (range) {
|
|
1523
|
+
result.push({
|
|
1524
|
+
range,
|
|
1525
|
+
target: link.target,
|
|
1526
|
+
tooltip: link.tooltip,
|
|
1527
|
+
data: link.data
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
return result.length ? result : void 0;
|
|
1533
|
+
},
|
|
1534
|
+
findDocumentHighlights(doc, params) {
|
|
1535
|
+
const infoByExt = getStyleSheetInfo(doc);
|
|
1536
|
+
const sourceOffset = doc.offsetAt(params.position);
|
|
1537
|
+
for (const ext in infoByExt) {
|
|
1538
|
+
const info = infoByExt[ext];
|
|
1539
|
+
const generatedOffset = info.generatedOffsetAt(sourceOffset);
|
|
1540
|
+
if (generatedOffset === void 0)
|
|
1541
|
+
continue;
|
|
1542
|
+
const { service: service2, virtualDoc } = info;
|
|
1543
|
+
const result = [];
|
|
1544
|
+
for (const highlight of service2.findDocumentHighlights(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed)) {
|
|
1545
|
+
const range = getSourceRange(doc, info, highlight.range);
|
|
1546
|
+
if (range) {
|
|
1547
|
+
result.push({
|
|
1548
|
+
range,
|
|
1549
|
+
kind: highlight.kind
|
|
1550
|
+
});
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
return result.length ? result : void 0;
|
|
1554
|
+
}
|
|
1555
|
+
},
|
|
1556
|
+
findDocumentColors(doc) {
|
|
1557
|
+
const infoByExt = getStyleSheetInfo(doc);
|
|
1558
|
+
const result = [];
|
|
1559
|
+
for (const ext in infoByExt) {
|
|
1560
|
+
const info = infoByExt[ext];
|
|
1561
|
+
const { service: service2, virtualDoc } = info;
|
|
1562
|
+
for (const colorInfo of service2.findDocumentColors(virtualDoc, info.parsed)) {
|
|
1563
|
+
const range = getSourceRange(doc, info, colorInfo.range);
|
|
1564
|
+
if (range) {
|
|
1565
|
+
result.push({
|
|
1566
|
+
range,
|
|
1567
|
+
color: colorInfo.color
|
|
1568
|
+
});
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
return result.length ? result : void 0;
|
|
1573
|
+
},
|
|
1574
|
+
getColorPresentations(doc, params) {
|
|
1575
|
+
const infoByExt = getStyleSheetInfo(doc);
|
|
1576
|
+
const sourceOffset = doc.offsetAt(params.range.start);
|
|
1577
|
+
for (const ext in infoByExt) {
|
|
1578
|
+
const info = infoByExt[ext];
|
|
1579
|
+
const generatedOffsetStart = info.generatedOffsetAt(sourceOffset);
|
|
1580
|
+
if (generatedOffsetStart === void 0)
|
|
1581
|
+
continue;
|
|
1582
|
+
const generatedOffsetEnd = info.generatedOffsetAt(doc.offsetAt(params.range.end));
|
|
1583
|
+
if (generatedOffsetEnd === void 0)
|
|
1584
|
+
continue;
|
|
1585
|
+
const { service: service2, virtualDoc } = info;
|
|
1586
|
+
const result = [];
|
|
1587
|
+
for (const colorPresentation of service2.getColorPresentations(virtualDoc, info.parsed, params.color, import_vscode_languageserver12.Range.create(virtualDoc.positionAt(generatedOffsetStart), virtualDoc.positionAt(generatedOffsetEnd)))) {
|
|
1588
|
+
const textEdit = colorPresentation.textEdit && getSourceEdit(doc, info, colorPresentation.textEdit);
|
|
1589
|
+
const additionalTextEdits = colorPresentation.additionalTextEdits && getSourceEdits(doc, info, colorPresentation.additionalTextEdits);
|
|
1590
|
+
if (textEdit || additionalTextEdits) {
|
|
1591
|
+
result.push({
|
|
1592
|
+
label: colorPresentation.label,
|
|
1593
|
+
textEdit,
|
|
1594
|
+
additionalTextEdits
|
|
1595
|
+
});
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
return result.length ? result : void 0;
|
|
1599
|
+
}
|
|
1600
|
+
},
|
|
1601
|
+
doHover(doc, params) {
|
|
1602
|
+
const infoByExt = getStyleSheetInfo(doc);
|
|
1603
|
+
const sourceOffset = doc.offsetAt(params.position);
|
|
1604
|
+
for (const ext in infoByExt) {
|
|
1605
|
+
const info = infoByExt[ext];
|
|
1606
|
+
const generatedOffset = info.generatedOffsetAt(sourceOffset);
|
|
1607
|
+
if (generatedOffset === void 0)
|
|
1608
|
+
continue;
|
|
1609
|
+
const { service: service2, virtualDoc } = info;
|
|
1610
|
+
const result = service2.doHover(virtualDoc, virtualDoc.positionAt(generatedOffset), info.parsed);
|
|
1611
|
+
if (result) {
|
|
1612
|
+
if (result.range) {
|
|
1613
|
+
const range = getSourceRange(doc, info, result.range);
|
|
1614
|
+
if (range) {
|
|
1615
|
+
return {
|
|
1616
|
+
range,
|
|
1617
|
+
contents: result.contents
|
|
1618
|
+
};
|
|
1619
|
+
}
|
|
1620
|
+
} else {
|
|
1621
|
+
return result;
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
},
|
|
1626
|
+
async doRename(doc, params) {
|
|
1627
|
+
const infoByExt = getStyleSheetInfo(doc);
|
|
1628
|
+
const sourceOffset = doc.offsetAt(params.position);
|
|
1629
|
+
for (const ext in infoByExt) {
|
|
1630
|
+
const info = infoByExt[ext];
|
|
1631
|
+
const generatedOffset = info.generatedOffsetAt(sourceOffset);
|
|
1632
|
+
if (generatedOffset === void 0)
|
|
1633
|
+
continue;
|
|
1634
|
+
const { service: service2, virtualDoc } = info;
|
|
1635
|
+
const result = service2.doRename(virtualDoc, virtualDoc.positionAt(generatedOffset), params.newName, info.parsed);
|
|
1636
|
+
if (result.changes) {
|
|
1637
|
+
for (const uri in result.changes) {
|
|
1638
|
+
if (uri === doc.uri) {
|
|
1639
|
+
result.changes[uri] = getSourceEdits(doc, info, result.changes[uri]) || [];
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
if (result.documentChanges) {
|
|
1644
|
+
for (const change of result.documentChanges) {
|
|
1645
|
+
if (import_vscode_languageserver12.TextDocumentEdit.is(change)) {
|
|
1646
|
+
if (change.textDocument.uri === doc.uri) {
|
|
1647
|
+
change.edits = getSourceEdits(doc, info, change.edits) || [];
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
return result;
|
|
1653
|
+
}
|
|
1654
|
+
},
|
|
1655
|
+
doCodeActions(doc, params) {
|
|
1656
|
+
var _a;
|
|
1657
|
+
const infoByExt = getStyleSheetInfo(doc);
|
|
1658
|
+
const sourceOffset = doc.offsetAt(params.range.start);
|
|
1659
|
+
for (const ext in infoByExt) {
|
|
1660
|
+
const info = infoByExt[ext];
|
|
1661
|
+
const generatedOffsetStart = info.generatedOffsetAt(sourceOffset);
|
|
1662
|
+
if (generatedOffsetStart === void 0)
|
|
1663
|
+
continue;
|
|
1664
|
+
const generatedOffsetEnd = info.generatedOffsetAt(doc.offsetAt(params.range.end));
|
|
1665
|
+
if (generatedOffsetEnd === void 0)
|
|
1666
|
+
continue;
|
|
1667
|
+
const { service: service2, virtualDoc } = info;
|
|
1668
|
+
const result = service2.doCodeActions(virtualDoc, import_vscode_languageserver12.Range.create(virtualDoc.positionAt(generatedOffsetStart), virtualDoc.positionAt(generatedOffsetEnd)), params.context, info.parsed);
|
|
1669
|
+
for (const command of result) {
|
|
1670
|
+
const edits = (_a = command.arguments) == null ? void 0 : _a[2];
|
|
1671
|
+
if (edits && Array.isArray(edits) && isTextEdit(edits[0])) {
|
|
1672
|
+
command.arguments[2] = getSourceEdits(doc, info, edits);
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
return result;
|
|
1676
|
+
}
|
|
1677
|
+
},
|
|
1678
|
+
doValidate(doc) {
|
|
1306
1679
|
const infoByExt = getStyleSheetInfo(doc);
|
|
1307
1680
|
const result = [];
|
|
1308
1681
|
for (const ext in infoByExt) {
|
|
1309
1682
|
const info = infoByExt[ext];
|
|
1310
1683
|
for (const diag of info.service.doValidation(info.virtualDoc, info.parsed)) {
|
|
1311
|
-
|
|
1684
|
+
const range = getSourceRange(doc, info, diag.range);
|
|
1685
|
+
if (range) {
|
|
1686
|
+
diag.range = range;
|
|
1312
1687
|
result.push(diag);
|
|
1313
1688
|
}
|
|
1314
1689
|
}
|
|
1315
1690
|
}
|
|
1316
|
-
return result;
|
|
1691
|
+
return result.length ? result : void 0;
|
|
1317
1692
|
}
|
|
1318
1693
|
};
|
|
1319
|
-
function
|
|
1694
|
+
function getSourceEdits(doc, info, edits) {
|
|
1695
|
+
const result = [];
|
|
1696
|
+
for (const edit of edits) {
|
|
1697
|
+
const sourceEdit = getSourceEdit(doc, info, edit);
|
|
1698
|
+
if (sourceEdit) {
|
|
1699
|
+
result.push(sourceEdit);
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
return result.length ? result : void 0;
|
|
1703
|
+
}
|
|
1704
|
+
function getSourceEdit(doc, info, textEdit) {
|
|
1705
|
+
const range = getSourceRange(doc, info, textEdit.range);
|
|
1706
|
+
if (range) {
|
|
1707
|
+
return {
|
|
1708
|
+
newText: textEdit.newText,
|
|
1709
|
+
range
|
|
1710
|
+
};
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
function getSourceInsertReplaceEdit(doc, info, textEdit) {
|
|
1714
|
+
if (isTextEdit(textEdit)) {
|
|
1715
|
+
return getSourceEdit(doc, info, textEdit);
|
|
1716
|
+
} else if (textEdit.replace) {
|
|
1717
|
+
const range = getSourceRange(doc, info, textEdit.replace);
|
|
1718
|
+
if (range) {
|
|
1719
|
+
return {
|
|
1720
|
+
newText: textEdit.newText,
|
|
1721
|
+
replace: range
|
|
1722
|
+
};
|
|
1723
|
+
}
|
|
1724
|
+
} else {
|
|
1725
|
+
const range = getSourceRange(doc, info, textEdit.insert);
|
|
1726
|
+
if (range) {
|
|
1727
|
+
return {
|
|
1728
|
+
newText: textEdit.newText,
|
|
1729
|
+
insert: range
|
|
1730
|
+
};
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
function getSourceRange(doc, info, range) {
|
|
1320
1735
|
const start = info.sourceOffsetAt(info.virtualDoc.offsetAt(range.start));
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1736
|
+
if (start === void 0)
|
|
1737
|
+
return;
|
|
1738
|
+
let end = start;
|
|
1739
|
+
if (range.start.line !== range.end.line || range.start.character !== range.end.character) {
|
|
1740
|
+
end = info.sourceOffsetAt(info.virtualDoc.offsetAt(range.end));
|
|
1741
|
+
if (end === void 0)
|
|
1742
|
+
return;
|
|
1326
1743
|
}
|
|
1327
|
-
|
|
1744
|
+
const pos = doc.positionAt(start);
|
|
1745
|
+
return {
|
|
1746
|
+
start: pos,
|
|
1747
|
+
end: start === end ? pos : doc.positionAt(end)
|
|
1748
|
+
};
|
|
1328
1749
|
}
|
|
1329
1750
|
function getStyleSheetInfo(doc) {
|
|
1330
1751
|
var _a;
|
|
1331
1752
|
const parsed = parse2(doc);
|
|
1332
|
-
let cached =
|
|
1753
|
+
let cached = cache2.get(parsed);
|
|
1333
1754
|
if (!cached) {
|
|
1334
1755
|
const results = extractStyleSheets(doc.getText(), parsed.program, getCompilerInfo(doc).lookup);
|
|
1335
1756
|
cached = {};
|
|
1336
1757
|
for (const ext in results) {
|
|
1337
|
-
const service2 = (_a = services[ext]) == null ? void 0 : _a.call(services
|
|
1758
|
+
const service2 = (_a = services[ext]) == null ? void 0 : _a.call(services, {
|
|
1759
|
+
fileSystemProvider: file_system_default,
|
|
1760
|
+
clientCapabilities
|
|
1761
|
+
});
|
|
1338
1762
|
if (!service2)
|
|
1339
1763
|
continue;
|
|
1340
1764
|
const { generated, sourceOffsetAt, generatedOffsetAt } = results[ext];
|
|
@@ -1347,16 +1771,25 @@ function getStyleSheetInfo(doc) {
|
|
|
1347
1771
|
parsed: service2.parseStylesheet(virtualDoc)
|
|
1348
1772
|
};
|
|
1349
1773
|
}
|
|
1350
|
-
|
|
1774
|
+
cache2.set(parsed, cached);
|
|
1351
1775
|
}
|
|
1352
1776
|
return cached;
|
|
1353
1777
|
}
|
|
1778
|
+
function isTextEdit(edit) {
|
|
1779
|
+
return edit.range !== void 0;
|
|
1780
|
+
}
|
|
1354
1781
|
|
|
1355
1782
|
// src/service/index.ts
|
|
1356
|
-
var plugins = [marko_default,
|
|
1783
|
+
var plugins = [marko_default, StyleSheetService];
|
|
1357
1784
|
var service = {
|
|
1785
|
+
async initialize(params) {
|
|
1786
|
+
await Promise.all(plugins.map((plugin) => {
|
|
1787
|
+
var _a;
|
|
1788
|
+
return (_a = plugin.initialize) == null ? void 0 : _a.call(plugin, params);
|
|
1789
|
+
}));
|
|
1790
|
+
},
|
|
1358
1791
|
async doComplete(doc, params, cancel) {
|
|
1359
|
-
const result =
|
|
1792
|
+
const result = import_vscode_languageserver13.CompletionList.create([], false);
|
|
1360
1793
|
try {
|
|
1361
1794
|
const requests = plugins.map((plugin) => {
|
|
1362
1795
|
var _a;
|
|
@@ -1365,7 +1798,7 @@ var service = {
|
|
|
1365
1798
|
for (const pending of requests) {
|
|
1366
1799
|
const cur = await pending;
|
|
1367
1800
|
if (cancel.isCancellationRequested)
|
|
1368
|
-
|
|
1801
|
+
return;
|
|
1369
1802
|
if (cur) {
|
|
1370
1803
|
let items;
|
|
1371
1804
|
if (Array.isArray(cur)) {
|
|
@@ -1393,7 +1826,7 @@ var service = {
|
|
|
1393
1826
|
for (const pending of requests) {
|
|
1394
1827
|
const cur = await pending;
|
|
1395
1828
|
if (cancel.isCancellationRequested)
|
|
1396
|
-
|
|
1829
|
+
return;
|
|
1397
1830
|
if (cur) {
|
|
1398
1831
|
if (Array.isArray(cur)) {
|
|
1399
1832
|
result.push(...cur);
|
|
@@ -1407,6 +1840,126 @@ var service = {
|
|
|
1407
1840
|
}
|
|
1408
1841
|
return result;
|
|
1409
1842
|
},
|
|
1843
|
+
async findReferences(doc, params, cancel) {
|
|
1844
|
+
let result;
|
|
1845
|
+
try {
|
|
1846
|
+
const requests = plugins.map((plugin) => {
|
|
1847
|
+
var _a;
|
|
1848
|
+
return (_a = plugin.findReferences) == null ? void 0 : _a.call(plugin, doc, params, cancel);
|
|
1849
|
+
});
|
|
1850
|
+
for (const pending of requests) {
|
|
1851
|
+
const cur = await pending;
|
|
1852
|
+
if (cancel.isCancellationRequested)
|
|
1853
|
+
return;
|
|
1854
|
+
if (cur) {
|
|
1855
|
+
if (result) {
|
|
1856
|
+
result.push(...cur);
|
|
1857
|
+
} else {
|
|
1858
|
+
result = cur;
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
} catch (err) {
|
|
1863
|
+
displayError(err);
|
|
1864
|
+
}
|
|
1865
|
+
return result;
|
|
1866
|
+
},
|
|
1867
|
+
async findDocumentLinks(doc, params, cancel) {
|
|
1868
|
+
let result;
|
|
1869
|
+
try {
|
|
1870
|
+
const requests = plugins.map((plugin) => {
|
|
1871
|
+
var _a;
|
|
1872
|
+
return (_a = plugin.findDocumentLinks) == null ? void 0 : _a.call(plugin, doc, params, cancel);
|
|
1873
|
+
});
|
|
1874
|
+
for (const pending of requests) {
|
|
1875
|
+
const cur = await pending;
|
|
1876
|
+
if (cancel.isCancellationRequested)
|
|
1877
|
+
return;
|
|
1878
|
+
if (cur) {
|
|
1879
|
+
if (result) {
|
|
1880
|
+
result.push(...cur);
|
|
1881
|
+
} else {
|
|
1882
|
+
result = cur;
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
} catch (err) {
|
|
1887
|
+
displayError(err);
|
|
1888
|
+
}
|
|
1889
|
+
return result;
|
|
1890
|
+
},
|
|
1891
|
+
async findDocumentHighlights(doc, params, cancel) {
|
|
1892
|
+
let result;
|
|
1893
|
+
try {
|
|
1894
|
+
const requests = plugins.map((plugin) => {
|
|
1895
|
+
var _a;
|
|
1896
|
+
return (_a = plugin.findDocumentHighlights) == null ? void 0 : _a.call(plugin, doc, params, cancel);
|
|
1897
|
+
});
|
|
1898
|
+
for (const pending of requests) {
|
|
1899
|
+
const cur = await pending;
|
|
1900
|
+
if (cancel.isCancellationRequested)
|
|
1901
|
+
return;
|
|
1902
|
+
if (cur) {
|
|
1903
|
+
if (result) {
|
|
1904
|
+
result.push(...cur);
|
|
1905
|
+
} else {
|
|
1906
|
+
result = cur;
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
} catch (err) {
|
|
1911
|
+
displayError(err);
|
|
1912
|
+
}
|
|
1913
|
+
return result;
|
|
1914
|
+
},
|
|
1915
|
+
async findDocumentColors(doc, params, cancel) {
|
|
1916
|
+
let result;
|
|
1917
|
+
try {
|
|
1918
|
+
const requests = plugins.map((plugin) => {
|
|
1919
|
+
var _a;
|
|
1920
|
+
return (_a = plugin.findDocumentColors) == null ? void 0 : _a.call(plugin, doc, params, cancel);
|
|
1921
|
+
});
|
|
1922
|
+
for (const pending of requests) {
|
|
1923
|
+
const cur = await pending;
|
|
1924
|
+
if (cancel.isCancellationRequested)
|
|
1925
|
+
return;
|
|
1926
|
+
if (cur) {
|
|
1927
|
+
if (result) {
|
|
1928
|
+
result.push(...cur);
|
|
1929
|
+
} else {
|
|
1930
|
+
result = cur;
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
} catch (err) {
|
|
1935
|
+
displayError(err);
|
|
1936
|
+
}
|
|
1937
|
+
return result;
|
|
1938
|
+
},
|
|
1939
|
+
async getColorPresentations(doc, params, cancel) {
|
|
1940
|
+
let result;
|
|
1941
|
+
try {
|
|
1942
|
+
const requests = plugins.map((plugin) => {
|
|
1943
|
+
var _a;
|
|
1944
|
+
return (_a = plugin.getColorPresentations) == null ? void 0 : _a.call(plugin, doc, params, cancel);
|
|
1945
|
+
});
|
|
1946
|
+
for (const pending of requests) {
|
|
1947
|
+
const cur = await pending;
|
|
1948
|
+
if (cancel.isCancellationRequested)
|
|
1949
|
+
return;
|
|
1950
|
+
if (cur) {
|
|
1951
|
+
if (result) {
|
|
1952
|
+
result.push(...cur);
|
|
1953
|
+
} else {
|
|
1954
|
+
result = cur;
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
} catch (err) {
|
|
1959
|
+
displayError(err);
|
|
1960
|
+
}
|
|
1961
|
+
return result;
|
|
1962
|
+
},
|
|
1410
1963
|
async doHover(doc, params, cancel) {
|
|
1411
1964
|
var _a;
|
|
1412
1965
|
try {
|
|
@@ -1421,6 +1974,80 @@ var service = {
|
|
|
1421
1974
|
displayError(err);
|
|
1422
1975
|
}
|
|
1423
1976
|
},
|
|
1977
|
+
async doRename(doc, params, cancel) {
|
|
1978
|
+
let changes;
|
|
1979
|
+
let changeAnnotations;
|
|
1980
|
+
let documentChanges;
|
|
1981
|
+
try {
|
|
1982
|
+
const requests = plugins.map((plugin) => {
|
|
1983
|
+
var _a;
|
|
1984
|
+
return (_a = plugin.doRename) == null ? void 0 : _a.call(plugin, doc, params, cancel);
|
|
1985
|
+
});
|
|
1986
|
+
for (const pending of requests) {
|
|
1987
|
+
const cur = await pending;
|
|
1988
|
+
if (cancel.isCancellationRequested)
|
|
1989
|
+
return;
|
|
1990
|
+
if (cur) {
|
|
1991
|
+
if (cur.changes) {
|
|
1992
|
+
if (changes) {
|
|
1993
|
+
for (const uri in cur.changes) {
|
|
1994
|
+
if (changes[uri]) {
|
|
1995
|
+
changes[uri].push(...cur.changes[uri]);
|
|
1996
|
+
} else {
|
|
1997
|
+
changes[uri] = cur.changes[uri];
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
} else {
|
|
2001
|
+
changes = cur.changes;
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
if (cur.changeAnnotations) {
|
|
2005
|
+
if (changeAnnotations) {
|
|
2006
|
+
Object.assign(changeAnnotations, cur.changeAnnotations);
|
|
2007
|
+
} else {
|
|
2008
|
+
changeAnnotations = cur.changeAnnotations;
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
if (cur.documentChanges) {
|
|
2012
|
+
if (documentChanges) {
|
|
2013
|
+
documentChanges.push(...cur.documentChanges);
|
|
2014
|
+
} else {
|
|
2015
|
+
documentChanges = cur.documentChanges;
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
} catch (err) {
|
|
2021
|
+
displayError(err);
|
|
2022
|
+
}
|
|
2023
|
+
if (changes || changeAnnotations || documentChanges) {
|
|
2024
|
+
return {
|
|
2025
|
+
changes,
|
|
2026
|
+
changeAnnotations,
|
|
2027
|
+
documentChanges
|
|
2028
|
+
};
|
|
2029
|
+
}
|
|
2030
|
+
},
|
|
2031
|
+
async doCodeActions(doc, params, cancel) {
|
|
2032
|
+
const result = [];
|
|
2033
|
+
try {
|
|
2034
|
+
const requests = plugins.map((plugin) => {
|
|
2035
|
+
var _a;
|
|
2036
|
+
return (_a = plugin.doCodeActions) == null ? void 0 : _a.call(plugin, doc, params, cancel);
|
|
2037
|
+
});
|
|
2038
|
+
for (const pending of requests) {
|
|
2039
|
+
const cur = await pending;
|
|
2040
|
+
if (cancel.isCancellationRequested)
|
|
2041
|
+
return;
|
|
2042
|
+
if (cur) {
|
|
2043
|
+
result.push(...cur);
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
} catch (err) {
|
|
2047
|
+
displayError(err);
|
|
2048
|
+
}
|
|
2049
|
+
return result;
|
|
2050
|
+
},
|
|
1424
2051
|
async doValidate(doc) {
|
|
1425
2052
|
const result = [];
|
|
1426
2053
|
try {
|
|
@@ -1458,14 +2085,21 @@ console.error = (...args) => {
|
|
|
1458
2085
|
};
|
|
1459
2086
|
process.on("uncaughtException", console.error);
|
|
1460
2087
|
process.on("unhandledRejection", console.error);
|
|
1461
|
-
connection2.onInitialize(() => {
|
|
2088
|
+
connection2.onInitialize(async (params) => {
|
|
1462
2089
|
setup(connection2);
|
|
2090
|
+
await service.initialize(params);
|
|
1463
2091
|
return {
|
|
1464
2092
|
capabilities: {
|
|
1465
2093
|
textDocumentSync: import_node.TextDocumentSyncKind.Incremental,
|
|
1466
2094
|
documentFormattingProvider: true,
|
|
1467
2095
|
definitionProvider: true,
|
|
1468
2096
|
hoverProvider: true,
|
|
2097
|
+
renameProvider: true,
|
|
2098
|
+
codeActionProvider: true,
|
|
2099
|
+
referencesProvider: true,
|
|
2100
|
+
documentLinkProvider: { resolveProvider: false },
|
|
2101
|
+
colorProvider: true,
|
|
2102
|
+
documentHighlightProvider: true,
|
|
1469
2103
|
completionProvider: {
|
|
1470
2104
|
triggerCharacters: [
|
|
1471
2105
|
".",
|
|
@@ -1505,9 +2139,30 @@ connection2.onCompletion(async (params, cancel) => {
|
|
|
1505
2139
|
connection2.onDefinition(async (params, cancel) => {
|
|
1506
2140
|
return await service.findDefinition(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
1507
2141
|
});
|
|
2142
|
+
connection2.onReferences(async (params, cancel) => {
|
|
2143
|
+
return await service.findReferences(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
2144
|
+
});
|
|
2145
|
+
connection2.onDocumentLinks(async (params, cancel) => {
|
|
2146
|
+
return await service.findDocumentLinks(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
2147
|
+
});
|
|
2148
|
+
connection2.onDocumentHighlight(async (params, cancel) => {
|
|
2149
|
+
return await service.findDocumentHighlights(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
2150
|
+
});
|
|
2151
|
+
connection2.onDocumentColor(async (params, cancel) => {
|
|
2152
|
+
return await service.findDocumentColors(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
2153
|
+
});
|
|
2154
|
+
connection2.onColorPresentation(async (params, cancel) => {
|
|
2155
|
+
return await service.getColorPresentations(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
2156
|
+
});
|
|
1508
2157
|
connection2.onHover(async (params, cancel) => {
|
|
1509
2158
|
return await service.doHover(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
1510
2159
|
});
|
|
2160
|
+
connection2.onRenameRequest(async (params, cancel) => {
|
|
2161
|
+
return await service.doRename(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
2162
|
+
});
|
|
2163
|
+
connection2.onCodeAction(async (params, cancel) => {
|
|
2164
|
+
return await service.doCodeActions(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
2165
|
+
});
|
|
1511
2166
|
connection2.onDocumentFormatting(async (params, cancel) => {
|
|
1512
2167
|
return await service.format(documents.get(params.textDocument.uri), params, cancel) || null;
|
|
1513
2168
|
});
|