Skip to content

Content mappers: let openProject watch a directory or glob, so a file added later reloads the mapperΒ #65348

Open

Description

πŸ” Search Terms

content mapper, contentMappers, openProject, watchedFiles, watch glob, watch directory, file added later, stale mapped output

βœ… Viability Checklist

⭐ 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

  1. A mapper that derives output from a config file and the files that config selects (schema definitions, route files, and so on).
  2. Today the mapper has no way to learn about a file that did not exist at openProject time, because the protocol accepts only exact file paths.
  3. The only workaround is restarting the TypeScript server (editor) or the tsc --watch process after adding a file.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions