vscode-motoko icon indicating copy to clipboard operation
vscode-motoko copied to clipboard

Import can't find files

Open infu opened this issue 2 years ago • 16 comments
trafficstars

Sometimes Motoko language server works and finds its files, sometimes it doesn't. Reloading doesn't help. Everything seems to be set properly, mops & dfx.json. Can't even find a local file. The only difference I can see is my git root is not where dfx.json is. Perhaps that path is being used? How the language server detects its dfx.json ? image

infu avatar Jul 05 '23 14:07 infu

Thanks for the bug report; I'll see if I can reproduce this on my end.

Everything seems alright for a simplified example, so would you be able to send a screenshot of your file / directory structure?

Also, does anything seem unusual in the extension log ("Output" -> "Motoko Language Server")?

The language server is able to handle multiple dfx.json files at a time in any subdirectory, so this is supposed to work even with a different Git root.

rvanasa avatar Jul 05 '23 18:07 rvanasa

Thanks for pointing out where I should be looking. image It seems it doesn't like the simlinks my npm setup has and ends in infinite loop. I can fix that on my end.

Edit: Removing looping npm packages fixed it

infu avatar Jul 06 '23 13:07 infu

Just to confirm, did this fix the original issue ("sometimes Motoko language server works and finds its files, sometimes it doesn't")?

I'll look into fixing this infinite loop condition to minimize the chance of the same situation happening in the future.

rvanasa avatar Jul 06 '23 15:07 rvanasa

It works most of the time. (On Mac/Intel) However, sometimes I get these errors. (not too often) reloading VScode or Motoko language server thru palette doesn't help. I have to close VScode and start it again. Then it works. image

infu avatar Jul 10 '23 11:07 infu

That is quite strange. What operating system are you using?

This might have something to do with VS Code itself rather than the extension, since the error messages indicate that the system path doesn't include npx or mops while the extension is being initialized.

rvanasa avatar Jul 10 '23 16:07 rvanasa

MacOs 13.4

infu avatar Jul 11 '23 12:07 infu

Thanks! I'll let you know if I find a way to reproduce this issue on my end (also on macOS 13.4).

You could try running mops sources and npx ic-mops sources in a terminal to see if anything unexpected happens (and then running code . from the same terminal to inherit the system path). If this doesn't help, then it might be worth reinstalling VS Code and perhaps running the Motoko extension by itself to try and narrow down the root cause.

rvanasa avatar Jul 11 '23 16:07 rvanasa

Hi @infu, are you still running into this issue? Here are a few more debugging steps that might help narrow down what's happening:

  • What happens if you remove or change defaults.build.packtool in your dfx.json file?
  • Do you get a "command not found" message when running which npx and which mops in the VS Code dev console?

rvanasa avatar Aug 22 '23 02:08 rvanasa

same issue here

ottodevs avatar Sep 14 '23 20:09 ottodevs

Haven't seen the 'looping' errors, but I stumble on other errors all the time on all my PCs, different OSes. Different errors. Sometimes they fix after window reload or language server restart.

Like this - Worked until I restarted VScode (no errors in log, files are there, paths are correct): image Most of my repos are pretty simple image In this case trying to import local libraries. Somehow after adding the library directories to the vscode workspace, it started working again. Perhaps VScode doesn't allow the extension to touch files unless in workspace? Just checked that out and it seems to be true. Removing library folder brings the error back.

infu avatar Sep 01 '24 10:09 infu

Thanks for the details and screenshots!

Perhaps VScode doesn't allow the extension to touch files unless in workspace?

This is correct. We have a workaround in the backlog. For the time being, it's necessary for all the Motoko files to be contained in the VS Code workspace.

rvanasa avatar Sep 04 '24 17:09 rvanasa