How to set up VS Code with Deno workspaces
I'm trying workspaces, introduced since Deno 1.45. It works well with the
deno
CLI, but in VS Code, red underlines show up on import
statements. (I guess this issue is relevant?) Is it a bug of Deno's LSP or my mistake? Is there any best practice to set up VS Code with Deno workspaces?GitHub
Failed to import package that contained deno workspace · Issue #113...
Describe the bug Deno workspace feature (not VSCode workspaces) supported from v1.45. I tried minimal sample code that written in Deno document, however importing package that contained workspace r...
8 Replies
To set up VS Code with Deno workspaces and address the issue with red underlines on
import
statements, you should follow these steps:
1. Install the Deno VS Code Extension: If you haven't already, install the official vscode_deno
extension from the VS Code marketplace. This extension integrates directly with the Deno CLI using the language server protocol, ensuring that the information you get about your code aligns with how it will work when you run it under the Deno CLI.
2. Enable Deno in the Workspace: Not every project in VS Code is a Deno project by default. To enable Deno for your workspace, use the Deno: Initialize Workspace Configuration
command from the VS Code command palette. This will activate a helper that will ask if you want to enable linting and the Deno unstable APIs for the project. This command will instruct VS Code to store these settings in the workspace configuration (your workspace root .vscode/settings.json
). Once the helper is finished, you should receive a notification that Deno is set up for the project.
3. Check Your Configuration: Ensure that the deno.enable
setting is set to true
in your workspace settings. This will enable the Deno language server and mute the built-in TypeScript/JavaScript extension, which could be causing the red underlines.
4. Partially Enabling Deno: If you have a mixed project with both Deno and non-Deno parts, you can partially enable Deno using the deno.enablePaths
setting. Specify the paths you want to be Deno-enabled, and the extension will use the Deno language server for those paths while using the built-in VS Code language server for others.
5. Check for deno.json
or deno.jsonc
: The Deno extension will auto-identify and apply a deno.jsonc
or deno.json
configuration file if it's found in the workspace root. If you have a specific configuration file you want to use, you can set the
deno.config
setting to point to it.
6. Addressing the Issue: If you're still seeing red underlines after following the above steps, it could be related to the issue you linked (#1131). This might indicate a bug or a limitation in the current version of the Deno extension or LSP. Check the issue tracker for updates or workarounds provided by the Deno team or community.
7. Development Containers: If you prefer an isolated development environment, consider using a development container with VS Code. This requires Docker Desktop, VS Code or VS Code Insiders, and the Remote Development extension pack. The .devcontainer
folder in your workspace should contain the configuration for the container, which will have the Deno CLI and the `vscode⬆️ This does not help at all…
does your monorepo run successfully? its likely that the LSP currently does not support detecting workspaces
Yeah, it works well with the
deno
CLI!we are working on getting LSP to detect workspaces. there are a few issues floating out there but just wanted to let you know
we are working on getting LSP to detect workspaces.@Andy (he/him) is there a ticket where I could subscribe for notifications
there might be some duplicates right now as the team is triaging, but here is one you can subscribe to: https://github.com/denoland/deno/issues/24598
GitHub
LSP workspace does not recognize package
imports
field in config ...Step to reproduce Version % deno -v deno 1.45.2 Files % tree . ├── deno.json ├── deno.lock └── web ├── deno.json └── main.ts deno.json { "imports": { "dax": "jsr:@david/dax...