Skip to content

Latest commit

 

History

History
74 lines (47 loc) · 4.33 KB

type-injector.md

File metadata and controls

74 lines (47 loc) · 4.33 KB

💉 Type Injector (plugins.fox.tools.type_injector)

← Back to Wiki Index

Turns type definitions on and off per project, for Lua and for TypeScript/JavaScript, from one picker — without editing .luarc.json or tsconfig.json by hand, and without dumping every schema you own into every project.


⌨️ Commands

Command Action
:FoxTypes / :TypeInjector Open the picker
:FoxGitignoreGenerated Add the generated .foxnvim/types.d.ts to .gitignore

Inside the picker: <Enter> / <Tab> toggles a schema, <C-n> installs an @types package from NPM, u updates an already downloaded package to @latest, <C-d> deletes one. Active schemas are ✅, sorted to the top, with their version in the label.

The language is inferred from the current filetype; from any other buffer it asks Lua vs TypeScript/JavaScript first.


📁 Where schemas come from

config/schemas-langs/
├── lua/
│   ├── vim_nvim/       -- Neovim API
│   ├── neovide/        -- Neovide GUI globals (vim.g)
│   ├── love/           -- LÖVE
│   └── koreader/
└── typescript_javascript/
    ├── browser/        -- hand-written DOM/window stub
    ├── node/           -- real @types/node, fetched from the npm registry
    └── bun/            -- real bun-types, self-contained (own node_modules/@types/node copy)

Each directory is a schema. A TS schema is either a flat folder of .d.ts files, or (when a package needs it — see the by-hand guide) holds a node_modules/@types/… tree, which is where the version shown in the picker comes from.

The love Lua schema targets the released LÖVE 11.5 API. It covers all modules, object methods, enums, and callbacks in the wiki-derived LÖVE API catalog, with links from the hover documentation to the official LÖVE wiki. Common functions also include short examples and usage tips. LÖVE 12.0 is still described as in development on the official version history, so its new API is outside this schema.

To refresh the schema after updating that catalog, extract its repository and run lua config/scripts/generate_love_types.lua /path/to/love-api from this repository root. The generator checks the catalog version before replacing config/schemas-langs/lua/love/love_types.lua.

Adding one is just adding a directory — scan_available_schemas() reads the filesystem, there is no registry to update. See Managing TypeScript Type Schemas for how node/ and bun/ were populated without running npm install.


🔌 How each language is wired

Lua (lua_ls). Active schema directories are appended to Lua.workspace.library, and the running client is notified with workspace/didChangeConfiguration — so toggling a schema takes effect immediately, no restart.

TypeScript (tsc). All active schemas are collapsed into a single generated file, .foxnvim/types.d.ts, holding one /// <reference path="…" /> per schema. The project's TS config is patched to include it. One generated file instead of N typeRoots entries keeps tsconfig.json readable and makes "what types are on?" a single file to look at.

Automatic type acquisition is disabled on tsc (see Languages), so what you toggle here is exactly what the server sees. The client name notified after a change is resolved from lua/fox/langs/typescript/init.lua's M.lsp_server, not hardcoded — it stays correct if that server is ever swapped.


💾 State

.foxnvim/types.json records which schemas are active, per language:

{
  "lua": ["vim_nvim"],
  "typescript_javascript": ["browser"]
}

Commit that file — it's the project's decision. The generated .foxnvim/types.d.ts is machine output; :FoxGitignoreGenerated adds it to .gitignore for you (and is a no-op if it's already listed).


📦 Installing @types from NPM

<C-n> in the picker takes a package name, normalises it to @types/<name> when needed, and installs it into the TypeScript schemas directory. It then shows up as a normal togglable schema with its version — so a project that needs @types/node gets it once, and every other project stays clean.