microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.99k stars 12.48k forks source link

TypeScript does not detect a symlinked directory getting re-created #55313

Open jfirebaugh opened 1 year ago

jfirebaugh commented 1 year ago

Does this issue occur when all extensions are disabled?: Yes

Steps to Reproduce:

  1. Run the following:
    mkdir -p scratch/src
    mkdir scratch2
    dst=$(cd scratch2 && pwd)
    ln -s $dst scratch/src/symlink
    echo "import { Foo } from './symlink/index'" >scratch/src/test.ts
    echo "export const Foo = 1;" >scratch2/index.ts
    code --disable-extensions scratch

    Open test.ts. It should have no errors.

  2. Run rm -rf scratch2. After vscode detects the change, it should display a red squiggle under ./symlink/index with the error "Cannot find module ...".
  3. Run mkdir scratch2 && echo "export const Foo = 1;" >scratch2/index.ts

The expected behavior at this point is that vscode recognizes that the target directory of the symlink once again exists, and removes the red squiggle.

The actual behavior is that the squiggle does not go away. You must close and reopen the project to get vscode to recognize that the code is valid.

jfirebaugh commented 1 year ago

This applies for for symlinked files as well: you can replace step 2 with rm scratch2/index.ts, and observe the same actual behavior after recreating that file in step 3.

After step 3, command clicking on the text with the squiggle opens a tab that displays the following:

Screenshot 2023-08-01 at 1 08 01 PM

However, you can open src/symlink/index.ts successfully from the Explorer.

bpasero commented 1 year ago

Our file watcher does not support changes to targets that are in the workspace behind symbolic links. In other words, the file watcher will not automatically follow symlinks for performance reasons. You can tell this by looking at the file explorer that does not remove the symbolic link from the tree even though it is deleted.

We have limited support to add additional folders to be watched via the files.watcherInclude setting, but in this scenario when I test, I am not seeing file events for when the folder is being recreated.

However here I believe TypeScript is doing something on their own, because they do detect the delete but not the recreation, so maybe this is something TypeScript deals specifically.

jfirebaugh commented 1 year ago

Yes, I concur that it's a TypeScript issue -- I was able to reproduce the same issue in another editor (IntelliJ IDEA). Do you have the ability to transfer the issue to the microsoft/typescript repository?

RyanCavanaugh commented 1 year ago

We have roughly similar trade-offs around watch. You can toggle between different watch strategies and find the one that works best for your scenarios.

jfirebaugh commented 1 year ago

As far as I can tell, none of those options would allow this scenario to function as expected.