Deno - jump to definition in jsr package

Recently I started playing with Deno and using its lsp implementation. The latest 2.x versions work great.

A small issue I’ve encountered was when trying to jump to definition for packages installed from jsr is the fact that it did not work because the package was not cached locally. So when trying to see the actual implementation of a symbol, I would be following an empty file. Wierdly enough this did not happen for packages installed from npm. 🤔 (I guess because these were already cached locally in the $DENO_DIR).

To solve the issue, I had to first cache the packages by adding to deno.json:

{"vendor": true}

and re-caching:

# clear the cache
deno cache --reload main.ts
# re-cache
deno cache main.ts

This will create two local folders: vendor(for jsr) and node_modules(for npm) containing the dependencies and won’t download those on every build.

Now every time I tried to jump to definition for a symbol, the correct file was followed.

More info on vendor option can be found in the official doc.