Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LSP badly resolves relative imports between cached modules #19908

Open
adamgreg opened this issue Jul 22, 2023 · 4 comments
Open

LSP badly resolves relative imports between cached modules #19908

adamgreg opened this issue Jul 22, 2023 · 4 comments

Comments

@adamgreg
Copy link
Contributor

adamgreg commented Jul 22, 2023

I think the LSP / VS Code has started resolving relative imports between cached modules badly.

I'm running under a devcontainer, with the project root in /workspace/ and $DENO_DIR is /deno/.cache/deno. I can run my unit tests from a terminal ok, but if I try to run them in VS Code I get a "Module Not Found" error popup that shows an attempt to import a module from /workspace/deno/.cache/deno/....

If I open the (cached) module containing the failing import and hover the import statement I see a popup with the "Resolved Dependency" in the wrong place, outside the cache. Screenshots attached.

It seems to be linked to an entry in the import map - "/": "./", copied from the "Using project root for absolute imports" example in the manual . If I comment that out, the problem goes away. I think there must be some bug at play here.

image
image

@adamgreg
Copy link
Contributor Author

I now have "absolute" imports and cache-relative imports both working properly after moving the "absolute" entries in the import map (deno.jsonc) into a project-relative scope:

  "scopes": {
    "./": {
      "/": "./",
      "./": "./"
    }

@cosmoswafer
Copy link

I personally strongly recommend revising the official documentation to include this as an example.

cosmoswafer added a commit to cosmoswafer/deno-docs that referenced this issue Jun 16, 2024
… root imports

Since the Deno LSP provides incorrect recommendations for absolute project root imports when using the official example, I suggest adding another example to resolve this issue.

Reference issues:
- denoland/deno#19908
- denoland/deno#17193
@adamgreg
Copy link
Contributor Author

Hi @cosmoswafer I later switched the import map entry so I could prefix project-relative imports with "@/" instead of "/". Then I didn't need to use scopes any more. I don't know if the original issue I reported is still a problem.

@cosmoswafer
Copy link

cosmoswafer commented Jun 16, 2024

@adamgreg, I see. I’ve conducted another test on Deno 1.44.2, and it appears that the scoped import map is not functioning as expected. While prefixes like “@/”, “@root/”, and “@baba/” seem to work, following the example from the official documentation leads to annoying suggestions. I think most users will read the documentation first, so it would be beneficial to provide an idiomatic example there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants