dfinity / vscode-motoko

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

extension don't see mops packages #177

Closed ZenVoich closed 1 year ago

ZenVoich commented 1 year ago

Project builds fine, but in vscode I see erros like this:

image

LS output:

Parsed typed AST
Loading packages for directory: e:\ic\mops
Running `mops sources` in directory: e:\ic\mops
Loading packages for directory: e:\ic\mops\backend
Received: ["--package","base",".mops\\base@0.8.1\\src","--package","time-consts",".mops\\time-consts@1.0.0\\src",""]
Package: base -> /e:/ic/mops/.mops/base@0.8.1/src (file:///e%3A/ic/mops)
Package: time-consts -> /e:/ic/mops/.mops/time-consts@1.0.0/src (file:///e%3A/ic/mops)
Checking workspace
~ /e:/ic/mops/backend/storage/storage-canister.mo (file:///e%3A/ic/mops/backend)
~ /e:/ic/mops/backend/main/validate-config.mo (file:///e%3A/ic/mops/backend)
~ /e:/ic/mops/backend/main/types.mo (file:///e%3A/ic/mops/backend)
~ /e:/ic/mops/backend/main/download-log.mo (file:///e%3A/ic/mops/backend)
~ /e:/ic/mops/backend/storage/storage-manager.mo (file:///e%3A/ic/mops/backend)
~ /e:/ic/mops/test/fail.test.mo (file:///e%3A/ic/mops)
~ /e:/ic/mops/backend/main/main-canister.mo (file:///e%3A/ic/mops/backend)

windows 10 vscode-motoko 0.9.1

rvanasa commented 1 year ago

This looks like a Windows-specific regression. I'll do my best to repro and fix this for you.

rvanasa commented 1 year ago

This should now be fixed in 0.9.2. Let me know otherwise and I'll take another look.

ZenVoich commented 1 year ago

Same error.

Output:

Loading packages for directory: e:\ic\mops
Running `mops sources` in directory: e:\ic\mops
Loading packages for directory: e:\ic\mops\backend
Running `npx --no ic-mops sources` in directory: e:\ic\mops\backend
Received: ["--package","base",".mops\\base@0.8.1\\src","--package","time-consts",".mops\\time-consts@1.0.0\\src","--package","_","backend","--package","test","..\\packages\\test\\src",""]
Package: base -> /e:/ic/mops/.mops/base@0.8.1/src (file:///e%3A/ic/mops)
Package: time-consts -> /e:/ic/mops/.mops/time-consts@1.0.0/src (file:///e%3A/ic/mops)
Package: _ -> /e:/ic/mops/backend (file:///e%3A/ic/mops)
Package: test -> /e:/ic/packages/test/src (file:///e%3A/ic/mops)
Received: [""]
Checking workspace
~ /e:/ic/mops/backend/main/download-log.mo (file:///e%3A/ic/mops/backend)
rvanasa commented 1 year ago

A few debugging questions:

As a short-term fix / debugging step, you could try adding the following dfx.json file to ...\mops\backend:

{
  "defaults": {
    "build": {
      "packtool": "mops sources"
    }
  }
}

The extension will use the specified packtool command instead of the npx ic-mops command (which runs for autodetected mops.toml files). Hopefully this will make it slightly easier to debug the issue.

ZenVoich commented 1 year ago

It looks like the extension is reading from a dfx.json file in ...\mops, and then directly from a mops.toml file in ...\mops\backend. Is this correct and intended?

yes, backend/mops.toml contents:

[package]
baseDir = "."

it just changes default value of baseDir="src" to resolve path to backend not to backend/src. For packages publishing to mops checked that baseDir="src"

Where in the project do these errors occur, e.g. in backend, test, or everywhere?

Everywhere, in each import line importing package (except base)

As a short-term fix / debugging step, you could try adding the following dfx.json file to ...\mops\backend:

there is no dfx.json in backend dir

ZenVoich commented 1 year ago

Just found out that removing backend/mops.toml solves the problem.

it just changes default value of baseDir="src" to resolve path to backend not to backend/src

It was intended to use root dir as "local package" to use it as mo:_/file.mo instead of ../../file.mo

Probably doesn't make much sense, I'll just delete it)

rvanasa commented 1 year ago

Okay, good to know about the baseDir field. I'm glad this worked as a solution!

ottodevs commented 11 months ago

This happens to me in macOS as well, trying to import any package with the extensions results in the "package not defined" error.