microsoft / vscode-java-dependency

Manage Java projects in Visual Studio Code.
https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-dependency
MIT License
152 stars 74 forks source link

Java project tree/view not updated with new files/packages when created from create class option of extension (Only for network location mounts [NFS/SMB] ) #787

Closed jlmanohar closed 9 months ago

jlmanohar commented 1 year ago

VSCode version 1.8.21 Project Manager for java v0.23.1

Issue: When creating a new package or class, the java project view doesnt show new classes/packages until it is refreshed manually.

Steps to reproduce:

  1. Create a new project with spring initializer, add to workspace the newly created project
  2. wait for java project manager to show in in view
  3. click on the main package , then on "+" icon, select java class, the give a name.
  4. As soon as it open the new class in editor, save it.
  5. The new class wont show up, but any errors in new class gets highlighted
  6. image

  7. Manually select refresh option by clicking "..." button near java projects, this will refresh and now show the new file
  8. image image

Expected: When new class/package is created, java project manager should auto refresh the view to show new package and classes as well.

Settings: Autorefresh is enabled with a delay of 2000ms image

jlmanohar commented 1 year ago

Update: This happens on a network drive , i tried to do the same thing on C drive and it works fine. Does autorefresh use filesystem's ionotify ?

jdneo commented 1 year ago

Does autorefresh use filesystem's ionotify ?

It may be something related with uri I guess. I guess some part of the code only works when the scheme is file.

jlmanohar commented 1 year ago

I will try to check if this happens on another machine with different network drive, but it might be something related to how network drive gets treated for auto reloads (probably by the host OS). This issue doesn't happen for projects on physical drive.

@jdneo , Do you have any suggestions or guide me in any direction that could help find me the issue, or get logs that can help others ?

jdneo commented 1 year ago

What net driver are you using? I can have a try if I have an account.

jlmanohar commented 1 year ago

I first observed this issue on my corporate issued VDI where i have to use an SMB shre for all my projects, which makes it hard to try out different things or get some info that only admin has access to. I switched to linux on a personal system and observed the same issue (Both on NFS and SMB shares)

Here is what i did.

  1. Install official VSCode debian package (code_1.82.2-1694671812_amd64.deb t the time of writing)
  2. Install Java and SpringBoot extension pack
  3. Have JDK installed and JAVA_HOME setup correctly
  4. mount the network drives with the following commands SMB Share sudo mount -t cifs //(IP of nas)/test ~/testsmb -o uid=(user id),gid=(users group id) NFS Share sudo mount (ip of nas):/mnt/pool0/test ~/testnfs then made it writable for everyone (just to rule out issues) sudo chmod 777 ~/testnfs
  5. Generate a test project from spring initializer and place it in the mounted location.
  6. Add the projects to workspace and trust the author.
  7. minimize the workspace explorer and use the java projetcs view
  8. open the base class package of newly created project, click on + button on the package and create new java class.

Expected: New class should be visible in the package where it got created Actual:

Kernel and other info:

Will try to get further info from a physical windows device if required.

jlmanohar commented 11 months ago

Any update on this ?

I want to add this note and will update the actual title as well, but this issue is only for network locations (Both NFS and SMB).

Note: files do reflect in the explorer view and project view when creating new files or editing externally. But when creating with the Extension's create class option, it shows only in explorer but not in java project.

I just found this in VSCode Output tab when i select "Window", this shows file watcher error not sure if that is something related

2023-10-24 19:23:05.111 [error] MainThreadFileSystem#$watch(): failed to stat a resource for file watching (extension: vscjava.vscode-java-test, path: file:///home/jlmanohar/Documents/SmdShareRecieve/demo/src/test/resources, recursive: true, session: 0.32353731377421235): EntryNotFound (FileSystemError): Error: ENOENT: no such file or directory, stat '/home/jlmanohar/Documents/SmdShareRecieve/demo/src/test/resources'
2023-10-24 19:23:05.112 [error] MainThreadFileSystem#$watch(): failed to stat a resource for file watching (extension: vscjava.vscode-java-test, path: file:///home/jlmanohar/Documents/SmdShareRecieve/demo/target/generated-test-sources/test-annotations, recursive: true, session: 0.919249591511081): EntryNotFound (FileSystemError): Error: ENOENT: no such file or directory, stat '/home/jlmanohar/Documents/SmdShareRecieve/demo/target/generated-test-sources/test-annotations'
jdneo commented 11 months ago

Sorry I haven't found a time to look deeper into this issue.

I just found this in VSCode Output tab when i select "Window", this shows file watcher error not sure if that is something related

This should be some errors caused by other extensions I guess. Should not related with this issue.

jlmanohar commented 9 months ago

I did a bit of research and it looks like this is an upstream issue from FileWatcher from vscode. Will report this in vscode repo as well

In summary, when a new file is created, it creates a "create event" on my regular filesystem, but generates a "change event" on network mounts.

filesystemwatcher issue.webm

jdneo commented 9 months ago

Thank you for the investigation! Nice job!

jlmanohar commented 9 months ago

Thanks @jdneo , have reported the bug in vscode, will look at it more when i have some more time available. Here is the report in case someone needs to refer it. https://github.com/microsoft/vscode/issues/201103

jlmanohar commented 9 months ago

I am going to close as not planned, i did a few tests ( I am not good with ts or js so my code is not good) but this is what i found.

Any one facing similar issue can try and enable this setting and see if it helps. This worked for me sometimes usually on linux, but doesnt help me in windows image

  1. Creating a file on smb share with vscode (without any extension) gives an update event from parcel watcher
  2. Creating a file with terminal touch <filename> gives an update event from parcel watcher
  3. Creating a file with my file browser (KDE's Dolphin in my case) creates a created event from parcel, and update + delete event for .part file

This issue doesn't seem to be related to anything vscode does, and maybe how files actually get created or how nfs/smb handles it, this part I don't know. I am not able to trace out where exactly is the issue ,is it with CIFS/SMB client implementations, actual SMB/NFS server or some other place.

For anyone in the future who wants to debug this issue, this is the snippet that i have, It creates a file watcher on the mentioned path, creates a file with node fs at 1 sec, creates a file with touch on the second second, then waits for 28 sec and then unsubscribes and terminates

const watcher = require('@parcel/watcher');
const path = require('path');
const fs = require('fs');
var exec = require('child_process').exec;

var p = "/<directory path>";
var subscription;

setTimeout(async() => {
  console.log("Watching events on "+p);
  subscription = await watcher.subscribe(p, (err, events) => {
    console.log(events);
  })
}, 1);
setTimeout(()=>{
  fs.writeFileSync(p+"/t.txt","");
}
,1000)
setTimeout(()=> {
exec("touch "+p+"/t1.txt")
},2000);
setTimeout(async() =>{
  await subscription.unsubscribe();
},30000)

these are the dependencies and you can do npm install and then node <filename.js> to run it.

"dependencies": {
    "@parcel/watcher": "2.1.0",
    "path": "^0.12.7"
  }