theme-language-server: creating or deleting a folder leaves stale readDirectory/stat cache

Open
#1,386 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@efegokdemir is already working on this.

Since Nov 10, 2026.

  • #1390 by @efegokdemir — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript
Domain
devtools

Research direction

Start in startServer and trace how watched-file create, delete, and rename events invalidate readDirectory, stat, and readFile caches. Check how paths are represented and where the workspace root is determined before changing invalidation. Done when creating or deleting nested folders, and renaming files across folders, refresh directory listings and stats without restarting the server.

Written by the indexing model from the issue text.

Description

Hi! When a watched-file event creates or deletes a file, startServer only invalidates readDirectory for that file's own folder (path.dirname(change.uri)), plus readFile and stat for the file itself.

That's not enough when the event creates or removes a whole folder. Say a theme has no snippets/ folder yet, and then snippets/card.liquid is created. readDirectory of the theme root and stat of snippets/ are still cached from before, so the server keeps thinking snippets/ doesn't exist. Snippet completion stays empty until you restart the server. The same happens the other way round when the last file in a folder is deleted: the cached root listing still has the folder, and walking it fails.

What fixed it for us was invalidating readDirectory and stat for every folder above the created or deleted file, up to the root, not just its direct parent. Renames have the same problem, since they also only invalidate the two parent folders.

We hit this on 2.21.2, and main looks the same. Happy to send a PR.

Dominant language
TypeScript
Stars
245
Forks
108
Avg merge
2d 8h
Merged PRs (30d)
24

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Shopify/theme-tools

All issues in Shopify/theme-tools

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.