dfinity / vscode-motoko

Motoko language support for VS Code.
Apache License 2.0
43 stars 17 forks source link

Import can't find files #223

Open infu opened 1 year ago

infu commented 1 year ago

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
rvanasa commented 1 year ago

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.

infu commented 1 year ago

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

rvanasa commented 1 year ago

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.

infu commented 1 year ago

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
rvanasa commented 1 year ago

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.

infu commented 1 year ago

MacOs 13.4

rvanasa commented 1 year ago

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 commented 1 year ago

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

ottodevs commented 1 year ago

same issue here

infu commented 2 months ago

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.

rvanasa commented 2 months ago

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.

infu commented 1 month ago

I was still getting errors. Mops not found. Then npx not found. Tried removing nvm and installing node with apt, but it didn't fix it. I am having that problem on MacOS and also on Ubuntu. And it only bugs sometimes. So I'll just go with this: image

mops sources > mops.sources
infu commented 1 month ago

Actually, removing defaults.build.packtool worked. I guess you are doing it internally in a different way

rvanasa commented 1 month ago

Glad you found a workaround! I've also experienced what you're describing but haven't yet been able to reliably reproduce the issue. This is most likely related to how VS Code passes environment variables to extensions, especially if npx is on your system path.

infu commented 1 month ago

I'll have to go back to packtool: "cat mops.sources" When packtool is removed from dfx.json then dfx build command doesn't work, while the VSCode extension works. @ZenVoich perhaps mops install and add, when called can just write a file (with mops sources contents) in .mops dir