@fluixi/ts-plugin 0.1.0-alpha.2 → 0.1.0-alpha.20

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 (3) hide show
  1. package/README.md +45 -14
  2. package/dist/index.js +1306 -710
  3. package/package.json +5 -3
package/README.md CHANGED
@@ -1,34 +1,49 @@
1
1
  # @fluixi/ts-plugin
2
2
 
3
- A TypeScript language-service plugin that teaches `tsserver` about Fluixi
4
- `` html`...` `` templates.
3
+ A TypeScript language-service plugin that gives `` html`...` `` templates the same editor
4
+ support JSX gets.
5
5
 
6
6
  ## The problem
7
7
 
8
- TypeScript sees a tagged template as an opaque string. A component referenced
9
- only by tag inside a template —
8
+ TypeScript sees a tagged template as an opaque string. Everything inside it falls off the
9
+ map: a component referenced only by tag is reported "declared but never used", a callback
10
+ param is an implicit `any`, nothing completes, hover says nothing, and go-to-definition
11
+ lands on the template literal instead of the component.
10
12
 
11
13
  ```ts
12
14
  function UserCard() { /* … */ }
13
15
 
14
16
  const app = html`<main><UserCard /></main>`;
17
+ // ^ greyed out — TypeScript never counted this as a reference
15
18
  ```
16
19
 
17
- is never counted as a reference, so `UserCard` is reported as **"declared but
18
- never used"** and greyed out, even though it's used.
20
+ Authoring in `` html`` `` shouldn't cost you the editor.
19
21
 
20
- ## The fix
22
+ ## What you get
21
23
 
22
- This plugin proxies the language service, reparses each `` html`` ``/`` svg`` ``
23
- template with [`@fluixi/template-parser`](../template-parser), collects the
24
- component tag names, and drops the "unused" diagnostics for those bindings — for
25
- both local declarations and imports.
24
+ Reparse the template with [`@fluixi/template-parser`](../template-parser), map every tag and
25
+ hole back to a real source position, and ask the program's own checker about it:
26
+
27
+ - **Hover** a component tag shows its signature, a prop shows its declared type, an
28
+ element attribute shows what it takes, and an inferred callback param (`each`, `event`,
29
+ `ref`, `use`, `Show`) shows the type it was inferred to.
30
+ - **Completion** — component prop names inside a tag, element attributes on an intrinsic
31
+ tag, and members of an inferred param (`it.`, `el.`, `e.`).
32
+ - **Navigation** — go-to-definition, find-all-references and rename work through tags.
33
+ Rename only adds tags when TypeScript's own rename succeeded, so you never get a
34
+ rewritten `<Tag>` with a stale `</Tag>`.
35
+ - **Diagnostics** — a bare accessor in a template (`` html`<p>${count}</p>` ``) is flagged,
36
+ since it renders the function once and never updates; a property that doesn't exist on an
37
+ inferred param is reported.
38
+ - **Quiet where it should be** — unused-component reports and implicit-`any` noise on params
39
+ the template can infer are dropped.
40
+ - **Quick fixes** — "Call `count`" for a bare accessor, with a fix-all for the file.
26
41
 
27
42
  ## Enable it
28
43
 
29
- Add it to your project's `tsconfig.json` and use the **workspace** TypeScript
30
- version (VS Code: `TypeScript: Select TypeScript Version → Use Workspace
31
- Version`, since tsconfig plugins only load under the workspace TS):
44
+ Add it to your project's `tsconfig.json` and use the **workspace** TypeScript version
45
+ (VS Code: `TypeScript: Select TypeScript Version → Use Workspace Version` — tsconfig plugins
46
+ only load under the workspace TS):
32
47
 
33
48
  ```jsonc
34
49
  {
@@ -38,6 +53,22 @@ Version`, since tsconfig plugins only load under the workspace TS):
38
53
  }
39
54
  ```
40
55
 
56
+ Nothing else. JSX needs no plugin, and neither do the `$signal`-style intrinsics — those are
57
+ typed by the `fluixi.d.ts` the compiler generates.
58
+
59
+ ## How it stays out of the way
60
+
61
+ Everything is computed on the **existing** program's checker. The plugin creates no language
62
+ service, adds no files, and never touches the host — it wraps the service it's handed, and
63
+ every addition is wrapped so a failure costs the extra information, never the real answer.
64
+
65
+ That restraint is deliberate. Two earlier designs for deep type-checking inside `${…}` holes
66
+ both had to go: a second `ts.LanguageService` meant a second document registry, so lib.d.ts
67
+ and node_modules were parsed twice; and shadow files added via `getScriptFileNames` re-entered
68
+ host machinery on every project sync and crashed the language service outright. Hole
69
+ diagnostics weren't worth either — a `${…}` hole is a real expression, so TypeScript already
70
+ checks it.
71
+
41
72
  ## License
42
73
 
43
74
  MIT