Deno IntelliSense on Visual Studio Code

Nov 21, 2022 Deno IntelliSense on Visual Studio Code

Deno modules and extension is different compared to Nodejs. For example, In Node.js we just import modules like import axios from 'axios'. But in Deno, it’s like import { assertEquals } from "https://deno.land/std@0.160.0/testing/asserts.ts". The good thing is you don’t have to run npm install to install the package. You can just cache the package with the Deno extension by opening VS Code quick fix.

Installation

Make sure you have Deno installed on your PC. Then install the official Deno extension.

Create a folder and run deno init on your terminal to create a new project.

Open the project in VS Code and try opening main_test.ts file. You will Vs Code is throwing errors because they don’t support Deno by default. You have to enable Deno in your workspace.

Open Vs Code command line and type deno to see available commands like below.

Deno extension from vscode command line

Select Deno: Initialize Workspace Configuration option to enable Deno for your project. It will ask some questions to enable Deno Linting & Deno Unstable API's, click yes. of course, you can change the settings later from .vscode folder later if you want to.

Now, if you open the main_test.ts file. You will see the error is gone except for the module import error Uncached or missing remote URL. Open the quick fix and hit on cache https://deno.land/std@..." and it's dependencies like below.

Deno cache module vscode quick fix Cache deno module from quick fix

Pretty easy, right? No terminal and no more installation for the second time. It will always use this module from the cache.

You might be wondering why generating .vscode/settings.json in the project folder is like this. Well, enabling Deno in your global config will enable Deno for your other Typescript projects as well which you don’t want to do. Maybe in the future, there will be updates that we won’t have to do this for every project.

Conclusion

When I first installed that extension, IntelliSense was not working for me. Then I realized I missed a step from the documentation. I just explained in more detail what the docs said and that’s all.

Well, Good Luck with Deno!