Stream: beginners

Topic: load: UNRECOGNIZED PACKAGE opening Excerism file in Zed


view this post on Zulip Niklas Konstenius (Oct 07 2024 at 18:48):

I'm getting an error (from Roc language server I guess) in Zed when opening the file RestApi.roc on https://exercism.org/tracks/roc/exercises/rest-api

The error shows as a red squiggly line under the first character m in the module keyword at the top of the file:

load: UNRECOGNIZED PACKAGE

This module is trying to import from `json`:

3│  import json.Json
           ^^^^^^^^^

A lowercase name indicates a package shorthand, but I don't
know which packages are available.

When checking a module directly, I look for a `main.roc` app
or package to resolve shorthands from.

You can create it, or specify an existing one with the
`--main` flag.

Any ideas how to work around this?

view this post on Zulip Isaac Van Doren (Oct 07 2024 at 19:21):

Do the tests work properly if you run them? I’m not sure if there is a way to get around this error from the LSP right now, but it suspect that everything else should still work normally.

view this post on Zulip Isaac Van Doren (Oct 07 2024 at 19:21):

@Aurélien Geron Maybe we should rename all of the test files to main.roc so this issue doesn’t arise when solving exercises locally. Wdyt?

view this post on Zulip Niklas Konstenius (Oct 07 2024 at 20:16):

Isaac Van Doren said:

Do the tests work properly if you run them? I’m not sure if there is a way to get around this error from the LSP right now, but it suspect that everything else should still work normally.

Yes the tests works fine when running with exercism test. The problem is that the error in Zed prevents me from getting useful info from the LSP like inferred types and compiler errors.

view this post on Zulip Isaac Van Doren (Oct 08 2024 at 01:24):

As a workaround you could rename the test file to main.roc and it should work. You may need to restart the lsp and you’ll need to run the tests using roc test instead.

view this post on Zulip Aurélien Geron (Oct 08 2024 at 02:09):

Mmh, the problem with renaming the test files is that all existing users will get a warning telling them that all the exercises they have done are outdated and they need to update them. They might even get one notification per exercise. So if we do this we need to synchronize with the Exercism team to ensure that this doesn't happen. It might be simpler to fix the LSP issue, IMHO.

view this post on Zulip Isaac Van Doren (Oct 08 2024 at 03:18):

Yeah that would not be good. I’m not sure about the best way to fix the LSP issue since it can’t be passed the —main flag.

@Agus Zubiaga do you have any ideas/background with this? I think I remember you working on the —main flag.

view this post on Zulip Agus Zubiaga (Oct 08 2024 at 08:16):

Yeah, unfortunately, we don’t have a way to specify a different main file when using the language server. We used to hang in this case, so that was an improvement, but we probably still need a way to do that.

view this post on Zulip Agus Zubiaga (Oct 08 2024 at 08:18):

I don’t have the bandwidth to do it now, but it should be pretty straightforward to add an Ls setting for this. I don’t know if that’d be the best design, though.

view this post on Zulip Agus Zubiaga (Oct 08 2024 at 08:19):

In the meantime, you could have a dummy main.roc file with all the dependencies needed.

view this post on Zulip Isaac Van Doren (Oct 08 2024 at 12:04):

Yeah it seems like adding a setting would work but would be a little bit annoying to use

view this post on Zulip Niklas Konstenius (Oct 09 2024 at 08:40):

Thanks for the feedback. Tried the workaround by copying the test-file as main.roc but unfortunately was hit by the language server panicking instead:

Roc language server initialized.
stderr: thread 'tokio-runtime-worker' panicked at crates/language_server/src/analysis.rs:301:71:
stderr: called `Option::unwrap()` on a `None` value
stderr: note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This was on my Linux machine, I'll try the workaround on my MacBook tonight and see if it works there.

view this post on Zulip Anton (Oct 09 2024 at 10:55):

I just tried the rest-api files and everything is working for me on Ubuntu 22.04. Can you share your RestApi.roc file?

view this post on Zulip Niklas Konstenius (Oct 09 2024 at 14:29):

Sure, just did a fresh download of the files with:

exercism download --track roc --exercise=rest-api --force
cp rest-api-test.roc main.roc

The contents of RestApi.roc is:

module [get, post]

import json.Json

User : {
    name : Str,
    owes : Dict Str F64,
    owedBy : Dict Str F64,
    balance : F64,
}

Database : { users : List User }

get : Database, { url : Str, payload ? Str } -> Result Str _
get = \database, { url, payload ? "" } ->
    crash "Please implement the 'get' function"

post : Database, { url : Str, payload ? Str } -> Result Str _
post = \database, { url, payload ? "" } ->
    crash "Please implement the 'post' function"

The roc compiler and lsp on my path is from roc_nightly-linux_x86_64-2024-10-07-6cb2501

md5sum `which roc`
7d299380f5270497917f388af74292d3  /home/xxxx/bin/roc

md5sum `which roc_language_server`
32a158fc8ee775c874f535a41ed3e21e  /home/xxxx/bin/roc_language_server

I'm using Ubuntu 22.0.4:

cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.5 LTS"

When I open RestApi.rocin Zed (0.155.2) I get the following in LSP Logs:

Roc language server initialized.
stderr: thread 'tokio-runtime-worker' panicked at crates/language_server/src/analysis.rs:301:71:
stderr: called `Option::unwrap()` on a `None` value
stderr: note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
stderr: thread 'tokio-runtime-worker' panicked at crates/language_server/src/analysis.rs:301:71:
stderr: called `Option::unwrap()` on a `None` value

view this post on Zulip Niklas Konstenius (Oct 09 2024 at 14:46):

If I then remove main.roc (the copy of rest-api-test.roc) and restart Zed and open RestApi.roc no errors are shown in the LSP Logs:

Roc language server initialized.

But the original error is shown on module keyword again:

load: UNRECOGNIZED PACKAGE

This module is trying to import from `json`:

3│  import json.Json
           ^^^^^^^^^

A lowercase name indicates a package shorthand, but I don't
know which packages are available.

When checking a module directly, I look for a `main.roc` app
or package to resolve shorthands from.

You can create it, or specify an existing one with the
`--main` flag.

view this post on Zulip Anton (Oct 09 2024 at 15:49):

Thanks for all the data @Niklas Konstenius, I was able to reproduce it now and will create an issue on the roc repo.
roc check and roc dev do look to be working fine, so you should be able to continue the exercise, unfortunately without help from the language server.

view this post on Zulip Anton (Oct 09 2024 at 16:38):

https://github.com/roc-lang/roc/issues/7153

view this post on Zulip Niklas Konstenius (Oct 09 2024 at 16:48):

Thanks for the help @Anton. I'll be watching the progress in the GH-issue.


Last updated: Jul 06 2025 at 12:14 UTC