ts-gem-plugin 0.0.6 → 0.0.7

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.
Files changed (2) hide show
  1. package/dist/index.js +85 -83
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -158,11 +158,14 @@ var Configuration = class {
158
158
  }
159
159
  };
160
160
 
161
+ // src/constants.ts
162
+ var NAME = "gem-plugin";
163
+
161
164
  // src/context.ts
162
- var import_vscode_html_languageservice2 = require("@mantou/vscode-html-languageservice");
163
- var import_standard_template_source_helper = __toESM(require("@mantou/typescript-template-language-service-decorator/lib/standard-template-source-helper"));
164
165
  var import_standard_script_source_helper = __toESM(require("@mantou/typescript-template-language-service-decorator/lib/standard-script-source-helper"));
166
+ var import_standard_template_source_helper = __toESM(require("@mantou/typescript-template-language-service-decorator/lib/standard-template-source-helper"));
165
167
  var import_vscode_css_languageservice = require("@mantou/vscode-css-languageservice");
168
+ var import_vscode_html_languageservice2 = require("@mantou/vscode-html-languageservice");
166
169
 
167
170
  // ../duoyun-ui/lib/map.js
168
171
  var StringWeakMap = class {
@@ -188,6 +191,76 @@ var StringWeakMap = class {
188
191
  }
189
192
  };
190
193
 
194
+ // ../duoyun-ui/lib/cache.js
195
+ var Cache = class {
196
+ #max;
197
+ #maxAge;
198
+ #renewal;
199
+ #map = /* @__PURE__ */ new Map();
200
+ #reverseMap = /* @__PURE__ */ new Map();
201
+ #addedLinked = new LinkedList();
202
+ constructor({ max = Infinity, maxAge = Infinity, renewal = false } = {}) {
203
+ this.#max = max;
204
+ this.#maxAge = maxAge;
205
+ this.#renewal = renewal;
206
+ }
207
+ setOptions(options) {
208
+ this.#max = options.max ?? this.#max;
209
+ this.#maxAge = options.maxAge ?? this.#maxAge;
210
+ this.#renewal = options.renewal ?? this.#renewal;
211
+ }
212
+ #trim() {
213
+ for (let i = this.#addedLinked.size - this.#max; i > 0; i--) {
214
+ const value = this.#addedLinked.get();
215
+ const key = this.#reverseMap.get(value);
216
+ this.#reverseMap.delete(value);
217
+ this.#map.delete(key);
218
+ }
219
+ }
220
+ set(key, value) {
221
+ this.#addedLinked.add(value);
222
+ this.#reverseMap.set(value, key);
223
+ this.#map.set(key, { value, timestamp: Date.now() });
224
+ this.#trim();
225
+ return value;
226
+ }
227
+ get(key, init) {
228
+ const cache = this.#map.get(key);
229
+ if (!cache) {
230
+ return init && this.set(key, init(key));
231
+ }
232
+ const { timestamp, value } = cache;
233
+ if (Date.now() - timestamp > this.#maxAge) {
234
+ this.#addedLinked.delete(value);
235
+ this.#reverseMap.delete(value);
236
+ this.#map.delete(key);
237
+ return init && this.set(key, init(key));
238
+ }
239
+ if (this.#renewal) {
240
+ cache.timestamp = Date.now();
241
+ }
242
+ this.#addedLinked.add(value);
243
+ return value;
244
+ }
245
+ };
246
+
247
+ // src/cache.ts
248
+ var LRUCache = class {
249
+ #bucket;
250
+ constructor(args) {
251
+ this.#bucket = new Cache({ max: 25, renewal: true, ...args });
252
+ }
253
+ #genKey(context, position) {
254
+ return [context.fileName, position?.line, position?.character, context.text].join(";");
255
+ }
256
+ get(context, position, init) {
257
+ return this.#bucket.get(this.#genKey(context, position), init);
258
+ }
259
+ };
260
+
261
+ // src/data-provider.ts
262
+ var import_vscode_html_languageservice = require("@mantou/vscode-html-languageservice");
263
+
191
264
  // src/utils.ts
192
265
  function isCustomElementTag(tag) {
193
266
  return tag.includes("-");
@@ -265,12 +338,6 @@ function decorate(origin, cb) {
265
338
  return result;
266
339
  }
267
340
 
268
- // src/data-provider.ts
269
- var import_vscode_html_languageservice = require("@mantou/vscode-html-languageservice");
270
-
271
- // src/constants.ts
272
- var NAME = "gem-plugin";
273
-
274
341
  // src/data-provider.ts
275
342
  var dataProvider = (0, import_vscode_html_languageservice.getDefaultHTMLDataProvider)();
276
343
  var HTMLDataProvider = class {
@@ -373,73 +440,6 @@ function getDocComment(typescript, declaration) {
373
440
  return commentStrings?.join("\n\n");
374
441
  }
375
442
 
376
- // ../duoyun-ui/lib/cache.js
377
- var Cache = class {
378
- #max;
379
- #maxAge;
380
- #renewal;
381
- #map = /* @__PURE__ */ new Map();
382
- #reverseMap = /* @__PURE__ */ new Map();
383
- #addedLinked = new LinkedList();
384
- constructor({ max = Infinity, maxAge = Infinity, renewal = false } = {}) {
385
- this.#max = max;
386
- this.#maxAge = maxAge;
387
- this.#renewal = renewal;
388
- }
389
- setOptions(options) {
390
- this.#max = options.max ?? this.#max;
391
- this.#maxAge = options.maxAge ?? this.#maxAge;
392
- this.#renewal = options.renewal ?? this.#renewal;
393
- }
394
- #trim() {
395
- for (let i = this.#addedLinked.size - this.#max; i > 0; i--) {
396
- const value = this.#addedLinked.get();
397
- const key = this.#reverseMap.get(value);
398
- this.#reverseMap.delete(value);
399
- this.#map.delete(key);
400
- }
401
- }
402
- set(key, value) {
403
- this.#addedLinked.add(value);
404
- this.#reverseMap.set(value, key);
405
- this.#map.set(key, { value, timestamp: Date.now() });
406
- this.#trim();
407
- return value;
408
- }
409
- get(key, init) {
410
- const cache = this.#map.get(key);
411
- if (!cache) {
412
- return init && this.set(key, init(key));
413
- }
414
- const { timestamp, value } = cache;
415
- if (Date.now() - timestamp > this.#maxAge) {
416
- this.#addedLinked.delete(value);
417
- this.#reverseMap.delete(value);
418
- this.#map.delete(key);
419
- return init && this.set(key, init(key));
420
- }
421
- if (this.#renewal) {
422
- cache.timestamp = Date.now();
423
- }
424
- this.#addedLinked.add(value);
425
- return value;
426
- }
427
- };
428
-
429
- // src/cache.ts
430
- var LRUCache = class {
431
- #bucket;
432
- constructor(args) {
433
- this.#bucket = new Cache({ max: 25, renewal: true, ...args });
434
- }
435
- #genKey(context, position) {
436
- return [context.fileName, position?.line, position?.character, context.text].join(";");
437
- }
438
- get(context, position, init) {
439
- return this.#bucket.get(this.#genKey(context, position), init);
440
- }
441
- };
442
-
443
443
  // src/context.ts
444
444
  var Context = class {
445
445
  elements;
@@ -582,7 +582,7 @@ function getSubstitution(templateString, start, end) {
582
582
  function isValidCSSTemplate(typescript, node, callName) {
583
583
  switch (node.kind) {
584
584
  case typescript.SyntaxKind.NoSubstitutionTemplateLiteral:
585
- case typescript.SyntaxKind.TemplateExpression:
585
+ case typescript.SyntaxKind.TemplateExpression: {
586
586
  const parent = node.parent;
587
587
  if (typescript.isCallExpression(parent) && parent.expression.getText() === callName) {
588
588
  return true;
@@ -594,6 +594,7 @@ function isValidCSSTemplate(typescript, node, callName) {
594
594
  }
595
595
  }
596
596
  return false;
597
+ }
597
598
  default:
598
599
  return false;
599
600
  }
@@ -662,8 +663,6 @@ function translationCompletionItemKind(context, kind) {
662
663
  return typescript.ScriptElementKind.alias;
663
664
  case vscode.CompletionItemKind.File:
664
665
  return typescript.ScriptElementKind.moduleElement;
665
- case vscode.CompletionItemKind.Snippet:
666
- case vscode.CompletionItemKind.Text:
667
666
  default:
668
667
  return typescript.ScriptElementKind.unknown;
669
668
  }
@@ -727,11 +726,11 @@ function genDefaultCompletionEntryDetails(context, name) {
727
726
  }
728
727
  function toDisplayParts(text, isDoc = false) {
729
728
  if (!text) return [];
730
- const escape = (unsafe) => unsafe.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;").replaceAll(" ", "&nbsp;").replaceAll("\n", " \n").replaceAll(" ", "&emsp;");
729
+ const escapeText = (unsafe) => unsafe.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;").replaceAll(" ", "&nbsp;").replaceAll("\n", " \n").replaceAll(" ", "&emsp;");
731
730
  return [
732
731
  {
733
732
  kind: "unknown",
734
- text: typeof text !== "string" ? text.value : isDoc ? escape(text) : text
733
+ text: typeof text !== "string" ? text.value : isDoc ? escapeText(text) : text
735
734
  }
736
735
  ];
737
736
  }
@@ -1082,7 +1081,7 @@ var HTMLLanguageService = class {
1082
1081
  if (hasValueSpan) {
1083
1082
  const spanType = getSpanType(this.#ctx.ts, typeChecker, file, offset, end);
1084
1083
  switch (attrInfo.decorate) {
1085
- case "?":
1084
+ case "?": {
1086
1085
  const boolType = getUnionType(typeChecker, [
1087
1086
  typeChecker.getBooleanType(),
1088
1087
  typeChecker.getUndefinedType(),
@@ -1092,6 +1091,7 @@ var HTMLLanguageService = class {
1092
1091
  diagnostics.push(diagnostic);
1093
1092
  }
1094
1093
  continue;
1094
+ }
1095
1095
  case ".":
1096
1096
  case "@":
1097
1097
  if (!typeChecker.isTypeAssignableTo(spanType, propType)) {
@@ -1121,7 +1121,6 @@ var HTMLLanguageService = class {
1121
1121
  } else if (types.every((t) => !typeChecker.isTypeAssignableTo(t, propType))) {
1122
1122
  diagnostics.push(diagnostic);
1123
1123
  }
1124
- continue;
1125
1124
  }
1126
1125
  }
1127
1126
  });
@@ -1197,6 +1196,8 @@ function getPropType(typeChecker, tagClassDeclaration, attrInfo) {
1197
1196
  case "style":
1198
1197
  case "part":
1199
1198
  case "exportparts":
1199
+ case "xmlns":
1200
+ case "viewBox":
1200
1201
  return typeChecker.getStringType();
1201
1202
  case "tabindex":
1202
1203
  return typeChecker.getNumberType();
@@ -1208,13 +1209,14 @@ function getPropType(typeChecker, tagClassDeclaration, attrInfo) {
1208
1209
  typeChecker.getBooleanType(),
1209
1210
  typeChecker.getUndefinedType()
1210
1211
  ]);
1211
- default:
1212
+ default: {
1212
1213
  const isEvent = attrInfo.decorate === "@";
1213
1214
  const propSymbol = classType.getProperty(propName);
1214
1215
  const propType = propSymbol && typeChecker.getTypeOfSymbol(propSymbol);
1215
1216
  if (!isEvent) return propType;
1216
1217
  const eventHandleType = getEmitterHandleType(typeChecker, classType, propType);
1217
1218
  return getUnionType(typeChecker, [eventHandleType, typeChecker.getUndefinedType()]);
1219
+ }
1218
1220
  }
1219
1221
  }
1220
1222
  function getEmitterHandleType(typeChecker, classType, propType) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-gem-plugin",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Typescript language service plugin for Gem",
5
5
  "keywords": [
6
6
  "gem",
@@ -18,7 +18,7 @@
18
18
  "@mantou/typescript-template-language-service-decorator": "^2.3.4",
19
19
  "@mantou/vscode-css-languageservice": "^6.3.3",
20
20
  "@mantou/vscode-emmet-helper": "^2.9.3",
21
- "@mantou/vscode-html-languageservice": "^5.3.4",
21
+ "@mantou/vscode-html-languageservice": "^5.3.6",
22
22
  "duoyun-ui": "^2.2.0",
23
23
  "vscode-languageserver-textdocument": "^1.0.12",
24
24
  "vscode-languageserver-types": "^3.17.5"