@marko/language-server 1.0.1 → 1.0.2
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 +262 -224
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +262 -224
- package/dist/index.mjs.map +4 -4
- package/dist/service/marko/complete/AttrName.d.ts +1 -1
- package/dist/service/marko/complete/Import.d.ts +1 -1
- package/dist/service/marko/complete/OpenTagName.d.ts +1 -1
- package/dist/service/marko/definition/AttrName.d.ts +1 -1
- package/dist/service/marko/definition/OpenTagName.d.ts +1 -1
- package/dist/service/marko/hover/OpenTagName.d.ts +1 -1
- package/dist/utils/file.d.ts +3 -0
- package/dist/utils/get-component-filename.d.ts +1 -2
- package/dist/utils/project.d.ts +5 -5
- package/package.json +4 -5
package/dist/index.mjs
CHANGED
|
@@ -15,17 +15,31 @@ import {
|
|
|
15
15
|
} from "vscode-languageserver/node";
|
|
16
16
|
|
|
17
17
|
// src/utils/project.ts
|
|
18
|
+
import path from "path";
|
|
18
19
|
import * as defaultCompiler from "@marko/compiler";
|
|
19
20
|
import * as defaultTranslator from "@marko/translator-default";
|
|
20
|
-
import lassoPackageRoot from "lasso-package-root";
|
|
21
21
|
import resolveFrom from "resolve-from";
|
|
22
|
-
var
|
|
23
|
-
|
|
22
|
+
var ignoreErrors = (_err) => {
|
|
23
|
+
};
|
|
24
24
|
var projectsByDir = /* @__PURE__ */ new Map();
|
|
25
|
+
var projectsByCompiler = /* @__PURE__ */ new Map();
|
|
25
26
|
var defaultProject = {
|
|
26
|
-
rootDir: cwd,
|
|
27
27
|
cache: /* @__PURE__ */ new Map(),
|
|
28
|
-
|
|
28
|
+
getLookup(dir) {
|
|
29
|
+
const key = `taglib:${dir}`;
|
|
30
|
+
let lookup = defaultProject.cache.get(key);
|
|
31
|
+
if (!lookup) {
|
|
32
|
+
defaultProject.cache.set(
|
|
33
|
+
key,
|
|
34
|
+
lookup = defaultCompiler.taglib.buildLookup(
|
|
35
|
+
dir,
|
|
36
|
+
defaultTranslator,
|
|
37
|
+
ignoreErrors
|
|
38
|
+
)
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return lookup;
|
|
42
|
+
},
|
|
29
43
|
compiler: defaultCompiler,
|
|
30
44
|
translator: defaultTranslator
|
|
31
45
|
};
|
|
@@ -41,55 +55,119 @@ function getMarkoProject(dir) {
|
|
|
41
55
|
return project;
|
|
42
56
|
}
|
|
43
57
|
function getMarkoProjects() {
|
|
44
|
-
return
|
|
58
|
+
return projectsByCompiler.values();
|
|
59
|
+
}
|
|
60
|
+
function clearMarkoProjectCaches() {
|
|
61
|
+
for (const project of getMarkoProjects()) {
|
|
62
|
+
project.cache.clear();
|
|
63
|
+
project.compiler.taglib.clearCaches();
|
|
64
|
+
}
|
|
45
65
|
}
|
|
46
66
|
function loadProject(dir) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
67
|
+
try {
|
|
68
|
+
const compilerConfigPath = resolveFrom(dir, "@marko/compiler/config");
|
|
69
|
+
const cachedProject = projectsByCompiler.get(compilerConfigPath);
|
|
70
|
+
if (cachedProject)
|
|
71
|
+
return cachedProject;
|
|
72
|
+
const [compiler, translator] = [
|
|
73
|
+
__require(path.join(compilerConfigPath, "..")),
|
|
74
|
+
__require(resolveFrom(
|
|
75
|
+
dir,
|
|
76
|
+
interopDefault(__require(compilerConfigPath)).translator
|
|
77
|
+
))
|
|
78
|
+
];
|
|
79
|
+
const project = {
|
|
80
|
+
cache: /* @__PURE__ */ new Map(),
|
|
81
|
+
getLookup(dir2) {
|
|
82
|
+
const key = `taglib:${dir2}`;
|
|
83
|
+
let lookup = project.cache.get(key);
|
|
84
|
+
if (lookup === void 0) {
|
|
85
|
+
try {
|
|
86
|
+
lookup = compiler.taglib.buildLookup(dir2, translator, ignoreErrors);
|
|
87
|
+
} catch {
|
|
88
|
+
lookup = defaultProject.getLookup(dir2);
|
|
89
|
+
}
|
|
90
|
+
project.cache.set(key, lookup);
|
|
91
|
+
}
|
|
92
|
+
return lookup;
|
|
93
|
+
},
|
|
94
|
+
compiler,
|
|
95
|
+
translator
|
|
96
|
+
};
|
|
97
|
+
projectsByCompiler.set(compilerConfigPath, project);
|
|
98
|
+
return project;
|
|
99
|
+
} catch {
|
|
100
|
+
return defaultProject;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function interopDefault(mod) {
|
|
104
|
+
return mod.default || mod;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// src/utils/file.ts
|
|
108
|
+
import path2 from "path";
|
|
109
|
+
import { parse } from "@marko/language-tools";
|
|
110
|
+
import { URI } from "vscode-uri";
|
|
111
|
+
var processorCaches = /* @__PURE__ */ new WeakMap();
|
|
112
|
+
function getFSPath(doc) {
|
|
113
|
+
return URI.parse(doc.uri).fsPath;
|
|
114
|
+
}
|
|
115
|
+
function getMarkoFile(doc) {
|
|
116
|
+
const { uri } = doc;
|
|
117
|
+
const { fsPath: filename, scheme } = URI.parse(uri);
|
|
118
|
+
const dirname = filename && path2.dirname(filename);
|
|
119
|
+
const project = getMarkoProject(dirname);
|
|
120
|
+
const cache = project.cache;
|
|
121
|
+
let file = cache.get(doc);
|
|
122
|
+
if (!file) {
|
|
123
|
+
const { version } = doc;
|
|
124
|
+
const code = doc.getText();
|
|
125
|
+
const parsed = parse(code, filename);
|
|
126
|
+
const lookup = project.getLookup(dirname);
|
|
127
|
+
cache.set(
|
|
128
|
+
doc,
|
|
129
|
+
file = {
|
|
130
|
+
project,
|
|
131
|
+
uri,
|
|
132
|
+
scheme,
|
|
133
|
+
version,
|
|
134
|
+
lookup,
|
|
135
|
+
filename,
|
|
136
|
+
dirname,
|
|
137
|
+
parsed,
|
|
138
|
+
code
|
|
62
139
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
return file;
|
|
143
|
+
}
|
|
144
|
+
function clearMarkoCacheForFile(doc) {
|
|
145
|
+
const { fsPath: filename } = URI.parse(doc.uri);
|
|
146
|
+
const dirname = filename && path2.dirname(filename);
|
|
147
|
+
const project = getMarkoProject(dirname);
|
|
148
|
+
const cache = project.cache;
|
|
149
|
+
cache.delete(doc);
|
|
150
|
+
}
|
|
151
|
+
function processDoc(doc, process2) {
|
|
152
|
+
const file = getMarkoFile(doc);
|
|
153
|
+
const cache = processorCaches.get(file.parsed);
|
|
154
|
+
let result;
|
|
155
|
+
if (cache) {
|
|
156
|
+
result = cache.get(process2);
|
|
157
|
+
if (!result) {
|
|
158
|
+
result = process2(file);
|
|
159
|
+
cache.set(process2, result);
|
|
68
160
|
}
|
|
161
|
+
} else {
|
|
162
|
+
result = process2(file);
|
|
163
|
+
processorCaches.set(file.parsed, /* @__PURE__ */ new Map([[process2, result]]));
|
|
69
164
|
}
|
|
70
|
-
return
|
|
71
|
-
rootDir,
|
|
72
|
-
cache,
|
|
73
|
-
get lookup() {
|
|
74
|
-
let lookup = cache.get(kTaglib);
|
|
75
|
-
if (lookup === void 0) {
|
|
76
|
-
try {
|
|
77
|
-
lookup = compiler.taglib.buildLookup(dir, translator);
|
|
78
|
-
} catch {
|
|
79
|
-
lookup = defaultProject.lookup;
|
|
80
|
-
}
|
|
81
|
-
cache.set(kTaglib, lookup);
|
|
82
|
-
}
|
|
83
|
-
return lookup;
|
|
84
|
-
},
|
|
85
|
-
compiler,
|
|
86
|
-
translator
|
|
87
|
-
};
|
|
165
|
+
return result;
|
|
88
166
|
}
|
|
89
167
|
|
|
90
168
|
// src/utils/text-documents.ts
|
|
91
169
|
import fs from "fs";
|
|
92
|
-
import { URI } from "vscode-uri";
|
|
170
|
+
import { URI as URI2 } from "vscode-uri";
|
|
93
171
|
import { FileChangeType } from "vscode-languageserver";
|
|
94
172
|
import { TextDocument } from "vscode-languageserver-textdocument";
|
|
95
173
|
var docs = /* @__PURE__ */ new Map();
|
|
@@ -107,7 +185,7 @@ function get(uri) {
|
|
|
107
185
|
const doc = docs.get(uri);
|
|
108
186
|
if (doc)
|
|
109
187
|
return doc;
|
|
110
|
-
const { fsPath, scheme } =
|
|
188
|
+
const { fsPath, scheme } = URI2.parse(uri);
|
|
111
189
|
if (scheme === "file") {
|
|
112
190
|
if (fileExists.get(uri) === false)
|
|
113
191
|
return void 0;
|
|
@@ -130,7 +208,7 @@ function exists(uri) {
|
|
|
130
208
|
const cached = fileExists.get(uri);
|
|
131
209
|
if (cached !== void 0)
|
|
132
210
|
return cached;
|
|
133
|
-
const { fsPath, scheme } =
|
|
211
|
+
const { fsPath, scheme } = URI2.parse(uri);
|
|
134
212
|
if (scheme === "file") {
|
|
135
213
|
try {
|
|
136
214
|
fs.accessSync(fsPath);
|
|
@@ -184,7 +262,7 @@ function setup(connection4) {
|
|
|
184
262
|
if (doc) {
|
|
185
263
|
projectVersion++;
|
|
186
264
|
openDocs.delete(doc);
|
|
187
|
-
if (
|
|
265
|
+
if (URI2.parse(ref.uri).scheme !== "file") {
|
|
188
266
|
docs.delete(ref.uri);
|
|
189
267
|
}
|
|
190
268
|
}
|
|
@@ -287,62 +365,6 @@ function display(type, data) {
|
|
|
287
365
|
setImmediate(() => connection2.sendNotification(type, msg));
|
|
288
366
|
}
|
|
289
367
|
|
|
290
|
-
// src/utils/file.ts
|
|
291
|
-
import path from "path";
|
|
292
|
-
import { parse } from "@marko/language-tools";
|
|
293
|
-
import { URI as URI2 } from "vscode-uri";
|
|
294
|
-
var processorCaches = /* @__PURE__ */ new WeakMap();
|
|
295
|
-
function getFSDir(doc) {
|
|
296
|
-
const filename = getFSPath(doc);
|
|
297
|
-
return filename ? path.dirname(filename) : void 0;
|
|
298
|
-
}
|
|
299
|
-
function getFSPath(doc) {
|
|
300
|
-
return URI2.parse(doc.uri).fsPath;
|
|
301
|
-
}
|
|
302
|
-
function getMarkoFile(doc) {
|
|
303
|
-
const { uri } = doc;
|
|
304
|
-
const { fsPath: filename, scheme } = URI2.parse(uri);
|
|
305
|
-
const dirname = filename && path.dirname(filename);
|
|
306
|
-
const project = getMarkoProject(dirname);
|
|
307
|
-
const cache = project.cache;
|
|
308
|
-
let file = cache.get(doc);
|
|
309
|
-
if (!file) {
|
|
310
|
-
const { version } = doc;
|
|
311
|
-
const code = doc.getText();
|
|
312
|
-
const parsed = parse(code, filename);
|
|
313
|
-
cache.set(
|
|
314
|
-
doc,
|
|
315
|
-
file = {
|
|
316
|
-
project,
|
|
317
|
-
uri,
|
|
318
|
-
scheme,
|
|
319
|
-
version,
|
|
320
|
-
filename,
|
|
321
|
-
dirname,
|
|
322
|
-
parsed,
|
|
323
|
-
code
|
|
324
|
-
}
|
|
325
|
-
);
|
|
326
|
-
}
|
|
327
|
-
return file;
|
|
328
|
-
}
|
|
329
|
-
function processDoc(doc, process2) {
|
|
330
|
-
const file = getMarkoFile(doc);
|
|
331
|
-
const cache = processorCaches.get(file.parsed);
|
|
332
|
-
let result;
|
|
333
|
-
if (cache) {
|
|
334
|
-
result = cache.get(process2);
|
|
335
|
-
if (!result) {
|
|
336
|
-
result = process2(file);
|
|
337
|
-
cache.set(process2, result);
|
|
338
|
-
}
|
|
339
|
-
} else {
|
|
340
|
-
result = process2(file);
|
|
341
|
-
processorCaches.set(file.parsed, /* @__PURE__ */ new Map([[process2, result]]));
|
|
342
|
-
}
|
|
343
|
-
return result;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
368
|
// src/service/index.ts
|
|
347
369
|
import { MarkupContent, MarkupKind as MarkupKind3 } from "vscode-languageserver";
|
|
348
370
|
|
|
@@ -359,10 +381,7 @@ import {
|
|
|
359
381
|
function AttrName({
|
|
360
382
|
offset,
|
|
361
383
|
node,
|
|
362
|
-
file: {
|
|
363
|
-
parsed,
|
|
364
|
-
project: { lookup }
|
|
365
|
-
}
|
|
384
|
+
file: { parsed, lookup }
|
|
366
385
|
}) {
|
|
367
386
|
let name = parsed.read(node);
|
|
368
387
|
const modifierIndex = name.indexOf(":");
|
|
@@ -459,7 +478,7 @@ function isExternalModule(file) {
|
|
|
459
478
|
}
|
|
460
479
|
|
|
461
480
|
// src/service/marko/complete/AttrValue.ts
|
|
462
|
-
import
|
|
481
|
+
import path3 from "path";
|
|
463
482
|
import {
|
|
464
483
|
CompletionItemKind as CompletionItemKind2,
|
|
465
484
|
TextEdit as TextEdit2
|
|
@@ -572,7 +591,7 @@ async function AttrValue({
|
|
|
572
591
|
const resolved = resolveUrl(req, uri);
|
|
573
592
|
if (resolved) {
|
|
574
593
|
const result = [];
|
|
575
|
-
const curFile = req === "." ?
|
|
594
|
+
const curFile = req === "." ? path3.basename(uri) : void 0;
|
|
576
595
|
const replaceRange = parsed.locationAt({
|
|
577
596
|
start: start + segmentStart + 1,
|
|
578
597
|
end: start + rawValue.length
|
|
@@ -605,7 +624,7 @@ async function AttrValue({
|
|
|
605
624
|
import { TextEdit as TextEdit4 } from "vscode-languageserver";
|
|
606
625
|
|
|
607
626
|
// src/service/marko/util/get-tag-name-completion.ts
|
|
608
|
-
import
|
|
627
|
+
import path4 from "path";
|
|
609
628
|
import {
|
|
610
629
|
CompletionItemKind as CompletionItemKind3,
|
|
611
630
|
CompletionItemTag,
|
|
@@ -634,7 +653,7 @@ function getTagNameCompletion({
|
|
|
634
653
|
kind: MarkupKind2.Markdown,
|
|
635
654
|
value: tag.html ? `Built in [<${tag.name}>](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/${tag.name}) HTML tag.` : isCoreTag ? `Core Marko <${tag.name}> tag.` : nodeModuleName ? `Custom Marko tag discovered from the ["${nodeModuleName}"](${fileURIForTag}) npm package.` : `Custom Marko tag discovered from:
|
|
636
655
|
|
|
637
|
-
[${importer ?
|
|
656
|
+
[${importer ? path4.relative(importer, fileForTag) : fileForTag}](${fileURIForTag})`
|
|
638
657
|
};
|
|
639
658
|
if (tag.description) {
|
|
640
659
|
documentation.value += `
|
|
@@ -671,11 +690,7 @@ ${autocomplete.description}`;
|
|
|
671
690
|
var importTagReg = /(['"])<((?:[^\1\\>]+|\\.)*)>?\1/;
|
|
672
691
|
function Import({
|
|
673
692
|
node,
|
|
674
|
-
file: {
|
|
675
|
-
parsed,
|
|
676
|
-
filename,
|
|
677
|
-
project: { lookup }
|
|
678
|
-
}
|
|
693
|
+
file: { parsed, filename, lookup }
|
|
679
694
|
}) {
|
|
680
695
|
var _a;
|
|
681
696
|
const value = parsed.read(node);
|
|
@@ -707,11 +722,7 @@ function Import({
|
|
|
707
722
|
import { NodeType as NodeType2 } from "@marko/language-tools";
|
|
708
723
|
function OpenTagName({
|
|
709
724
|
node,
|
|
710
|
-
file: {
|
|
711
|
-
parsed,
|
|
712
|
-
filename,
|
|
713
|
-
project: { lookup }
|
|
714
|
-
}
|
|
725
|
+
file: { parsed, filename, lookup }
|
|
715
726
|
}) {
|
|
716
727
|
var _a;
|
|
717
728
|
const tag = node.parent;
|
|
@@ -832,14 +843,14 @@ var doComplete = async (doc, params) => {
|
|
|
832
843
|
};
|
|
833
844
|
|
|
834
845
|
// src/service/marko/validate.ts
|
|
835
|
-
import
|
|
846
|
+
import path5 from "path";
|
|
836
847
|
import { DiagnosticSeverity } from "vscode-languageserver";
|
|
837
848
|
var markoErrorRegExp = /^(.+?)\.marko(?:\((\d+)(?:\s*,\s*(\d+))?\))?: (.*)$/gm;
|
|
838
849
|
var doValidate = (doc) => {
|
|
839
850
|
const filename = getFSPath(doc);
|
|
840
851
|
const diagnostics = [];
|
|
841
852
|
const { compiler, translator, cache } = getMarkoProject(
|
|
842
|
-
filename &&
|
|
853
|
+
filename && path5.dirname(filename)
|
|
843
854
|
);
|
|
844
855
|
try {
|
|
845
856
|
compiler.compileSync(doc.getText(), filename || "untitled.marko", {
|
|
@@ -895,11 +906,7 @@ var START_LOCATION = {
|
|
|
895
906
|
// src/service/marko/hover/OpenTagName.ts
|
|
896
907
|
function OpenTagName2({
|
|
897
908
|
node,
|
|
898
|
-
file: {
|
|
899
|
-
parsed,
|
|
900
|
-
filename,
|
|
901
|
-
project: { lookup }
|
|
902
|
-
}
|
|
909
|
+
file: { parsed, filename, lookup }
|
|
903
910
|
}) {
|
|
904
911
|
const tag = node.parent;
|
|
905
912
|
const range = parsed.locationAt(node);
|
|
@@ -971,10 +978,7 @@ function escape(val) {
|
|
|
971
978
|
// src/service/marko/definition/AttrName.ts
|
|
972
979
|
function AttrName2({
|
|
973
980
|
node,
|
|
974
|
-
file: {
|
|
975
|
-
parsed,
|
|
976
|
-
project: { lookup }
|
|
977
|
-
}
|
|
981
|
+
file: { parsed, lookup }
|
|
978
982
|
}) {
|
|
979
983
|
const tagName = node.parent.parent.nameText;
|
|
980
984
|
const attrName = parsed.read(node);
|
|
@@ -1013,7 +1017,7 @@ function AttrName2({
|
|
|
1013
1017
|
|
|
1014
1018
|
// src/service/marko/definition/OpenTagName.ts
|
|
1015
1019
|
import fs4 from "fs";
|
|
1016
|
-
import
|
|
1020
|
+
import path6 from "path";
|
|
1017
1021
|
import { URI as URI5 } from "vscode-uri";
|
|
1018
1022
|
import {
|
|
1019
1023
|
NodeType as NodeType5,
|
|
@@ -1022,10 +1026,7 @@ import {
|
|
|
1022
1026
|
} from "@marko/language-tools";
|
|
1023
1027
|
function OpenTagName3({
|
|
1024
1028
|
node,
|
|
1025
|
-
file: {
|
|
1026
|
-
parsed,
|
|
1027
|
-
project: { lookup }
|
|
1028
|
-
}
|
|
1029
|
+
file: { parsed, lookup }
|
|
1029
1030
|
}) {
|
|
1030
1031
|
const tag = node.parent;
|
|
1031
1032
|
let tagDef;
|
|
@@ -1042,7 +1043,7 @@ function OpenTagName3({
|
|
|
1042
1043
|
return;
|
|
1043
1044
|
}
|
|
1044
1045
|
const tagEntryFile = tagDef.template || tagDef.renderer || tagDef.filePath;
|
|
1045
|
-
if (!
|
|
1046
|
+
if (!path6.isAbsolute(tagEntryFile)) {
|
|
1046
1047
|
return;
|
|
1047
1048
|
}
|
|
1048
1049
|
if (/\/marko(?:-tag)?\.json$/.test(tagEntryFile)) {
|
|
@@ -1097,7 +1098,7 @@ function extractDocumentLinks({
|
|
|
1097
1098
|
scheme,
|
|
1098
1099
|
parsed,
|
|
1099
1100
|
code,
|
|
1100
|
-
|
|
1101
|
+
lookup
|
|
1101
1102
|
}) {
|
|
1102
1103
|
if (scheme !== "file") {
|
|
1103
1104
|
return [];
|
|
@@ -1173,7 +1174,7 @@ function extractDocumentSymbols({
|
|
|
1173
1174
|
uri,
|
|
1174
1175
|
scheme,
|
|
1175
1176
|
parsed,
|
|
1176
|
-
|
|
1177
|
+
lookup
|
|
1177
1178
|
}) {
|
|
1178
1179
|
if (scheme !== "file") {
|
|
1179
1180
|
return [];
|
|
@@ -1254,7 +1255,7 @@ var marko_default = {
|
|
|
1254
1255
|
};
|
|
1255
1256
|
|
|
1256
1257
|
// src/service/script/index.ts
|
|
1257
|
-
import
|
|
1258
|
+
import path10 from "path";
|
|
1258
1259
|
import { relativeImportPath } from "relative-import-path";
|
|
1259
1260
|
import ts from "typescript/lib/tsserverlibrary";
|
|
1260
1261
|
import {
|
|
@@ -1273,7 +1274,7 @@ import {
|
|
|
1273
1274
|
} from "@marko/language-tools";
|
|
1274
1275
|
|
|
1275
1276
|
// src/ts-plugin/host.ts
|
|
1276
|
-
import
|
|
1277
|
+
import path9 from "path";
|
|
1277
1278
|
import {
|
|
1278
1279
|
ScriptLang as ScriptLang2,
|
|
1279
1280
|
extractScript,
|
|
@@ -1281,15 +1282,15 @@ import {
|
|
|
1281
1282
|
} from "@marko/language-tools";
|
|
1282
1283
|
|
|
1283
1284
|
// src/utils/get-runtime-types.ts
|
|
1284
|
-
import
|
|
1285
|
-
var internalTypesFile =
|
|
1286
|
-
var defaultMarkoTypesFile =
|
|
1285
|
+
import path7 from "path";
|
|
1286
|
+
var internalTypesFile = path7.join(__dirname, "marko.internal.d.ts");
|
|
1287
|
+
var defaultMarkoTypesFile = path7.join(__dirname, "marko.runtime.d.ts");
|
|
1287
1288
|
function getProjectTypeLibs(project, ts2, host) {
|
|
1288
1289
|
let cached = project.cache.get(getProjectTypeLibs);
|
|
1289
1290
|
if (cached === void 0) {
|
|
1290
1291
|
const { resolvedTypeReferenceDirective } = ts2.resolveTypeReferenceDirective(
|
|
1291
1292
|
project.translator.runtimeTypes || "marko",
|
|
1292
|
-
|
|
1293
|
+
path7.join(host.getCurrentDirectory(), "_.d.ts"),
|
|
1293
1294
|
host.getCompilationSettings(),
|
|
1294
1295
|
host
|
|
1295
1296
|
);
|
|
@@ -1328,21 +1329,19 @@ function getScriptLang(filename, ts2, host, projectScriptLang) {
|
|
|
1328
1329
|
}
|
|
1329
1330
|
|
|
1330
1331
|
// src/utils/get-component-filename.ts
|
|
1331
|
-
import
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
const
|
|
1332
|
+
import fs5 from "fs";
|
|
1333
|
+
import path8 from "path";
|
|
1334
|
+
function getComponentFilename(from) {
|
|
1335
|
+
const dir = path8.dirname(from);
|
|
1336
|
+
const nameNoExt = path8.basename(from, ".marko");
|
|
1335
1337
|
const isEntry = nameNoExt === "index";
|
|
1336
|
-
const componentFull =
|
|
1337
|
-
const componentBrowserFull =
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
)
|
|
1341
|
-
const componentPartial = isEntry ? path7.join(dir, "component.") : void 0;
|
|
1342
|
-
const componentBrowserPartial = isEntry ? path7.join(dir, "component-browser.") : void 0;
|
|
1343
|
-
for (const entry of host.readDirectory(dir)) {
|
|
1338
|
+
const componentFull = `${nameNoExt}.component.`;
|
|
1339
|
+
const componentBrowserFull = `${nameNoExt}.component-browser.`;
|
|
1340
|
+
const componentPartial = isEntry ? "component." : void 0;
|
|
1341
|
+
const componentBrowserPartial = isEntry ? "component-browser." : void 0;
|
|
1342
|
+
for (const entry of fs5.readdirSync(dir)) {
|
|
1344
1343
|
if (entry !== from && (isEntry && entry.startsWith(componentBrowserPartial) || entry.startsWith(componentPartial)) || entry.startsWith(componentBrowserFull) || entry.startsWith(componentFull)) {
|
|
1345
|
-
return entry;
|
|
1344
|
+
return path8.join(dir, entry);
|
|
1346
1345
|
}
|
|
1347
1346
|
}
|
|
1348
1347
|
}
|
|
@@ -1380,14 +1379,15 @@ function patch(ts2, scriptLang, cache, host) {
|
|
|
1380
1379
|
let cached = cache.get(filename);
|
|
1381
1380
|
if (!cached) {
|
|
1382
1381
|
const code = host.readFile(filename, "utf-8") || "";
|
|
1383
|
-
const
|
|
1382
|
+
const dir = path9.dirname(filename);
|
|
1383
|
+
const markoProject = getMarkoProject(dir);
|
|
1384
1384
|
cached = extractScript({
|
|
1385
1385
|
ts: ts2,
|
|
1386
1386
|
parsed: parse2(code, filename),
|
|
1387
|
-
lookup: markoProject.
|
|
1387
|
+
lookup: markoProject.getLookup(dir),
|
|
1388
1388
|
scriptLang: getScriptLang(filename, ts2, host, scriptLang),
|
|
1389
1389
|
runtimeTypesCode: projectTypeLibs.markoTypesCode,
|
|
1390
|
-
componentFilename: getComponentFilename(filename
|
|
1390
|
+
componentFilename: getComponentFilename(filename)
|
|
1391
1391
|
});
|
|
1392
1392
|
cached.snapshot = ts2.ScriptSnapshot.fromString(cached.toString());
|
|
1393
1393
|
cache.set(filename, cached);
|
|
@@ -1396,11 +1396,20 @@ function patch(ts2, scriptLang, cache, host) {
|
|
|
1396
1396
|
}
|
|
1397
1397
|
return getScriptSnapshot(filename);
|
|
1398
1398
|
};
|
|
1399
|
+
if (host.getProjectVersion) {
|
|
1400
|
+
const getScriptVersion = host.getScriptVersion.bind(host);
|
|
1401
|
+
host.getScriptVersion = (filename) => {
|
|
1402
|
+
if (markoExtReg.test(filename)) {
|
|
1403
|
+
return host.getProjectVersion();
|
|
1404
|
+
}
|
|
1405
|
+
return getScriptVersion(filename);
|
|
1406
|
+
};
|
|
1407
|
+
}
|
|
1399
1408
|
const readDirectory2 = (_b = host.readDirectory) == null ? void 0 : _b.bind(host);
|
|
1400
1409
|
if (readDirectory2) {
|
|
1401
|
-
host.readDirectory = (
|
|
1410
|
+
host.readDirectory = (path11, extensions, exclude, include, depth) => {
|
|
1402
1411
|
return readDirectory2(
|
|
1403
|
-
|
|
1412
|
+
path11,
|
|
1404
1413
|
extensions == null ? void 0 : extensions.concat(markoExt),
|
|
1405
1414
|
exclude,
|
|
1406
1415
|
include,
|
|
@@ -1411,31 +1420,16 @@ function patch(ts2, scriptLang, cache, host) {
|
|
|
1411
1420
|
const resolveModuleNames = (_c = host.resolveModuleNames) == null ? void 0 : _c.bind(host);
|
|
1412
1421
|
if (resolveModuleNames) {
|
|
1413
1422
|
host.resolveModuleNames = (moduleNames, containingFile, reusedNames, redirectedReference, options, sourceFile) => {
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
reusedNames,
|
|
1418
|
-
redirectedReference,
|
|
1419
|
-
options,
|
|
1420
|
-
sourceFile
|
|
1421
|
-
);
|
|
1422
|
-
for (let i = resolvedModules.length; i--; ) {
|
|
1423
|
+
let normalModuleNames = moduleNames;
|
|
1424
|
+
let resolvedModules;
|
|
1425
|
+
for (let i = 0; i < moduleNames.length; i++) {
|
|
1423
1426
|
const moduleName = moduleNames[i];
|
|
1424
|
-
|
|
1427
|
+
const shouldProcess = moduleName[0] !== "*" ? markoExtReg.test(moduleName) : void 0;
|
|
1428
|
+
if (shouldProcess) {
|
|
1429
|
+
let resolvedFileName;
|
|
1425
1430
|
if (fsPathReg.test(moduleName)) {
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
"..",
|
|
1429
|
-
moduleName
|
|
1430
|
-
);
|
|
1431
|
-
if (host.fileExists(resolvedFileName)) {
|
|
1432
|
-
resolvedModules[i] = {
|
|
1433
|
-
resolvedFileName,
|
|
1434
|
-
extension: isMarkoTSFile(resolvedFileName) ? ts2.Extension.Ts : ts2.Extension.Js,
|
|
1435
|
-
isExternalLibraryImport: false
|
|
1436
|
-
};
|
|
1437
|
-
}
|
|
1438
|
-
} else if (moduleName[0] !== "*") {
|
|
1431
|
+
resolvedFileName = path9.resolve(containingFile, "..", moduleName);
|
|
1432
|
+
} else {
|
|
1439
1433
|
const [, nodeModuleName, relativeModulePath] = modulePartsReg.exec(moduleName);
|
|
1440
1434
|
const { resolvedModule } = ts2.resolveModuleName(
|
|
1441
1435
|
`${nodeModuleName}/package.json`,
|
|
@@ -1444,24 +1438,63 @@ function patch(ts2, scriptLang, cache, host) {
|
|
|
1444
1438
|
host
|
|
1445
1439
|
);
|
|
1446
1440
|
if (resolvedModule) {
|
|
1447
|
-
|
|
1441
|
+
resolvedFileName = path9.join(
|
|
1448
1442
|
resolvedModule.resolvedFileName,
|
|
1449
1443
|
"..",
|
|
1450
1444
|
relativeModulePath
|
|
1451
1445
|
);
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
if (!resolvedModules) {
|
|
1449
|
+
resolvedModules = [];
|
|
1450
|
+
normalModuleNames = [];
|
|
1451
|
+
for (let j = 0; j < i; j++) {
|
|
1452
|
+
resolvedModules.push(void 0);
|
|
1453
|
+
normalModuleNames.push(moduleNames[j]);
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
resolvedModules.push(
|
|
1457
|
+
resolvedFileName && host.fileExists(resolvedFileName) ? {
|
|
1458
|
+
resolvedFileName,
|
|
1459
|
+
extension: isMarkoTSFile(resolvedFileName) ? ts2.Extension.Ts : ts2.Extension.Js,
|
|
1460
|
+
isExternalLibraryImport: false
|
|
1461
|
+
} : null
|
|
1462
|
+
);
|
|
1463
|
+
} else if (resolvedModules) {
|
|
1464
|
+
resolvedModules.push(void 0);
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
const normalResolvedModules = normalModuleNames.length ? resolveModuleNames(
|
|
1468
|
+
normalModuleNames,
|
|
1469
|
+
containingFile,
|
|
1470
|
+
reusedNames,
|
|
1471
|
+
redirectedReference,
|
|
1472
|
+
options,
|
|
1473
|
+
sourceFile
|
|
1474
|
+
) : void 0;
|
|
1475
|
+
if (resolvedModules) {
|
|
1476
|
+
if (normalResolvedModules) {
|
|
1477
|
+
for (let i = 0, j = 0; i < resolvedModules.length; i++) {
|
|
1478
|
+
switch (resolvedModules[i]) {
|
|
1479
|
+
case void 0:
|
|
1480
|
+
resolvedModules[i] = normalResolvedModules[j++];
|
|
1481
|
+
break;
|
|
1482
|
+
case null:
|
|
1483
|
+
resolvedModules[i] = void 0;
|
|
1484
|
+
break;
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
} else {
|
|
1488
|
+
for (let i = resolvedModules.length; i--; ) {
|
|
1489
|
+
if (resolvedModules[i] === null) {
|
|
1490
|
+
resolvedModules[i] = void 0;
|
|
1460
1491
|
}
|
|
1461
1492
|
}
|
|
1462
1493
|
}
|
|
1494
|
+
return resolvedModules;
|
|
1495
|
+
} else {
|
|
1496
|
+
return normalResolvedModules;
|
|
1463
1497
|
}
|
|
1464
|
-
return resolvedModules;
|
|
1465
1498
|
};
|
|
1466
1499
|
}
|
|
1467
1500
|
return host;
|
|
@@ -1562,7 +1595,7 @@ var ScriptService = {
|
|
|
1562
1595
|
let source = completion.source;
|
|
1563
1596
|
if (source && completion.hasAction) {
|
|
1564
1597
|
if (source[0] === ".") {
|
|
1565
|
-
source =
|
|
1598
|
+
source = path10.resolve(fileName, "..", source);
|
|
1566
1599
|
}
|
|
1567
1600
|
detail = relativeImportPath(fileName, source);
|
|
1568
1601
|
sortText = `\uFFFF${sortText}`;
|
|
@@ -1866,19 +1899,21 @@ ${documentation}`;
|
|
|
1866
1899
|
}
|
|
1867
1900
|
};
|
|
1868
1901
|
function processScript(doc, tsProject) {
|
|
1869
|
-
return processDoc(
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1902
|
+
return processDoc(
|
|
1903
|
+
doc,
|
|
1904
|
+
({ filename, parsed, lookup, project: markoProject }) => {
|
|
1905
|
+
var _a;
|
|
1906
|
+
const { host, markoScriptLang } = tsProject;
|
|
1907
|
+
return extractScript2({
|
|
1908
|
+
ts,
|
|
1909
|
+
parsed,
|
|
1910
|
+
lookup,
|
|
1911
|
+
scriptLang: getScriptLang(filename, ts, host, markoScriptLang),
|
|
1912
|
+
runtimeTypesCode: (_a = getProjectTypeLibs(markoProject, ts, host)) == null ? void 0 : _a.markoTypesCode,
|
|
1913
|
+
componentFilename: getComponentFilename(filename)
|
|
1914
|
+
});
|
|
1915
|
+
}
|
|
1916
|
+
);
|
|
1882
1917
|
}
|
|
1883
1918
|
function getInsertModuleStatementOffset(parsed) {
|
|
1884
1919
|
const { program } = parsed;
|
|
@@ -1947,7 +1982,7 @@ function getTSProject(docFsPath) {
|
|
|
1947
1982
|
);
|
|
1948
1983
|
}
|
|
1949
1984
|
}
|
|
1950
|
-
const rootDir = configPath &&
|
|
1985
|
+
const rootDir = configPath && path10.dirname(configPath) || process.cwd();
|
|
1951
1986
|
const markoProject = getMarkoProject(configPath && rootDir);
|
|
1952
1987
|
let projectCache = markoProject.cache.get(getTSProject);
|
|
1953
1988
|
let cached;
|
|
@@ -1961,7 +1996,8 @@ function getTSProject(docFsPath) {
|
|
|
1961
1996
|
}
|
|
1962
1997
|
const { fileNames, options, projectReferences } = ts.parseJsonConfigFileContent(
|
|
1963
1998
|
configPath && ts.readConfigFile(configPath, ts.sys.readFile).config || {
|
|
1964
|
-
compilerOptions: { lib: ["dom", "node", "esnext"] }
|
|
1999
|
+
compilerOptions: { lib: ["dom", "node", "esnext"] },
|
|
2000
|
+
include: []
|
|
1965
2001
|
},
|
|
1966
2002
|
ts.sys,
|
|
1967
2003
|
rootDir,
|
|
@@ -1982,10 +2018,11 @@ function getTSProject(docFsPath) {
|
|
|
1982
2018
|
options.rootDir ??= rootDir;
|
|
1983
2019
|
options.module = ts.ModuleKind.ESNext;
|
|
1984
2020
|
options.moduleResolution = ts.ModuleResolutionKind.NodeJs;
|
|
1985
|
-
options.
|
|
2021
|
+
options.declaration = false;
|
|
2022
|
+
options.noEmit = options.allowJs = options.skipLibCheck = options.isolatedModules = options.resolveJsonModule = options.skipDefaultLibCheck = options.allowNonTsExtensions = true;
|
|
1986
2023
|
const tsPkgFile = configPath && ((_a = ts.resolveModuleName("typescript/package.json", configPath, options, ts.sys).resolvedModule) == null ? void 0 : _a.resolvedFileName);
|
|
1987
|
-
const defaultLibFile =
|
|
1988
|
-
tsPkgFile ?
|
|
2024
|
+
const defaultLibFile = path10.join(
|
|
2025
|
+
tsPkgFile ? path10.join(tsPkgFile, "../lib") : __dirname,
|
|
1989
2026
|
ts.getDefaultLibFileName(options)
|
|
1990
2027
|
);
|
|
1991
2028
|
const host = patch(
|
|
@@ -2039,12 +2076,16 @@ function getTSProject(docFsPath) {
|
|
|
2039
2076
|
return `${((_a2 = get(filenameToURI(filename))) == null ? void 0 : _a2.version) ?? -1}`;
|
|
2040
2077
|
},
|
|
2041
2078
|
getScriptKind(filename) {
|
|
2042
|
-
switch (
|
|
2079
|
+
switch (path10.extname(filename)) {
|
|
2043
2080
|
case ts.Extension.Js:
|
|
2081
|
+
case ts.Extension.Cjs:
|
|
2082
|
+
case ts.Extension.Mjs:
|
|
2044
2083
|
return ts.ScriptKind.JS;
|
|
2045
2084
|
case ts.Extension.Jsx:
|
|
2046
2085
|
return ts.ScriptKind.JSX;
|
|
2047
2086
|
case ts.Extension.Ts:
|
|
2087
|
+
case ts.Extension.Cts:
|
|
2088
|
+
case ts.Extension.Mts:
|
|
2048
2089
|
return ts.ScriptKind.TS;
|
|
2049
2090
|
case ts.Extension.Tsx:
|
|
2050
2091
|
return ts.ScriptKind.TSX;
|
|
@@ -2546,7 +2587,7 @@ var StyleSheetService = {
|
|
|
2546
2587
|
}
|
|
2547
2588
|
};
|
|
2548
2589
|
function processStyle(doc) {
|
|
2549
|
-
return processDoc(doc, ({ uri, version, parsed,
|
|
2590
|
+
return processDoc(doc, ({ uri, version, parsed, lookup }) => {
|
|
2550
2591
|
var _a;
|
|
2551
2592
|
const result = [];
|
|
2552
2593
|
for (const [ext, extracted] of extractStyle({
|
|
@@ -3024,7 +3065,7 @@ setup(connection3);
|
|
|
3024
3065
|
onFileChange((changeDoc) => {
|
|
3025
3066
|
if (changeDoc) {
|
|
3026
3067
|
queueDiagnostic();
|
|
3027
|
-
|
|
3068
|
+
clearMarkoCacheForFile(changeDoc);
|
|
3028
3069
|
} else {
|
|
3029
3070
|
validateDocs();
|
|
3030
3071
|
}
|
|
@@ -3121,10 +3162,7 @@ for (const command in service.commands) {
|
|
|
3121
3162
|
}
|
|
3122
3163
|
function validateDocs() {
|
|
3123
3164
|
queueDiagnostic();
|
|
3124
|
-
|
|
3125
|
-
project.cache.clear();
|
|
3126
|
-
project.compiler.taglib.clearCaches();
|
|
3127
|
-
}
|
|
3165
|
+
clearMarkoProjectCaches();
|
|
3128
3166
|
}
|
|
3129
3167
|
function queueDiagnostic() {
|
|
3130
3168
|
clearTimeout(diagnosticTimeout);
|