deno-nvim icon indicating copy to clipboard operation
deno-nvim copied to clipboard

A plugin to improve deno experience in neovim

deno-nvim

A plugin to improve deno experience

Installation

using packer.nvim

use 'neovim/nvim-lspconfig'
use 'sigmasd/deno-nvim'

-- Debugging
use 'mfussenegger/nvim-dap'

Setup

This plugin automatically sets up nvim-lspconfig for deno for you, so don't do that manually, as it causes conflicts.

Put this in your init.lua or any lua file that is sourced.

Example config:

require("deno-nvim").setup({
  server = {
    on_attach = ...,
    capabilites = ...
  },
  -- if you're using dap to debug (see the README for more info)
  dap = {
    adapter = ...
  }
})

Local settings

To use local settings for each project, checkout https://github.com/folke/neoconf.nvim which can even parse .vscode/settings.json

The default settings are located here https://github.com/denoland/vscode_deno/blob/main/package.json

Its also recomended to install jsonls with lspconfig to get autocompletion inside the settings

Usage

deno test with code lens

use vim.lsp.codelens to activate this

Example of keybindings:

vim.keymap.set("n", "<space>dr", function()
    vim.lsp.codelens.refresh();
    vim.lsp.codelens.run()
end, opts)
dap support

Support debugging with https://github.com/mfussenegger/nvim-dap

Follow the instruction here https://github.com/mfussenegger/nvim-dap/wiki/Debug-Adapter-installation#javascript-deno to download and extract dapDebugServer.

Then you will need to set dap.adapter.executable.args to {dapDebugServerPath, "${port}"} when using deno.nvim.setup. (don't change "${port}" its not a place holder)

Example:

    require("deno-nvim").setup {
      dap = {
        adapter = {
          executable = {
            args = {
              "/absolute-path/to/js-debug/src/dapDebugServer.js", "${port}"
            }
          }
        }
      }
    }

If you want to use dap outside of tests, you can add theses lines somewhere in your init.lua

-- same thing for configurations.javascript
require("dap").configurations.typescript = {
  {
    type = 'pwa-node',
    request = 'launch',
    name = "Launch file",
    runtimeExecutable = "deno",
    runtimeArgs = {
      "run",
      "--inspect-wait",
      "--allow-all"
    },
    program = "${file}",
    cwd = "${workspaceFolder}",
    attachSimplePort = 9229,
  },
}
auto complete import from deno registeries
deno task
Inlay Hints

Inlay hints are supported in deno from version 1.27.0, to use it install https://github.com/lvimuser/lsp-inlayhints.nvim

You can set it locally by using neoconf with these settings https://github.com/denoland/vscode_deno/blob/main/package.json#L245

You can set it globally by adding this to your init.lua where you instantiate denols server:

require "deno-nvim".setup({
    server = {
        on_attach = ...,
        capabilities = ...,
        settings = {
            deno = {
                inlayHints = {
                    parameterNames = {
                        enabled = "all"
                    },
                    parameterTypes = {
                        enabled = true
                    },
                    variableTypes = {
                        enabled = true
                    },
                    propertyDeclarationTypes = {
                        enabled = true
                    },
                    functionLikeReturnTypes = {
                        enabled = true
                    },
                    enumMemberValues = {
                        enabled = true
                    },
                }

            }
        }
    }
})

Now you should be able to show the hints with require('lsp-inlayhints').toggle()

Custom useful commands

This part is WIP, currently I'm adding some commands that I personaly find useful. Feel free to open an issue or PR to improve this part. Usage `:Deno custom_command` (press Tab for completion)

Check/Update dependencies

The list of available user commands is here https://github.com/sigmaSd/deno-nvim/blob/master/lua/deno-nvim/lsp.lua#L52

Important

For the lsp to function 100% correctly you need atleast:

  • nvim 0.8.0
  • deno 1.26.1

More stuff

You can checkout https://github.com/sigmaSd/conjure-deno for deno repl integration in nvim or just use iron.nvim https://github.com/sigmaSd/conjure-deno#alternative

Credits

Thanks to https://github.com/simrat39/rust-tools.nvim for the nice readable and commented codebase.