@marko/language-server 1.3.8 → 1.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -5,21 +5,12 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
5
5
  throw Error('Dynamic require of "' + x + '" is not supported');
6
6
  });
7
7
 
8
- // src/index.ts
9
- import { inspect as inspect2, isDeepStrictEqual } from "util";
10
- import {
11
- ProposedFeatures,
12
- TextDocumentSyncKind,
13
- createConnection
14
- } from "vscode-languageserver/node";
15
- import { Project as Project6 } from "@marko/language-tools";
16
-
17
8
  // src/utils/project-defaults.ts
18
- import path from "path";
19
9
  import * as defaultCompiler from "@marko/compiler";
20
10
  import defaultConfig from "@marko/compiler/config";
21
- import * as defaultTranslator from "@marko/translator-default";
22
11
  import { Project } from "@marko/language-tools";
12
+ import * as defaultTranslator from "@marko/translator-default";
13
+ import path from "path";
23
14
  Project.setDefaultTypePaths({
24
15
  internalTypesFile: path.join(__dirname, "marko.internal.d.ts"),
25
16
  markoTypesFile: path.join(__dirname, "marko.runtime.d.ts")
@@ -29,74 +20,25 @@ Project.setDefaultCompilerMeta(defaultCompiler, {
29
20
  translator: defaultTranslator
30
21
  });
31
22
 
32
- // src/utils/file.ts
33
- import path2 from "path";
34
- import { Project as Project2, parse } from "@marko/language-tools";
35
- import { URI } from "vscode-uri";
36
- var processorCaches = /* @__PURE__ */ new WeakMap();
37
- function getFSDir(doc) {
38
- const filename = getFSPath(doc);
39
- return filename && path2.dirname(filename);
40
- }
41
- function getFSPath(doc) {
42
- const parsed = URI.parse(doc.uri);
43
- return parsed.scheme === "file" ? parsed.fsPath : void 0;
44
- }
45
- function getMarkoFile(doc) {
46
- const { uri } = doc;
47
- const { fsPath, scheme } = URI.parse(uri);
48
- const filename = scheme === "file" ? fsPath : void 0;
49
- const dirname = filename ? path2.dirname(filename) : process.cwd();
50
- const cache = Project2.getCache(dirname);
51
- let file = cache.get(doc);
52
- if (!file) {
53
- const { version } = doc;
54
- const code = doc.getText();
55
- const parsed = parse(code, filename);
56
- const lookup = Project2.getTagLookup(dirname);
57
- cache.set(
58
- doc,
59
- file = {
60
- uri,
61
- scheme,
62
- version,
63
- lookup,
64
- filename,
65
- dirname,
66
- parsed,
67
- code
68
- }
69
- );
70
- }
71
- return file;
72
- }
73
- function clearMarkoCacheForFile(doc) {
74
- Project2.getCache(getFSDir(doc)).delete(doc);
75
- }
76
- function processDoc(doc, process2) {
77
- const file = getMarkoFile(doc);
78
- const cache = processorCaches.get(file.parsed);
79
- let result;
80
- if (cache) {
81
- result = cache.get(process2);
82
- if (!result) {
83
- result = process2(file);
84
- cache.set(process2, result);
85
- }
86
- } else {
87
- result = process2(file);
88
- processorCaches.set(file.parsed, /* @__PURE__ */ new Map([[process2, result]]));
89
- }
90
- return result;
91
- }
23
+ // src/index.ts
24
+ import { Project as Project6 } from "@marko/language-tools";
25
+ import { inspect as inspect2, isDeepStrictEqual } from "util";
26
+ import {
27
+ createConnection,
28
+ ProposedFeatures,
29
+ TextDocumentSyncKind
30
+ } from "vscode-languageserver/node";
31
+
32
+ // src/service/index.ts
33
+ import { MarkupContent, MarkupKind as MarkupKind3 } from "vscode-languageserver";
92
34
 
93
35
  // src/utils/text-documents.ts
94
36
  import fs from "fs";
95
- import { URI as URI2 } from "vscode-uri";
96
37
  import {
97
38
  FileChangeType
98
39
  } from "vscode-languageserver";
99
40
  import { TextDocument } from "vscode-languageserver-textdocument";
41
+ import { URI } from "vscode-uri";
100
42
  var docs = /* @__PURE__ */ new Map();
101
43
  var openDocs = /* @__PURE__ */ new Set();
102
44
  var fileExists = /* @__PURE__ */ new Map();
@@ -111,7 +53,7 @@ function getAllOpen() {
111
53
  function get(uri) {
112
54
  const doc = docs.get(uri);
113
55
  if (doc) return doc;
114
- const { fsPath, scheme } = URI2.parse(uri);
56
+ const { fsPath, scheme } = URI.parse(uri);
115
57
  if (scheme === "file") {
116
58
  if (fileExists.get(uri) === false) return void 0;
117
59
  try {
@@ -132,7 +74,7 @@ function get(uri) {
132
74
  function exists(uri) {
133
75
  const cached = fileExists.get(uri);
134
76
  if (cached !== void 0) return cached;
135
- const { fsPath, scheme } = URI2.parse(uri);
77
+ const { fsPath, scheme } = URI.parse(uri);
136
78
  if (scheme === "file") {
137
79
  try {
138
80
  fs.accessSync(fsPath);
@@ -185,7 +127,7 @@ function doClose(params) {
185
127
  if (doc) {
186
128
  projectVersion++;
187
129
  openDocs.delete(doc);
188
- if (URI2.parse(ref.uri).scheme !== "file") {
130
+ if (URI.parse(ref.uri).scheme !== "file") {
189
131
  docs.delete(ref.uri);
190
132
  }
191
133
  }
@@ -230,75 +172,72 @@ function emitFileChange(doc) {
230
172
  }
231
173
  }
232
174
 
233
- // src/utils/workspace.ts
234
- var isInitialized = false;
235
- var connection;
236
- var configChangeHandlers = /* @__PURE__ */ new Set();
237
- var settingsCache = /* @__PURE__ */ new Map();
238
- async function getConfig(section) {
239
- let cached = settingsCache.get(section);
240
- if (!cached) {
241
- try {
242
- cached = await connection.workspace.getConfiguration(section) || {};
243
- settingsCache.set(section, cached);
244
- } catch {
245
- }
246
- }
247
- return cached;
248
- }
249
- function onConfigChange(handler) {
250
- configChangeHandlers.add(handler);
175
+ // src/service/html/index.ts
176
+ import { extractHTML } from "@marko/language-tools";
177
+ import axe from "axe-core";
178
+ import { JSDOM } from "jsdom";
179
+
180
+ // src/utils/file.ts
181
+ import { parse, Project as Project2 } from "@marko/language-tools";
182
+ import path2 from "path";
183
+ import { URI as URI2 } from "vscode-uri";
184
+ var processorCaches = /* @__PURE__ */ new WeakMap();
185
+ function getFSDir(doc) {
186
+ const filename = getFSPath(doc);
187
+ return filename && path2.dirname(filename);
251
188
  }
252
- function setup(_) {
253
- connection = _;
254
- connection.onDidChangeConfiguration(() => {
255
- if (isInitialized) {
256
- settingsCache.clear();
257
- emitConfigChange();
258
- } else {
259
- isInitialized = true;
260
- }
261
- });
189
+ function getFSPath(doc) {
190
+ const parsed = URI2.parse(doc.uri);
191
+ return parsed.scheme === "file" ? parsed.fsPath : void 0;
262
192
  }
263
- function emitConfigChange() {
264
- for (const handler of configChangeHandlers) {
265
- handler();
193
+ function getMarkoFile(doc) {
194
+ const { uri } = doc;
195
+ const { fsPath, scheme } = URI2.parse(uri);
196
+ const filename = scheme === "file" ? fsPath : void 0;
197
+ const dirname = filename ? path2.dirname(filename) : process.cwd();
198
+ const cache = Project2.getCache(dirname);
199
+ let file = cache.get(doc);
200
+ if (!file) {
201
+ const { version } = doc;
202
+ const code = doc.getText();
203
+ const parsed = parse(code, filename);
204
+ const lookup = Project2.getTagLookup(dirname);
205
+ cache.set(
206
+ doc,
207
+ file = {
208
+ uri,
209
+ scheme,
210
+ version,
211
+ lookup,
212
+ filename,
213
+ dirname,
214
+ parsed,
215
+ code
216
+ }
217
+ );
266
218
  }
219
+ return file;
267
220
  }
268
-
269
- // src/utils/messages.ts
270
- import { inspect } from "util";
271
- var connection2;
272
- var previousMessagesByType = /* @__PURE__ */ new Map();
273
- function setup2(_) {
274
- connection2 = _;
275
- }
276
- function displayError(data) {
277
- display("showError", data);
221
+ function clearMarkoCacheForFile(doc) {
222
+ Project2.getCache(getFSDir(doc)).delete(doc);
278
223
  }
279
- function display(type, data) {
280
- const msg = typeof data === "string" ? data : inspect(data, { colors: false });
281
- const previousMessages = previousMessagesByType.get(type);
282
- if (previousMessages) {
283
- if (previousMessages.includes(msg)) return;
284
- previousMessages.push(msg);
285
- if (previousMessages.length > 3) {
286
- previousMessages.unshift();
224
+ function processDoc(doc, process2) {
225
+ const file = getMarkoFile(doc);
226
+ const cache = processorCaches.get(file.parsed);
227
+ let result;
228
+ if (cache) {
229
+ result = cache.get(process2);
230
+ if (!result) {
231
+ result = process2(file);
232
+ cache.set(process2, result);
287
233
  }
288
234
  } else {
289
- previousMessagesByType.set(type, [msg]);
235
+ result = process2(file);
236
+ processorCaches.set(file.parsed, /* @__PURE__ */ new Map([[process2, result]]));
290
237
  }
291
- setImmediate(() => connection2.sendNotification(type, msg));
238
+ return result;
292
239
  }
293
240
 
294
- // src/service/index.ts
295
- import { MarkupContent, MarkupKind as MarkupKind3 } from "vscode-languageserver";
296
-
297
- // src/service/html/index.ts
298
- import axe from "axe-core";
299
- import { extractHTML } from "@marko/language-tools";
300
- import { JSDOM } from "jsdom";
301
-
302
241
  // src/service/html/axe-rules/axe-rules.ts
303
242
  var keyboard = {
304
243
  /**
@@ -842,7 +781,7 @@ var ruleExceptions = {
842
781
  [aria.ariaInputFieldName]: { unknownBody: true, attrSpread: true },
843
782
  [aria.ariaMeterName]: { unknownBody: true, attrSpread: true },
844
783
  [aria.ariaProgressbarName]: { unknownBody: true, attrSpread: true },
845
- [aria.ariaProhibitedAttr]: {},
784
+ [aria.ariaProhibitedAttr]: { dynamicAttrs: ["role"] },
846
785
  [aria.ariaRequiredAttr]: { attrSpread: true },
847
786
  [aria.ariaRequiredChildren]: { unknownBody: true },
848
787
  [aria.ariaRoles]: { dynamicAttrs: ["role"] },
@@ -1104,31 +1043,6 @@ import {
1104
1043
  TextEdit as TextEdit2
1105
1044
  } from "vscode-languageserver";
1106
1045
 
1107
- // src/service/marko/util/is-document-link-attr.ts
1108
- import { NodeType } from "@marko/language-tools";
1109
- var linkedAttrs = /* @__PURE__ */ new Map([
1110
- [
1111
- "src",
1112
- /* @__PURE__ */ new Set([
1113
- "audio",
1114
- "embed",
1115
- "iframe",
1116
- "img",
1117
- "input",
1118
- "script",
1119
- "source",
1120
- "track",
1121
- "video"
1122
- ])
1123
- ],
1124
- ["href", /* @__PURE__ */ new Set(["a", "area", "link"])],
1125
- ["data", /* @__PURE__ */ new Set(["object"])],
1126
- ["poster", /* @__PURE__ */ new Set(["video"])]
1127
- ]);
1128
- function isDocumentLinkAttr(code, tag, attr) {
1129
- return tag.nameText && attr.type === NodeType.AttrNamed && attr.value?.type === NodeType.AttrValue && /^['"]$/.test(code[attr.value.value.start]) && linkedAttrs.get(code.slice(attr.name.start, attr.name.end))?.has(tag.nameText) || false;
1130
- }
1131
-
1132
1046
  // src/utils/file-system.ts
1133
1047
  import fs2 from "fs/promises";
1134
1048
  import { fileURLToPath } from "url";
@@ -1183,6 +1097,31 @@ function resolveUrl(to, base) {
1183
1097
  }
1184
1098
  }
1185
1099
 
1100
+ // src/service/marko/util/is-document-link-attr.ts
1101
+ import { NodeType } from "@marko/language-tools";
1102
+ var linkedAttrs = /* @__PURE__ */ new Map([
1103
+ [
1104
+ "src",
1105
+ /* @__PURE__ */ new Set([
1106
+ "audio",
1107
+ "embed",
1108
+ "iframe",
1109
+ "img",
1110
+ "input",
1111
+ "script",
1112
+ "source",
1113
+ "track",
1114
+ "video"
1115
+ ])
1116
+ ],
1117
+ ["href", /* @__PURE__ */ new Set(["a", "area", "link"])],
1118
+ ["data", /* @__PURE__ */ new Set(["object"])],
1119
+ ["poster", /* @__PURE__ */ new Set(["video"])]
1120
+ ]);
1121
+ function isDocumentLinkAttr(code, tag, attr) {
1122
+ return tag.nameText && attr.type === NodeType.AttrNamed && attr.value?.type === NodeType.AttrValue && /^['"]$/.test(code[attr.value.value.start]) && linkedAttrs.get(code.slice(attr.name.start, attr.name.end))?.has(tag.nameText) || false;
1123
+ }
1124
+
1186
1125
  // src/service/marko/complete/AttrValue.ts
1187
1126
  async function AttrValue({
1188
1127
  offset,
@@ -1379,12 +1318,12 @@ function OpenTagName({
1379
1318
  }
1380
1319
 
1381
1320
  // src/service/marko/complete/Tag.ts
1321
+ import { UNFINISHED } from "@marko/language-tools";
1382
1322
  import {
1383
1323
  CompletionItemKind as CompletionItemKind4,
1384
1324
  InsertTextFormat as InsertTextFormat3,
1385
1325
  TextEdit as TextEdit5
1386
1326
  } from "vscode-languageserver";
1387
- import { UNFINISHED } from "@marko/language-tools";
1388
1327
  var partialCloseTagReg = /<\/(?:[^><]*>)?/iy;
1389
1328
  function Tag({
1390
1329
  node,
@@ -1454,9 +1393,19 @@ var doComplete = async (doc, params) => {
1454
1393
  import { NodeType as NodeType5 } from "@marko/language-tools";
1455
1394
 
1456
1395
  // src/service/marko/definition/AttrName.ts
1396
+ import { getLines, getLocation } from "@marko/language-tools";
1457
1397
  import fs3 from "fs";
1458
1398
  import { URI as URI4 } from "vscode-uri";
1459
- import { getLines, getLocation } from "@marko/language-tools";
1399
+
1400
+ // src/utils/constants.ts
1401
+ var START_POSITION = {
1402
+ line: 0,
1403
+ character: 0
1404
+ };
1405
+ var START_LOCATION = {
1406
+ start: START_POSITION,
1407
+ end: START_POSITION
1408
+ };
1460
1409
 
1461
1410
  // src/utils/regexp-builder.ts
1462
1411
  function RegExpBuilder(strings, ...expressions) {
@@ -1482,16 +1431,6 @@ function escape(val) {
1482
1431
  return String(val).replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
1483
1432
  }
1484
1433
 
1485
- // src/utils/constants.ts
1486
- var START_POSITION = {
1487
- line: 0,
1488
- character: 0
1489
- };
1490
- var START_LOCATION = {
1491
- start: START_POSITION,
1492
- end: START_POSITION
1493
- };
1494
-
1495
1434
  // src/service/marko/definition/AttrName.ts
1496
1435
  function AttrName2({
1497
1436
  node,
@@ -1533,14 +1472,14 @@ function AttrName2({
1533
1472
  }
1534
1473
 
1535
1474
  // src/service/marko/definition/OpenTagName.ts
1536
- import fs4 from "fs";
1537
- import path5 from "path";
1538
- import { URI as URI5 } from "vscode-uri";
1539
1475
  import {
1540
- NodeType as NodeType4,
1541
1476
  getLines as getLines2,
1542
- getLocation as getLocation2
1477
+ getLocation as getLocation2,
1478
+ NodeType as NodeType4
1543
1479
  } from "@marko/language-tools";
1480
+ import fs4 from "fs";
1481
+ import path5 from "path";
1482
+ import { URI as URI5 } from "vscode-uri";
1544
1483
  function OpenTagName2({
1545
1484
  node,
1546
1485
  file: { parsed, lookup }
@@ -1682,8 +1621,8 @@ function extractDocumentLinks({
1682
1621
  }
1683
1622
 
1684
1623
  // src/service/marko/document-symbols.ts
1685
- import { SymbolKind } from "vscode-languageserver";
1686
1624
  import { NodeType as NodeType7 } from "@marko/language-tools";
1625
+ import { SymbolKind } from "vscode-languageserver";
1687
1626
  var findDocumentSymbols = async (doc) => processDoc(doc, extractDocumentSymbols);
1688
1627
  function extractDocumentSymbols({
1689
1628
  uri,
@@ -1727,6 +1666,33 @@ import { Project as Project3 } from "@marko/language-tools";
1727
1666
  import * as prettier from "prettier";
1728
1667
  import * as markoPrettier from "prettier-plugin-marko";
1729
1668
  import { TextEdit as TextEdit6 } from "vscode-languageserver";
1669
+
1670
+ // src/utils/messages.ts
1671
+ import { inspect } from "util";
1672
+ var connection;
1673
+ var previousMessagesByType = /* @__PURE__ */ new Map();
1674
+ function setup(_) {
1675
+ connection = _;
1676
+ }
1677
+ function displayError(data) {
1678
+ display("showError", data);
1679
+ }
1680
+ function display(type, data) {
1681
+ const msg = typeof data === "string" ? data : inspect(data, { colors: false });
1682
+ const previousMessages = previousMessagesByType.get(type);
1683
+ if (previousMessages) {
1684
+ if (previousMessages.includes(msg)) return;
1685
+ previousMessages.push(msg);
1686
+ if (previousMessages.length > 3) {
1687
+ previousMessages.unshift();
1688
+ }
1689
+ } else {
1690
+ previousMessagesByType.set(type, [msg]);
1691
+ }
1692
+ setImmediate(() => connection.sendNotification(type, msg));
1693
+ }
1694
+
1695
+ // src/service/marko/format.ts
1730
1696
  async function formatDocument(doc, formatOptions, cancel) {
1731
1697
  try {
1732
1698
  const dir = getFSDir(doc);
@@ -1805,10 +1771,10 @@ var doHover = async (doc, params) => {
1805
1771
  };
1806
1772
 
1807
1773
  // src/service/marko/validate.ts
1808
- import path6 from "path";
1774
+ import { DiagnosticType } from "@marko/babel-utils";
1809
1775
  import { Project as Project4 } from "@marko/language-tools";
1776
+ import path6 from "path";
1810
1777
  import { DiagnosticSeverity } from "vscode-languageserver";
1811
- import { DiagnosticType } from "@marko/babel-utils";
1812
1778
  var markoErrorRegExp = /^(.+?)\.marko(?:\((\d+)(?:\s*,\s*(\d+))?\))?: (.*)$/gm;
1813
1779
  var compilerConfig = {
1814
1780
  code: false,
@@ -1969,7 +1935,14 @@ var marko_default = {
1969
1935
  };
1970
1936
 
1971
1937
  // src/service/script/index.ts
1938
+ import {
1939
+ extractScript,
1940
+ NodeType as NodeType9,
1941
+ Project as Project5,
1942
+ ScriptLang
1943
+ } from "@marko/language-tools";
1972
1944
  import path8 from "path";
1945
+ import * as prettier2 from "prettier";
1973
1946
  import { relativeImportPath } from "relative-import-path";
1974
1947
  import ts from "typescript/lib/tsserverlibrary";
1975
1948
  import {
@@ -1980,21 +1953,14 @@ import {
1980
1953
  InsertTextFormat as InsertTextFormat4
1981
1954
  } from "vscode-languageserver";
1982
1955
  import { URI as URI6 } from "vscode-uri";
1983
- import * as prettier2 from "prettier";
1984
- import {
1985
- NodeType as NodeType9,
1986
- Project as Project5,
1987
- ScriptLang,
1988
- extractScript
1989
- } from "@marko/language-tools";
1990
1956
 
1991
1957
  // src/ts-plugin/host.ts
1992
- import path7 from "path";
1993
1958
  import {
1994
- Processors,
1995
1959
  getExt,
1996
- isDefinitionFile
1960
+ isDefinitionFile,
1961
+ Processors
1997
1962
  } from "@marko/language-tools";
1963
+ import path7 from "path";
1998
1964
  var fsPathReg = /^(?:[./\\]|[A-Z]:)/i;
1999
1965
  var modulePartsReg = /^((?:@(?:[^/]+)\/)?(?:[^/]+))(.*)$/;
2000
1966
  function patch(ts2, configFile, extractCache3, resolutionCache, host, ps) {
@@ -2165,6 +2131,42 @@ function patch(ts2, configFile, extractCache3, resolutionCache, host, ps) {
2165
2131
  }
2166
2132
  }
2167
2133
 
2134
+ // src/utils/workspace.ts
2135
+ var isInitialized = false;
2136
+ var connection2;
2137
+ var configChangeHandlers = /* @__PURE__ */ new Set();
2138
+ var settingsCache = /* @__PURE__ */ new Map();
2139
+ async function getConfig(section) {
2140
+ let cached = settingsCache.get(section);
2141
+ if (!cached) {
2142
+ try {
2143
+ cached = await connection2.workspace.getConfiguration(section) || {};
2144
+ settingsCache.set(section, cached);
2145
+ } catch {
2146
+ }
2147
+ }
2148
+ return cached;
2149
+ }
2150
+ function onConfigChange(handler) {
2151
+ configChangeHandlers.add(handler);
2152
+ }
2153
+ function setup2(_) {
2154
+ connection2 = _;
2155
+ connection2.onDidChangeConfiguration(() => {
2156
+ if (isInitialized) {
2157
+ settingsCache.clear();
2158
+ emitConfigChange();
2159
+ } else {
2160
+ isInitialized = true;
2161
+ }
2162
+ });
2163
+ }
2164
+ function emitConfigChange() {
2165
+ for (const handler of configChangeHandlers) {
2166
+ handler();
2167
+ }
2168
+ }
2169
+
2168
2170
  // src/service/script/util/print-jsdoc-tag.ts
2169
2171
  var REG_BACK_TICK = /`/g;
2170
2172
  var REG_LINE = /\r\n|\n/;
@@ -3079,6 +3081,7 @@ function getCanonicalFileName(fileName) {
3079
3081
  }
3080
3082
 
3081
3083
  // src/service/style/index.ts
3084
+ import { extractStyle } from "@marko/language-tools";
3082
3085
  import {
3083
3086
  getCSSLanguageService,
3084
3087
  getLESSLanguageService,
@@ -3088,7 +3091,6 @@ import {
3088
3091
  TextDocumentEdit
3089
3092
  } from "vscode-languageserver";
3090
3093
  import { TextDocument as TextDocument2 } from "vscode-languageserver-textdocument";
3091
- import { extractStyle } from "@marko/language-tools";
3092
3094
  var services = {
3093
3095
  ".css": getCSSLanguageService,
3094
3096
  ".less": getLESSLanguageService,
@@ -3756,7 +3758,7 @@ console.error = (...args) => {
3756
3758
  process.on("uncaughtException", console.error);
3757
3759
  process.on("unhandledRejection", console.error);
3758
3760
  connection3.onInitialize(async (params) => {
3759
- setup2(connection3);
3761
+ setup(connection3);
3760
3762
  await service.initialize(params);
3761
3763
  return {
3762
3764
  capabilities: {
@@ -3798,7 +3800,7 @@ connection3.onInitialize(async (params) => {
3798
3800
  }
3799
3801
  };
3800
3802
  });
3801
- setup(connection3);
3803
+ setup2(connection3);
3802
3804
  onConfigChange(validateDocs);
3803
3805
  connection3.onDidOpenTextDocument(async (params) => {
3804
3806
  doOpen(params);