feat: more work on nvim config
This commit is contained in:
parent
df5e333e31
commit
716113c644
|
@ -1,19 +1,20 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function M.map(mode, lhs, rhs, opts)
|
function M.map(mode, lhs, rhs, opts)
|
||||||
local options = {noremap = true}
|
local options = {noremap = true}
|
||||||
if opts then options = vim.tbl_extend('force', options, opts) end
|
if opts then options = vim.tbl_extend('force', options, opts) end
|
||||||
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
|
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.mapSilent(mode, lhs, rhs, opts)
|
function M.mapSilent(mode, lhs, rhs, opts)
|
||||||
local options = {silent = true}
|
local options = {silent = true}
|
||||||
if opts then options = vim.tbl_extend('force', options, opts) end
|
if opts then options = vim.tbl_extend('force', options, opts) end
|
||||||
M.map(mode, lhs, rhs, opts)
|
M.map(mode, lhs, rhs, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.setup()
|
function M.setup()
|
||||||
M.map("i", "jj", "<Esc>") -- Remap Esc to
|
M.map("i", "jj", "<Esc>") -- Remap Esc to jj
|
||||||
|
M.map("n", "<Space><Space>", ":w<cr>") -- Double space to sace
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
|
@ -6,6 +6,7 @@ function M.setup()
|
||||||
|
|
||||||
-- Other unconfigured plugins
|
-- Other unconfigured plugins
|
||||||
require('nvim-autopairs').setup()
|
require('nvim-autopairs').setup()
|
||||||
|
require('nvim_comment').setup()
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
|
@ -1,16 +1,51 @@
|
||||||
|
local cmd = vim.cmd
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
-- Command for formatting lua code
|
||||||
|
local formatLua = "lua-format -i --no-keep-simple-function-one-line --no-break-after-operator --column-limit=150 --break-after-table-lb"
|
||||||
|
|
||||||
-- Use a loop to conveniently call 'setup' on multiple servers and
|
-- Use a loop to conveniently call 'setup' on multiple servers and
|
||||||
-- map buffer local keybindings when the language server attaches
|
-- map buffer local keybindings when the language server attaches
|
||||||
local servers = { "tsserver", "purescriptls" }
|
local servers = {
|
||||||
|
tsserver = {settings = {}, cmd = nil},
|
||||||
|
sumneko_lua = {
|
||||||
|
settings = {
|
||||||
|
|
||||||
function M.map(buf, mode, lhs, rhs, opts)
|
Lua = {
|
||||||
local options = { noremap=true, silent=true }
|
runtime = {
|
||||||
if opts then options = vim.tbl_extend('force', options, opts) end
|
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
|
||||||
map(buf, mode, lhs, rhs, options)
|
version = 'LuaJIT',
|
||||||
|
-- Setup your lua path
|
||||||
|
path = runtime_path
|
||||||
|
},
|
||||||
|
diagnostics = {
|
||||||
|
-- Get the language server to recognize the `vim` global
|
||||||
|
globals = {'vim'}
|
||||||
|
},
|
||||||
|
workspace = {
|
||||||
|
-- Make the server aware of Neovim runtime files
|
||||||
|
library = vim.api.nvim_get_runtime_file("", true)
|
||||||
|
},
|
||||||
|
-- Do not send telemetry data containing a randomized but unique identifier
|
||||||
|
telemetry = {enable = false}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
cmd = {"lua-language-server"}
|
||||||
|
},
|
||||||
|
purescriptls = {
|
||||||
|
settings = {purescript = {censorWarnings = {"UnusedName", "ShadowedName", "UserDefinedWarning"}, formatter = "purs-tidy"}},
|
||||||
|
cmd = nil
|
||||||
|
},
|
||||||
|
rnix = {settings = {}, cmd = nil}
|
||||||
|
}
|
||||||
|
|
||||||
|
local function map(buf, mode, lhs, rhs, opts)
|
||||||
|
local options = {noremap = true, silent = true}
|
||||||
|
if opts then options = vim.tbl_extend('force', options, opts) end
|
||||||
|
vim.api.nvim_buf_set_keymap(buf, mode, lhs, rhs, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_attach(client, bufnr)
|
local function on_attach(client, bufnr)
|
||||||
-- Enable completion triggered by <c-x><c-o>
|
-- Enable completion triggered by <c-x><c-o>
|
||||||
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
|
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
|
||||||
|
|
||||||
|
@ -37,14 +72,28 @@ function on_attach(client, bufnr)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.setup()
|
function M.setup()
|
||||||
for _, lsp in pairs(servers) do
|
-- Setup basic language servers
|
||||||
|
for lsp, details in pairs(servers) do
|
||||||
require('lspconfig')[lsp].setup {
|
require('lspconfig')[lsp].setup {
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
|
settings = details.settings, -- Specific per-language settings
|
||||||
flags = {
|
flags = {
|
||||||
debounce_text_changes = 150, -- This will be the default in neovim 0.7+
|
debounce_text_changes = 150 -- This will be the default in neovim 0.7+
|
||||||
}
|
},
|
||||||
|
cmd = details.cmd
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Setup auto-formatting
|
||||||
|
require"lspconfig".efm.setup {
|
||||||
|
init_options = {documentFormatting = true},
|
||||||
|
filetypes = {"lua"},
|
||||||
|
settings = {rootMarkers = {".git/"}, languages = {lua = {{formatCommand = formatLua, formatStdin = true}}}}
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Auto format lua stuff
|
||||||
|
cmd("autocmd BufWritePre *.lua lua vim.lsp.buf.formatting_sync(nil, 100)")
|
||||||
|
-- cmd("autocmd BufWritePre nix vim.lsp.buf.formatting_sync(nil, 100)")
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
|
@ -4,8 +4,10 @@ let
|
||||||
name = "config-nvim";
|
name = "config-nvim";
|
||||||
src = ../../dotfiles/neovim;
|
src = ../../dotfiles/neovim;
|
||||||
};
|
};
|
||||||
in {
|
in
|
||||||
home-manager.users.adrielus.programs.neovim = {
|
|
||||||
|
{
|
||||||
|
home-manager.users.adrielus.programs.neovim = {
|
||||||
enable = true;
|
enable = true;
|
||||||
package = pkgs.neovim-nightly;
|
package = pkgs.neovim-nightly;
|
||||||
|
|
||||||
|
@ -14,13 +16,18 @@ in {
|
||||||
luafile ${config-nvim}/init.lua
|
luafile ${config-nvim}/init.lua
|
||||||
'';
|
'';
|
||||||
|
|
||||||
extraPackages = [
|
extraPackages = with pkgs; [
|
||||||
pkgs.fzf # Required by lua-fzf
|
fzf # Required by lua-fzf
|
||||||
|
|
||||||
# Language servers
|
# Language servers
|
||||||
pkgs.nodePackages.typescript
|
nodePackages.typescript # typescript
|
||||||
pkgs.easy-purescript-nix.purescript-language-server
|
easy-purescript-nix.purescript-language-server # purescript
|
||||||
|
sumneko-lua-language-server # lua
|
||||||
|
efm-langserver # auto-formatting
|
||||||
|
rnix-lsp # nix
|
||||||
|
|
||||||
|
# Formatters
|
||||||
|
luaformatter # lua
|
||||||
];
|
];
|
||||||
|
|
||||||
plugins = with pkgs.vimPlugins;
|
plugins = with pkgs.vimPlugins;
|
||||||
|
@ -30,6 +37,8 @@ in {
|
||||||
nvim-lspconfig # configures lsps for me
|
nvim-lspconfig # configures lsps for me
|
||||||
nvim-autopairs # close pairs for me
|
nvim-autopairs # close pairs for me
|
||||||
fzf-lua # fuzzy search for say opening files
|
fzf-lua # fuzzy search for say opening files
|
||||||
|
purescript-vim # purescript syntax highlighting
|
||||||
|
nvim-comment # allows toggling line-comments
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue