dfinity / vscode-motoko

Motoko language support for VS Code.
Apache License 2.0
42 stars 16 forks source link

Error: Error while finding MOPS packages. #148

Closed tomijaga closed 1 year ago

tomijaga commented 1 year ago

Hey @rvanasa, I've been using this vscode extension for a while now and would like to say that it's been very helpful for formatting and highlighting errors and warnings. 🙌

It has been working great for me, however the latest update to the extension throws an error for me on initialization:

Error: Error while finding MOPS packages.
Make sure MOPS is installed locally or globally (https://mops.one/docs/install).
Command failed: npx --no ic-mops sources
npm ERR! canceled

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/dire.sol/.npm/_logs/2023-01-12T03_24_14_372Z-debug.log

I tried running this command locally in my terminal and found out that it asks to install the package before running the command.

npx ic-mops sources
Need to install the following packages:
  ic-mops
Ok to proceed? (y)

When I responded with a yes (y) the command ran successfully and returned the file paths for all my dependencies

npx --yes ic-mops sources
--package base .mops/_github/base@moc-0.7.4/src
--package array .mops/_github/array@v0.2.0/src
--package StableTrieMap .mops/_github/StableTrieMap@main/src
--package StableBuffer .mops/_github/StableBuffer@v0.2.0/src
--package itertools .mops/itertools@0.1.1/src
rvanasa commented 1 year ago

Thanks for opening this issue!

What happens if you run npm i -g ic-mops and then restart the Motoko language server? I changed this behavior for security reasons (since it might be concerning if the extension silently installed a third-party npm package without confirmation).

I'm planning to revisit this in the near future by bundling MOPS with the extension (or adding a prompt to install the latest version). Let me know if the short-term solution mentioned above works for you; otherwise I'll do my best to implement this today.

tomijaga commented 1 year ago

Thank you for your response, @rvanasa.

I had already installed the mops CLI globally on my system and attempted to reinstall it and restart the language server multiple times before creating the issue. After some time, I reopened the VSCode app and the issue was resolved.

I agree with the decision to change the behaviour due to security concerns, and think that the solution of detecting the mops CLI or adding a prompt to install the latest version of mops is a good approach, as it ensures the CLI version used is the one expected by the user.