Add this file as a custom plugin:
-- ./lua/plugins/nu-lsp.lua
vim.filetype.add({
extension = {
nu = "nu",
nush = "nu",
nuon = "nu",
nushell = "nu",
},
pattern = {
[".*"] = {
function(path, bufnr)
local content = vim.filetype.getlines(bufnr, 1)
if vim.filetype.matchregex(content, [[^#!/usr/bin/env (-S )?nu( --stdin)?]]) then
return "nu"
end
end,
priority = -math.huge,
},
},
})
return {
-- Set up nu LSP
{ "neovim/nvim-lspconfig",
opts = {
servers = {
nu_ls = {
settings = {
nu = {}
}
}
},
setup = {
nu_ls = function(_, opts)
local lspconfig = require('lspconfig')
local configs = require('lspconfig.configs')
configs.nu_ls = {
default_config = {
cmd = { "nu", "--lsp" },
filetypes = { "nu" },
root_dir = function(fname)
local git_root = lspconfig.util.find_git_ancestor(fname)
if git_root then
return git_root
else
return vim.fn.fnamemodify(fname, ":p:h") -- get the parent directory of the file
end
end
},
}
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
lspconfig.nu_ls.setup({ capabilities = capabilities })
return true
end
}
}
},
{
"nvim-treesitter/nvim-treesitter",
opts = {
ensure_installed = {
"nu"
}
},
init = function()
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
parser_config.nu = {
install_info = {
url = "https://github.com/nushell/tree-sitter-nu",
files = { "src/parser.c" },
branch = "main",
},
filetype = "nu",
}
end
}
}
Then run this command once (As instructed from here):
let remote = "https://raw.githubusercontent.com/nushell/tree-sitter-nu/main/queries/"
let local = (
$env.XDG_DATA_HOME?
| default ($env.HOME | path join ".local" "share")
| path join "nvim" "lazy" "nvim-treesitter" "queries" "nu"
)
let file = "highlights.scm"
mkdir $local
http get ([$remote $file] | str join "/") | save --force ($local | path join $file)