Repository navigation
Description
π Search Terms
content mapper, contentMappers, openProject, watchedFiles, watch glob, watch directory, file added later, stale mapped output
β Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
β Suggestion
Let a content mapper ask for a reload when the set of files matching a directory or glob changes, for example a watchedGlobs / watchedDirectories field in the openProject result.
Today openProject can only list watchedFiles, and the mapper is reopened only when one of those paths changes. A mapper whose output depends on every file matching a pattern in its own config (for example files: ["./tailordb/*.ts"]) cannot list a file that does not exist yet, because the name is unknown. After a matching file is added, the mapped output stays stale until the project is reopened.
π Motivating Example
Version: typescript@7.1.0-beta (native), macOS arm64. Reproduced with tsc --watch --runExternalCode and in VS Code.
Setup: a mapper whose output depends on the files matching ./tailordb/*.ts. src/use.ts references a table defined only in a new file tailordb/invoice.ts, which is created after the first check.
openProject result (tsc --watch, 15 s after the file is created) |
Mapper reloaded after invoice.ts is created? |
|---|---|
watchedFiles = the files imported by the config (no extra entry) |
no |
plus the directory path (.../tailordb, also with a trailing slash) |
no |
plus a glob (.../tailordb/*.ts) |
no |
plus watchedDirectories, watchedDirs, or watchedDirectory (extra result fields) |
no |
plus the exact path of the file that is about to be created (.../tailordb/invoice.ts) |
yes |
tsconfig include also covers ./tailordb |
TypeScript re-checks, but the mapper is not reloaded |
In VS Code (TypeScript Native Preview 1.0.1 with typescript@7.1.0-beta selected through js/ts.tsdk.path, js/ts.contentMappers.enabled at its default), driven by a probe extension that keeps src/use.ts as the active editor and reads its diagnostics 40 s after each step:
| Step | src/use.ts still reports the missing table? |
|---|---|
tailordb/invoice.ts is created through the editor's file API |
yes |
the new file is opened in the editor, then use.ts is shown again |
yes |
TypeScript Native Preview: Restart |
no |
A file that appears while the editor is running (a git checkout, a generator) leaves the mapped output stale until the server is restarted. tsc --watch did not reload it either.
π» Use Cases
- A mapper that derives output from a config file and the files that config selects (schema definitions, route files, and so on).
- Today the mapper has no way to learn about a file that did not exist at
openProjecttime, because the protocol accepts only exact file paths. - The only workaround is restarting the TypeScript server (editor) or the
tsc --watchprocess after adding a file.
Activity