Comments (13)
from typescript.
Here is a quick and dirty patch:
diff --git a/extensions/typescript-language-features/src/tsServer/fileWatchingManager.ts b/extensions/typescript-language-features/src/tsServer/fileWatchingManager.ts
index 27b9ec3d7f6c..d9a4e02ee7db 100644
--- a/extensions/typescript-language-features/src/tsServer/fileWatchingManager.ts
+++ b/extensions/typescript-language-features/src/tsServer/fileWatchingManager.ts
@@ -60,6 +60,12 @@ export class FileWatcherManager implements IDisposable {
if (watchParentDirs && uri.scheme !== Schemes.untitled) {
// We need to watch the parent directories too for when these are deleted / created
for (let dirUri = Utils.dirname(uri); dirUri.path.length > 1; dirUri = Utils.dirname(dirUri)) {
+ // on macOS, avoid turning `~/Library/Caches/typescript/5.5/...` into a watcher on `~/Library`
+ // this prevents security alerts, due to a parcel-bundler/watcher bug trying to open(~/Library/Containers)
+ // https://github.com/microsoft/vscode/issues/208105#issuecomment-2323462416
+ if (dirUri.path.endsWith('/Library/Caches')) {
+ break;
+ }
const dirWatcher: DirWatcherEntry = { uri: dirUri, listeners: [] };
let parentDirWatcher = this._dirWatchers.get(dirUri);
from typescript.
it's not clear to me why the extension is trying to traverse upward and install additional watcher up through the root?
perhaps the proper fix is:
--- a/extensions/typescript-language-features/src/tsServer/serverProcess.browser.ts
+++ b/extensions/typescript-language-features/src/tsServer/serverProcess.browser.ts
@@ -115,7 +115,7 @@ class WorkerServerProcess implements TsServerProcess {
}
case 'watchDirectory':
case 'watchFile': {
- this._watches.create(event.data.id, vscode.Uri.from(event.data.uri), /*watchParentDirs*/ true, !!event.data.recursive, {
+ this._watches.create(event.data.id, vscode.Uri.from(event.data.uri), /*watchParentDirs*/ false, !!event.data.recursive, {
change: uri => this._watcher.postMessage({ type: 'watch', event: 'change', uri }),
create: uri => this._watcher.postMessage({ type: 'watch', event: 'create', uri }),
from typescript.
I think I understand.. the intention of the watchParentDirs
flag is to install a non-recursive set of watchers up the directory tree, however on macOS each of these is recursive by default and thus ends up sending events for unnecessary files.
Unfortunately it doesn't appear that vscode.workspace.createFileSystemWatcher
provides control over the recursive option?
For the initially requested directory, FileWatcherManager.create appends **
to request recursion..
const watcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(uri, isRecursive ? '**' : '*'), !listeners.create, !listeners.change, !listeners.delete);
from typescript.
Never mind, the issue is not related to watchParentDirs
.
I found in tsserver.log that it is explicitly requesting a resursive watcher on ~/Library, because it infers the default cache location of ~/Library/Caches/typescript/5.5/node_modules is rooted there.
EDIT: It appears I may be using another typescript extension that's causing this issue
from typescript.
I believe this is where a directory watcher on ~/Library is installed:
TypeScript/src/server/project.ts
Lines 1601 to 1604 in a709f98
from typescript.
@tmm1 we need a tsserver log for this issue so we can determine what is the best way to fix this.
Thanks
from typescript.
Okay. This is hard to reproduce as it happens very intermittently (not sure when tsserver decides to use ~/Library/Caches/typescript
but it's not all the time).
I will remember to capture and share the logs next time.
from typescript.
Here is what I see when things go haywire:
Info 12165[16:26:43.910] Starting updateGraphWorker: Project: /dev/null/inferredProject1*
Info 12167[16:26:43.924] DirectoryWatcher:: Added:: WatchInfo: /Users/tmm1/Library 1 undefined Project: /dev/null/inferredProject1*
WatchType: Failed Lookup Locations
Info 12168[16:26:43.924] event:
{"seq":0,"type":"event","event":"createDirectoryWatcher","body":{"id":5825,"path":"/Users/tmm1/Library","recursive":true,"ignoreUpdate":true}}
Info 12169[16:26:43.924] Elapsed:: 0.08395910263061523ms DirectoryWatcher:: Added:: WatchInfo: /Users/tmm1/Library 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations
Info 12170[16:26:43.924] FileWatcher:: Added:: WatchInfo: /Users/tmm1/Library/Caches/typescript/5.5/node_modules/undici-types/package.json 2000 undefined Project: /dev/null/inferredProject1* WatchType: File location affecting resolution
Info 12171[16:26:43.924] event:
{"seq":0,"type":"event","event":"createFileWatcher","body":{"id":5826,"path":"/Users/tmm1/Library/Caches/typescript/5.5/node_modules/undici-types/package.json"}}
Info 12172[16:26:43.937] FileWatcher:: Added:: WatchInfo: /Users/tmm1/Library/Caches/typescript/5.5/node_modules/@types/node/package.json 2000 undefined Project: /dev/null/inferredProject1* WatchType: File location affecting resolution
Info 12173[16:26:43.937] event:
{"seq":0,"type":"event","event":"createFileWatcher","body":{"id":5827,"path":"/Users/tmm1/Library/Caches/typescript/5.5/node_modules/@types/node/package.json"}}
Info 12174[16:26:44.078] Finishing updateGraphWorker: Project: /dev/null/inferredProject1* projectStateVersion: 3 projectProgramVersion: 2 structureChanged: true structureIsReused:: SafeModules Elapsed: 168.39091682434082ms
Info 12175[16:26:44.078] Project '/dev/null/inferredProject1*' (Inferred)
Info 12176[16:26:44.080] Files (143)
from typescript.
I need the complete log pls. You can replace all sensitive information in the log but file list is important to see whats going on
from typescript.
From the log it seems like you have plugin enabled. Can you please disable the plugins and then generate new tsserver log file and see if this still repros. I am still trying to find why "Library" is watched instead of "node_modules" in it and have no repro yet
Edit1: I think for some reason your current directory sent to tsserver is "/" which is what probably causing this . will need to really see if i can repro it that way. But may be your plugin is causing that to happen?
Edit2: Yes the repro needs the current directory to be "/" and then i am able to see the issue.
from typescript.
I am not able to repro easily without the plugin.
I believe what's happening is that the plugin uses in-memory documents with no real file path. These are causing confusion in resolving project root and resulting in file watchers on strangely rooted directories.
cc #59508
from typescript.
Yeah but its not issue when its using correct location of vscode which is normally a path thats not "/" and we will watch "node_modules" instead of determining what to watch based off of "root directory". Plugin is what is causing current directory for tsserver to be "/" and not something like "/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
You can create a document that's not on disk by:
Open code (without "." or some folder path)
Close any existing folder/workspaces
create new file, set type to javascript and you should be able to get exact same behavior on opening a file
from typescript.
Related Issues (20)
- FETCH / Give The json() Function The Power To Use Generic Type HOT 1
- TS 5.6 requires composite projects with noEmit to have fully accessible types, unlike 5.5 HOT 6
- useVsCodeWatcher interferes with updating typescript @aliased imports paths on file or folder moves HOT 2
- Switch typeguard for single case HOT 2
- `AutoFill` is missing a few valid tokens for the `autocomplete` attribute HOT 2
- Cannot read properties of undefined (reading 'charCount') HOT 1
- `tsBuildInfoFile` compiler option should be allowed without `incremental` or `composite` in Typescript versions `>5.6`
- super() typed as returning void HOT 2
- Move to File does not generate imports in the same way that autoimports does
- Move To File makes extra spaces when moving jsdoc comments
- (JSDoc, JavaScript) Imported class types by require() are unresolved HOT 1
- Type all exported members according to some interface HOT 2
- JSDoc typed function comments inside functions
- Error when accessing CSS property value using kebab case in `CSSStyleDeclaration` object HOT 1
- Type 'never' incorrectly inferred for mixed primitive type properties assignment with strictNullChecks disabled HOT 2
- Array of object unions not working as expected HOT 2
- Support WebIDL interfaces nominally (not just structurally) HOT 9
- Improve type inference for nullish coalescing (??) after null checks on multiple variables HOT 2
- [NewErrors] 5.7.0-dev.20240915 vs 5.6.2 HOT 6
- [ServerErrors][JavaScript] 5.7.0-dev.20240915 vs 5.6.2 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typescript.