@fluixi/ts-plugin 0.1.0-alpha.25 → 0.1.0-alpha.26

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.
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Components the compiler auto-imports.
3
+ *
4
+ * `<Show>`, `<Portal>`, `<Suspense>`, `<Outlet>` and friends work in a template
5
+ * with no import: the compiler injects one. That's good ergonomics and bad for
6
+ * tooling: there is no binding in the file, so `getSymbolsInScope` finds nothing
7
+ * and every symbol-driven feature (definition, references, rename, hover) goes
8
+ * quiet on exactly the components used most.
9
+ *
10
+ * So resolve them the way the compiler would: find the module it would import
11
+ * from, and look the name up there.
12
+ *
13
+ * The names come from `@fluixi/compiler/builtins`, which exists so this list is not
14
+ * copied. It used to be duplicated here: the plugin is an esbuild bundle and pulling
15
+ * in the compiler would dwarf it: with a spec reading the compiler source to pin the
16
+ * two together. That subpath is pure data with no compiler code behind it, so the
17
+ * bundle stays small and the copy is gone.
18
+ */
19
+ import type * as TS from 'typescript';
20
+ /** Tag name → the module the compiler injects an import from. */
21
+ export declare const AUTO_IMPORTED: Readonly<Record<string, string>>;
22
+ /** Where a name is declared: enough for a jump, without needing the checker. */
23
+ export interface DeclarationSite {
24
+ fileName: string;
25
+ start: number;
26
+ length: number;
27
+ }
28
+ /**
29
+ * Find where a module declares a name, reading from disk.
30
+ *
31
+ * Needed because an auto-imported component means nothing imports its module, so
32
+ * the module's declarations are usually NOT in the program and the checker can say
33
+ * nothing about them. Definition only needs a file and a span, so it can be
34
+ * answered without the program: following `export *` re-exports through the
35
+ * barrels these packages are built from.
36
+ */
37
+ export declare function declarationSite(ts: typeof TS, program: TS.Program, host: TS.ModuleResolutionHost, from: TS.SourceFile, name: string): DeclarationSite | undefined;
38
+ /**
39
+ * The symbol for an auto-imported component tag, or undefined when the name isn't
40
+ * one or the module can't be resolved.
41
+ */
42
+ export declare function autoImportedSymbol(ts: typeof TS, program: TS.Program, host: TS.ModuleResolutionHost, from: TS.SourceFile, name: string): TS.Symbol | undefined;
43
+ //# sourceMappingURL=auto-import.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-import.d.ts","sourceRoot":"","sources":["../src/auto-import.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAGtC,iEAAiE;AACjE,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAyB,CAAC;AAkCrF,gFAAgF;AAChF,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAID;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,EAAE,EAAE,OAAO,EAAE,EACb,OAAO,EAAE,EAAE,CAAC,OAAO,EACnB,IAAI,EAAE,EAAE,CAAC,oBAAoB,EAC7B,IAAI,EAAE,EAAE,CAAC,UAAU,EACnB,IAAI,EAAE,MAAM,GACX,eAAe,GAAG,SAAS,CAuB7B;AAoFD;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,OAAO,EAAE,EACb,OAAO,EAAE,EAAE,CAAC,OAAO,EACnB,IAAI,EAAE,EAAE,CAAC,oBAAoB,EAC7B,IAAI,EAAE,EAAE,CAAC,UAAU,EACnB,IAAI,EAAE,MAAM,GACX,EAAE,CAAC,MAAM,GAAG,SAAS,CAevB"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Per-file caches for work that would otherwise repeat on every keystroke.
3
+ *
4
+ * Everything is keyed on the `SourceFile` object, which TypeScript replaces
5
+ * whenever the file changes: so a `WeakMap` gives exact invalidation for free,
6
+ * with no version bookkeeping and no way to serve a stale parse.
7
+ *
8
+ * This matters because the editor calls completion/hover/diagnostics several
9
+ * times per keystroke, and each entry point needs the same parsed template.
10
+ */
11
+ import type * as TS from 'typescript';
12
+ import { type ParseResult } from '@fluixi/template-parser';
13
+ /** Parse a template, reusing the result for as long as the file is unchanged. */
14
+ export declare function parseCached(ts: typeof TS, sf: TS.SourceFile, tpl: TS.TemplateLiteral): ParseResult;
15
+ /**
16
+ * Every `html`/`svg` template in the file, collected in one AST walk instead of
17
+ * one walk per lookup. Sorted by start so a position lookup is a binary search.
18
+ *
19
+ * A file that cannot contain a template skips the walk entirely. The plugin is loaded
20
+ * by tsserver in every project, so most files it sees have no `` html`` `` at all, and
21
+ * scanning the text for the tag is far cheaper than traversing the AST to prove it.
22
+ */
23
+ export declare function templatesIn(ts: typeof TS, sf: TS.SourceFile): TS.TaggedTemplateExpression[];
24
+ /**
25
+ * The innermost template containing `pos`. Templates nest (a template can appear
26
+ * inside a `${…}` hole), so the last match wins.
27
+ */
28
+ export declare function templateAtCached(ts: typeof TS, sf: TS.SourceFile, pos: number): TS.TaggedTemplateExpression | undefined;
29
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAK1E,iFAAiF;AACjF,wBAAgB,WAAW,CACzB,EAAE,EAAE,OAAO,EAAE,EACb,EAAE,EAAE,EAAE,CAAC,UAAU,EACjB,GAAG,EAAE,EAAE,CAAC,eAAe,GACtB,WAAW,CAab;AAgBD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,UAAU,GAAG,EAAE,CAAC,wBAAwB,EAAE,CAwB3F;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,EAAE,EAAE,OAAO,EAAE,EACb,EAAE,EAAE,EAAE,CAAC,UAAU,EACjB,GAAG,EAAE,MAAM,GACV,EAAE,CAAC,wBAAwB,GAAG,SAAS,CAQzC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The pure logic behind the plugin: which identifiers a file references ONLY
3
+ * through `` html`` `` component tags (so TypeScript can't see them), and whether
4
+ * a given "unused" diagnostic should therefore be suppressed.
5
+ *
6
+ * A `<UserCard/>` inside a template is plain text to TypeScript, it never
7
+ * counts as a reference, so the binding gets flagged "declared but never used".
8
+ * We reparse each template with `@fluixi/template-parser`, collect the component
9
+ * tag roots, and treat those names as used.
10
+ *
11
+ * The `typescript` module is passed in (the instance tsserver hands the plugin
12
+ * via `init({ typescript })`) rather than imported, so the plugin uses the exact
13
+ * TS the editor is running: never a second copy resolved from node_modules.
14
+ */
15
+ import type * as TS from 'typescript';
16
+ export declare function isUnusedCode(code: number): boolean;
17
+ /**
18
+ * Component tag roots referenced inside html``/svg`` templates in the file.
19
+ *
20
+ * Cached on the `SourceFile`, which TypeScript replaces on edit. It has to be: the
21
+ * editor asks for semantic AND suggestion diagnostics on every keystroke, so an
22
+ * uncached walk here cost two full traversals of every open file per keypress ,
23
+ * including files with no templates at all, in any project the extension activates
24
+ * for. Reuses `templatesIn` and `parseCached` so a file with no `` html`` `` costs
25
+ * one cached lookup and nothing else.
26
+ */
27
+ export declare function usedComponentTags(ts: typeof TS, sourceFile: TS.SourceFile): Set<string>;
28
+ /**
29
+ * Whether `diagnostic` is an "unused" report for a binding that IS used through
30
+ * a template component tag: and should therefore be dropped.
31
+ */
32
+ export declare function shouldSuppress(ts: typeof TS, sourceFile: TS.SourceFile, diagnostic: TS.Diagnostic, used: ReadonlySet<string>): boolean;
33
+ //# sourceMappingURL=collect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collect.d.ts","sourceRoot":"","sources":["../src/collect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAOtC,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAElD;AAID;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,CAUvF;AAYD;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,EAAE,EAAE,OAAO,EAAE,EACb,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,GACxB,OAAO,CAmBT"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Member completion for inferred callback params inside html`` templates.
3
+ *
4
+ * At `${(it) => it.|}` TypeScript sees `it` as implicit `any`, so its own
5
+ * completion offers nothing useful. We infer `it`'s type from the template
6
+ * (each item, event, ref/use element, …) and return that type's members, the
7
+ * same list JSX would show. Runs entirely on the main language service.
8
+ */
9
+ import type * as TS from 'typescript';
10
+ export declare function paramMemberCompletions(ts: typeof TS, ls: TS.LanguageService, fileName: string, position: number): TS.CompletionEntry[] | undefined;
11
+ //# sourceMappingURL=completion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completion.d.ts","sourceRoot":"","sources":["../src/completion.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAGtC,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,OAAO,EAAE,EACb,EAAE,EAAE,EAAE,CAAC,eAAe,EACtB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,EAAE,CAAC,eAAe,EAAE,GAAG,SAAS,CA6BlC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Type errors inside `${…}` holes, checked against the MAIN program.
3
+ *
4
+ * A `${(it) => it.nope}` is a real expression in a real file, TypeScript has
5
+ * already parsed and bound it. The only thing it lacks is a contextual type for
6
+ * `it`, which is why the mistake goes unreported: `it` is implicitly `any`, and
7
+ * every property access on `any` is allowed.
8
+ *
9
+ * So rather than building a parallel document to make the checker see the
10
+ * template, we supply the missing type ourselves (the same inference hover uses)
11
+ * and ask the checker whether each property access holds. Spans are real source
12
+ * positions, so nothing needs mapping: and nothing is added to the program, no
13
+ * second service exists, and the host is never touched.
14
+ *
15
+ * The trade-off is honest: this catches property access on an inferred parameter,
16
+ * which is the mistake templates actually produce. It is not a general type-check
17
+ * of hole contents.
18
+ */
19
+ import type * as TS from 'typescript';
20
+ /** The plugin's own diagnostic code for a bare accessor, shared with its fix. */
21
+ export declare const ACCESSOR_NOT_CALLED = 9001;
22
+ export declare function templateDiagnostics(ts: typeof TS, ls: TS.LanguageService, fileName: string): TS.Diagnostic[];
23
+ //# sourceMappingURL=diagnostics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAKtC,iFAAiF;AACjF,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAyGxC,wBAAgB,mBAAmB,CACjC,EAAE,EAAE,OAAO,EAAE,EACb,EAAE,EAAE,EAAE,CAAC,eAAe,EACtB,QAAQ,EAAE,MAAM,GACf,EAAE,CAAC,UAAU,EAAE,CAiDjB"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Element attribute support inside html`` templates.
3
+ *
4
+ * Everything here is driven by `IntrinsicElements` from `@fluixi/dom/attributes`
5
+ *: the same tag → attributes map JSX type-checks against, so html`` and JSX
6
+ * agree on what an element accepts, and neither needs the other's package.
7
+ *
8
+ * The editor's HTML language service already offers the standard HTML attribute
9
+ * names from MDN data. What it cannot know is the framework's surface: `classList`,
10
+ * `onClick`, the `Reactive<T>` value types, `prop:`/`attr:`/`bool:`. That comes
11
+ * from the type, which is what this adds.
12
+ *
13
+ * Performance: the resolved type is cached per Program, and the attribute list per
14
+ * tag, so a keystroke costs a map lookup rather than a module resolution.
15
+ */
16
+ import type * as TS from 'typescript';
17
+ /** Attribute-name completion for a native element inside a template. */
18
+ export declare function elementAttributeCompletions(ts: typeof TS, ls: TS.LanguageService, host: TS.ModuleResolutionHost, fileName: string, position: number): TS.CompletionEntry[] | undefined;
19
+ /** Hover over an element attribute name: its declared type, from the same map. */
20
+ export declare function elementAttributeHover(ts: typeof TS, ls: TS.LanguageService, host: TS.ModuleResolutionHost, fileName: string, position: number): TS.QuickInfo | undefined;
21
+ //# sourceMappingURL=elements.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../src/elements.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAkJtC,wEAAwE;AACxE,wBAAgB,2BAA2B,CACzC,EAAE,EAAE,OAAO,EAAE,EACb,EAAE,EAAE,EAAE,CAAC,eAAe,EACtB,IAAI,EAAE,EAAE,CAAC,oBAAoB,EAC7B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,EAAE,CAAC,eAAe,EAAE,GAAG,SAAS,CA0BlC;AAsCD,kFAAkF;AAClF,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,OAAO,EAAE,EACb,EAAE,EAAE,EAAE,CAAC,eAAe,EACtB,IAAI,EAAE,EAAE,CAAC,oBAAoB,EAC7B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,EAAE,CAAC,SAAS,GAAG,SAAS,CAqC1B"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Quick fixes for the plugin's own diagnostics.
3
+ *
4
+ * A diagnostic you can't act on is half a feature: the editor shows a squiggle,
5
+ * and the fix: which the rule already knows exactly, is left to be typed by
6
+ * hand. Every rule that can name its remedy should offer it.
7
+ *
8
+ * These are keyed to the plugin's diagnostic codes, so they appear alongside
9
+ * TypeScript's own fixes rather than replacing them.
10
+ */
11
+ import type * as TS from 'typescript';
12
+ /**
13
+ * Fixes for a span. Returns only fixes for the plugin's codes; TypeScript's are
14
+ * added by the caller, which leaves its own list untouched.
15
+ */
16
+ export declare function templateCodeFixes(ts: typeof TS, ls: TS.LanguageService, fileName: string, start: number, end: number, errorCodes: readonly number[]): TS.CodeFixAction[];
17
+ /** The same edit applied to every occurrence in the file. */
18
+ export declare function templateFixAll(ts: typeof TS, ls: TS.LanguageService, fileName: string, errorCodes: readonly number[]): TS.CombinedCodeActions | undefined;
19
+ //# sourceMappingURL=fixes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixes.d.ts","sourceRoot":"","sources":["../src/fixes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAGtC;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,OAAO,EAAE,EACb,EAAE,EAAE,EAAE,CAAC,eAAe,EACtB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,SAAS,MAAM,EAAE,GAC5B,EAAE,CAAC,aAAa,EAAE,CA0BpB;AAED,6DAA6D;AAC7D,wBAAgB,cAAc,CAC5B,EAAE,EAAE,OAAO,EAAE,EACb,EAAE,EAAE,EAAE,CAAC,eAAe,EACtB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,SAAS,MAAM,EAAE,GAC5B,EAAE,CAAC,mBAAmB,GAAG,SAAS,CAcpC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Hover for component tags inside `` html`` `` templates.
3
+ *
4
+ * TypeScript sees `<AsyncName …>` as text in a string, so hovering the tag shows
5
+ * nothing. We map the tag to the binding it names, then return the SAME quick
6
+ * info TypeScript would show for that binding (its signature/type), remapped so
7
+ * the hover highlights the tag in the template. Same idea as ts-lit-plugin.
8
+ */
9
+ import type * as TS from 'typescript';
10
+ export declare function componentQuickInfo(ts: typeof TS, ls: TS.LanguageService, host: TS.ModuleResolutionHost, fileName: string, position: number): TS.QuickInfo | undefined;
11
+ //# sourceMappingURL=hover.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hover.d.ts","sourceRoot":"","sources":["../src/hover.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAKtC,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,OAAO,EAAE,EACb,EAAE,EAAE,EAAE,CAAC,eAAe,EACtB,IAAI,EAAE,EAAE,CAAC,oBAAoB,EAC7B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,EAAE,CAAC,SAAS,GAAG,SAAS,CAgC1B"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Fluixi TypeScript language-service plugin.
3
+ *
4
+ * Gives html`` templates real TypeScript support: hovering a callback param shows
5
+ * its inferred type, element and component attributes complete and hover, a wrong
6
+ * property on an inferred param is reported, the implicit-any noise on those params
7
+ * is dropped, and a component used only through a tag isn't reported unused.
8
+ *
9
+ * Everything is computed on the EXISTING program's checker. The plugin creates no
10
+ * language service, adds no files, and does not touch the host, it only wraps
11
+ * the service it is handed.
12
+ *
13
+ * That restraint is deliberate. Two earlier designs for deep type-checking inside
14
+ * `${…}` holes both had to go: a second `ts.LanguageService` (a second document
15
+ * registry, so lib.d.ts and node_modules were parsed twice), and shadow files
16
+ * added to the program by patching `getScriptFileNames`, which tsserver calls on
17
+ * every project sync, so building shadows there re-entered host machinery and
18
+ * crashed the language service outright. Hole diagnostics are not worth either.
19
+ *
20
+ * Enable it in a project's tsconfig (using the workspace TypeScript version):
21
+ * { "compilerOptions": { "plugins": [{ "name": "@fluixi/ts-plugin" }] } }
22
+ */
23
+ import type * as ts from 'typescript';
24
+ interface PluginCreateInfo {
25
+ languageService: ts.LanguageService;
26
+ languageServiceHost: ts.LanguageServiceHost;
27
+ project?: {
28
+ projectService?: {
29
+ logger?: {
30
+ info(message: string): void;
31
+ };
32
+ };
33
+ };
34
+ }
35
+ interface PluginModule {
36
+ create(info: PluginCreateInfo): ts.LanguageService;
37
+ }
38
+ /** tsserver calls this with the TS module instance the editor is running. */
39
+ declare function init(modules: {
40
+ typescript: typeof import('typescript');
41
+ }): PluginModule;
42
+ export = init;
43
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAatC,UAAU,gBAAgB;IACxB,eAAe,EAAE,EAAE,CAAC,eAAe,CAAC;IACpC,mBAAmB,EAAE,EAAE,CAAC,mBAAmB,CAAC;IAC5C,OAAO,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE;YAAE,MAAM,CAAC,EAAE;gBAAE,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;aAAE,CAAA;SAAE,CAAA;KAAE,CAAC;CAC7E;AACD,UAAU,YAAY;IACpB,MAAM,CAAC,IAAI,EAAE,gBAAgB,GAAG,EAAE,CAAC,eAAe,CAAC;CACpD;AAED,6EAA6E;AAG7E,iBAAS,IAAI,CAAC,OAAO,EAAE;IAAE,UAAU,EAAE,cAAc,YAAY,CAAC,CAAA;CAAE,GAAG,YAAY,CAwOhF;AAED,SAAS,IAAI,CAAC"}