zioroboco / nu-ls.nvim

A null-ls source providing language server features for the nushell language in neovim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nu-ls.nvim

A null-ls.nvim source providing language server features for the nushell language in neovim.

Intended to provide an uncomplicated way to access nushell's language server features via the nu --ide-* flags added in nushell v0.79. It does not provide syntax highlighting or other features (see nushell/tree-sitter-nu), and not all language server methods are supported (e.g. go to definition, see #2).

Note that this project is unstable: releases are unversioned, and future updates will require backwards-incompatible changes to config.

Installation

Installing the nu-ls.nvim package

Install zioroboco/nu-ls.nvim using any package manager. Note that this is a null-ls.nvim source, which will also need to be installed along with its dependency plenary.nvim.

For example:

-- if using folke/lazy.nvim
require("lazy").setup({
  "nvim-lua/plenary.nvim",
  "jose-elias-alvarez/null-ls.nvim",
  "zioroboco/nu-ls.nvim",
  -- ...
})

-- if using wbthomason/packer.nvim
require("packer").startup(function(use)
  use "nvim-lua/plenary.nvim"
  use "jose-elias-alvarez/null-ls.nvim"
  use "zioroboco/nu-ls.nvim"
  -- ...
end)

Registering as a null-ls source

The nu-ls source can now be registered with null-ls:

-- register nu-ls as a null-ls source (required)
require("null-ls").setup({
  sources = {
    require("nu-ls"),
    -- ...
  },
})

Setting the nu filetype

The nu-ls source will be attached to buffers with the nu filetype.

This filetype can be associated with buffers according to their file extension:

vim.filetype.add({
  extension = {
    nu = "nu",
  },
})

In addition, you can also set the filetype by reading shebangs, which might be useful if you keep any executable nushell scripts without the .nu extension. For example (assuming shebangs starting #!/usr/bin/env nu):

-- see `:h vim.filetype.add()`
vim.filetype.add({
  pattern = {
    [".*"] = {
      priority = -math.huge,
      function(path, bufnr)
        local content = vim.filetype.getlines(bufnr, 1)
        if vim.filetype.matchregex(content, [[^#!/usr/bin/env nu]]) then
          return "nu"
        end
      end,
    },
  },
})

Troubleshooting

Completion performance

Completions are a bit inefficient, and so are not generated until 500ms after the last input. To modify this, the setup function can be used to construct a custom null-ls source, with either a different debounce time or by removing "completion" from the list of enabled null-ls methods:

require("null-ls").setup({
  sources = {
    -- note: setup is optional, default values are below
    require("nu-ls").setup({
      debounce = 500, -- completion debounce time in ms
      methods = {
        "completion", -- remove to disable completions altogether
        "diagnostics_on_open",
        "diagnostics_on_save",
        "hover",
      },
    }),
    -- ...
  },
})

About

A null-ls source providing language server features for the nushell language in neovim

License:MIT License


Languages

Language:Lua 98.1%Language:Nu 1.9%