@gi-tcg/gts-language-client-code 0.4.3 → 0.4.5

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/package.json +4 -1
  2. package/src/decoration.ts +18 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gi-tcg/gts-language-client-code",
3
- "version": "0.4.3",
3
+ "version": "0.4.5",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./decoration": "./src/decoration.ts"
@@ -14,6 +14,9 @@
14
14
  "devDependencies": {
15
15
  "@types/vscode": "^1.120.0"
16
16
  },
17
+ "dependencies": {
18
+ "remeda": "^2.39.0"
19
+ },
17
20
  "scripts": {
18
21
  "build:svg": "node ./scripts/build_svg.ts",
19
22
  "build": "pnpm build:svg"
package/src/decoration.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type * as vscode from "vscode";
2
2
  import * as SVG from "./svg.ts";
3
+ import { funnel } from "remeda";
3
4
 
4
5
  declare global {
5
6
  function btoa(str: string): string;
@@ -42,12 +43,14 @@ export function registerDecorations(
42
43
  );
43
44
  }
44
45
  let activeEditor = vscode.window.activeTextEditor;
45
- // TODO: throttle
46
- const triggerUpdateDecorations = (throttle: boolean) => {
47
- void throttle;
46
+
47
+ const updateDecorations = () => {
48
48
  if (!activeEditor) {
49
49
  return;
50
50
  }
51
+ if (activeEditor.document.languageId !== "gaming-ts") {
52
+ return;
53
+ }
51
54
  const text = activeEditor.document.getText();
52
55
  let match;
53
56
  const regex = new RegExp(`\\b(${Object.keys(SVG).join("|")})\\b`, "ig");
@@ -57,7 +60,7 @@ export function registerDecorations(
57
60
  const endPos = activeEditor.document.positionAt(
58
61
  match.index + match[0].length,
59
62
  );
60
- const element = match[1] as ElementType;
63
+ const element = match[1].toLowerCase() as ElementType;
61
64
  if (!decorations.has(element)) {
62
65
  decorations.set(element, []);
63
66
  }
@@ -69,6 +72,17 @@ export function registerDecorations(
69
72
  activeEditor.setDecorations(decType, decorations.get(element) ?? []);
70
73
  }
71
74
  };
75
+ const throttledUpdateDecorations = funnel(updateDecorations, {
76
+ minGapMs: 100,
77
+ triggerAt: "start",
78
+ });
79
+ const triggerUpdateDecorations = (throttle: boolean) => {
80
+ if (throttle) {
81
+ throttledUpdateDecorations.call();
82
+ } else {
83
+ updateDecorations();
84
+ }
85
+ };
72
86
  if (activeEditor) {
73
87
  triggerUpdateDecorations(false);
74
88
  }