vscode_deno icon indicating copy to clipboard operation
vscode_deno copied to clipboard

deno.json not recognized if not at root of workspace

Open mfulton26 opened this issue 9 months ago • 1 comments

Describe the bug

If I define my deno.json file at the root my workspace then I get proper Deno language support but if I put it in a folder then I do not.

To Reproduce

  1. Run "Deno: Initialize Workspace Configuration"
  2. Create a folder named "foo"
  3. Create a deno.json file in "foo" with some "imports" defined (e.g. for std lib)
  4. Create a main.ts file in "foo" and import something leveraging the "imports" defined in the deno.json file

Note how you'll get an error message from VSCode:

Relative import path "$std/flags/mod.ts" not prefixed with / or ./ or ../deno(import-prefix-missing)

However running deno run foo/main.ts works fine (and creates a deno.lock file too)

diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..01cede9
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,5 @@
+{
+    "deno.enable": true,
+    "deno.lint": true,
+    "deno.unstable": false
+}
\ No newline at end of file
diff --git a/foo/deno.json b/foo/deno.json
new file mode 100644
index 0000000..55ca111
--- /dev/null
+++ b/foo/deno.json
@@ -0,0 +1,5 @@
+{
+  "imports": {
+    "$std/": "https://deno.land/[email protected]/"
+  }
+}
diff --git a/foo/main.ts b/foo/main.ts
new file mode 100644
index 0000000..57ebaf7
--- /dev/null
+++ b/foo/main.ts
@@ -0,0 +1,3 @@
+import { parse } from "$std/flags/mod.ts";
+
+console.log(parse(Deno.args));

Expected behavior

The VSCode Deno extension should provide code completion inside the subfolder just as it would if deno.json were at the root of the workspace instead.

Screenshots

image

Versions

vscode: 1.82.2 deno: 1.37.0 extension: 3.23.1

mfulton26 avatar Sep 25 '23 12:09 mfulton26

This will be coupled with #787. If you have only one subdirectory with a deno.json, you can work around this in the meantime by specifying "deno.config": "foo/deno.json" in your workspace settings.

nayeemrmn avatar Sep 25 '23 16:09 nayeemrmn