mirror of
https://github.com/nmasur/dotfiles
synced 2024-11-10 01:42:55 +00:00
add lsp to neovim flake
This commit is contained in:
parent
47a1823af4
commit
96c64c4da1
@ -176,6 +176,7 @@
|
||||
./modules/neovim/plugins/statusline.nix
|
||||
./modules/neovim/plugins/bufferline.nix
|
||||
./modules/neovim/plugins/telescope.nix
|
||||
./modules/neovim/plugins/lsp.nix
|
||||
];
|
||||
};
|
||||
|
||||
|
@ -2,63 +2,15 @@
|
||||
-- Settings
|
||||
-- ===========================================================================
|
||||
|
||||
-- Remember last position when reopening file
|
||||
vim.api.nvim_exec(
|
||||
[[
|
||||
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
|
||||
]] ,
|
||||
false
|
||||
)
|
||||
|
||||
-- Better backup, swap and undo storage
|
||||
vim.o.backup = true --- Easier to recover and more secure
|
||||
vim.bo.swapfile = false --- Instead of swaps, create backups
|
||||
vim.bo.undofile = true --- Keeps undos after quit
|
||||
|
||||
-- Create backup directories if they don't exist
|
||||
-- Should be fixed in 0.6 by https://github.com/neovim/neovim/pull/15433
|
||||
vim.o.backupdir = vim.fn.stdpath("cache") .. "/backup"
|
||||
vim.api.nvim_exec(
|
||||
[[
|
||||
if !isdirectory(&backupdir)
|
||||
call mkdir(&backupdir, "p")
|
||||
endif
|
||||
]] ,
|
||||
false
|
||||
)
|
||||
|
||||
-- LaTeX options
|
||||
vim.api.nvim_exec(
|
||||
[[
|
||||
au FileType tex inoremap ;bf \textbf{}<Esc>i
|
||||
au BufWritePost *.tex silent! execute "!pdflatex -output-directory=%:p:h % >/dev/null 2>&1" | redraw!
|
||||
]] ,
|
||||
false
|
||||
)
|
||||
|
||||
-- Highlight when yanking
|
||||
vim.api.nvim_exec(
|
||||
[[
|
||||
au TextYankPost * silent! lua vim.highlight.on_yank { timeout = 250 }
|
||||
]] ,
|
||||
false
|
||||
)
|
||||
|
||||
vim.filetype.add({
|
||||
pattern = {
|
||||
[".*%.tfvars"] = "terraform",
|
||||
},
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
pattern = "*.eml",
|
||||
callback = function()
|
||||
vim.o.wrapmargin = 79 -- Wrap text automatically
|
||||
end,
|
||||
})
|
||||
|
||||
-- Netrw
|
||||
vim.g.netrw_liststyle = 3 -- Change style to 'tree' view
|
||||
vim.g.netrw_banner = 0 -- Remove useless banner
|
||||
vim.g.netrw_winsize = 15 -- Explore window takes % of page
|
||||
vim.g.netrw_browse_split = 4 -- Open in previous window
|
||||
vim.g.netrw_altv = 1 -- Always split left
|
||||
|
@ -1,6 +1,4 @@
|
||||
{ pkgs, dsl, ... }:
|
||||
# with dsl;
|
||||
{
|
||||
{ pkgs, ... }: {
|
||||
plugins = [ pkgs.vimPlugins.gitsigns-nvim ];
|
||||
setup.gitsigns = { };
|
||||
lua = builtins.readFile ./gitsigns.lua;
|
||||
|
97
modules/neovim/plugins/lsp.nix
Normal file
97
modules/neovim/plugins/lsp.nix
Normal file
@ -0,0 +1,97 @@
|
||||
{ pkgs, dsl, ... }: {
|
||||
|
||||
plugins = [
|
||||
pkgs.vimPlugins.nvim-lspconfig
|
||||
pkgs.vimPlugins.lsp-colors-nvim
|
||||
pkgs.vimPlugins.null-ls-nvim
|
||||
];
|
||||
|
||||
use.lspconfig.sumneko_lua.setup = dsl.callWith {
|
||||
settings = { Lua = { diagnostics = { globals = [ "vim" "hs" ]; }; }; };
|
||||
capabilities = dsl.rawLua "require('cmp_nvim_lsp').default_capabilities()";
|
||||
cmd = [ "${pkgs.sumneko-lua-language-server}/bin/lua-language-server" ];
|
||||
};
|
||||
|
||||
use.lspconfig.nil_ls.setup = dsl.callWith {
|
||||
cmd = [ "${pkgs.nil}/bin/nil" ];
|
||||
capabilities = dsl.rawLua "require('cmp_nvim_lsp').default_capabilities()";
|
||||
};
|
||||
|
||||
use.lspconfig.pyright.setup = dsl.callWith {
|
||||
cmd = [ "${pkgs.pyright}/bin/pyright-langserver" "--stdio" ];
|
||||
};
|
||||
|
||||
use.lspconfig.terraformls.setup =
|
||||
dsl.callWith { cmd = [ "${pkgs.terraform-ls}/bin/terraform-lsp" ]; };
|
||||
|
||||
vim.api.nvim_create_augroup = dsl.callWith [ "LspFormatting" { } ];
|
||||
|
||||
# setup."null-ls" = {
|
||||
# sources = [
|
||||
# (dsl.rawLua
|
||||
# "require('null-ls').builtins.formatting.black.with({ command = ${pkgs.black}/bin/black })")
|
||||
# (dsl.rawLua
|
||||
# "require('null-ls').builtins.formatting.flake8.with({ command = ${pkgs.python310Packages.flake8}/bin/flake8 })")
|
||||
# (dsl.rawLua
|
||||
# "require('null-ls').builtins.formatting.fish_indent.with({ command = ${pkgs.fish}/bin/fish_indent })")
|
||||
# (dsl.rawLua
|
||||
# "require('null-ls').builtins.formatting.nixfmt.with({ command = ${pkgs.nixfmt}/bin/nixfmt })")
|
||||
# (dsl.rawLua
|
||||
# "require('null-ls').builtins.formatting.rustfmt.with({ command = ${pkgs.rustfmt}/bin/rustfmt })")
|
||||
# (dsl.rawLua
|
||||
# "require('null-ls').builtins.diagnostics.shellcheck.with({ command = ${pkgs.shellcheck}/bin/shellcheck })")
|
||||
# (dsl.rawLua ''
|
||||
# require('null-ls').builtins.formatting.shfmt.with(
|
||||
# command = {${pkgs.shfmt}/bin/shfmt },
|
||||
# extra_args = { '-i', '4', '-ci' },
|
||||
# )'')
|
||||
# (dsl.rawLua
|
||||
# "require('null-ls').builtins.formatting.terraform_fmt.with({ command = ${pkgs.terraform}/bin/terraform })")
|
||||
# ];
|
||||
# };
|
||||
|
||||
lua = ''
|
||||
vim.keymap.set("n", "gd", vim.lsp.buf.definition)
|
||||
vim.keymap.set("n", "gT", vim.lsp.buf.type_definition)
|
||||
vim.keymap.set("n", "gi", vim.lsp.buf.implementation)
|
||||
vim.keymap.set("n", "gh", vim.lsp.buf.hover)
|
||||
-- vim.keymap.set("n", "gr", telescope.lsp_references)
|
||||
vim.keymap.set("n", "<Leader>R", vim.lsp.buf.rename)
|
||||
vim.keymap.set("n", "]e", vim.diagnostic.goto_next)
|
||||
vim.keymap.set("n", "[e", vim.diagnostic.goto_prev)
|
||||
vim.keymap.set("n", "<Leader>de", vim.diagnostic.open_float)
|
||||
vim.keymap.set("n", "<Leader>E", vim.lsp.buf.code_action)
|
||||
|
||||
|
||||
require("null-ls").setup({
|
||||
sources = {
|
||||
require('null-ls').builtins.formatting.stylua.with({ command = "${pkgs.stylua}/bin/stylua" }),
|
||||
require('null-ls').builtins.formatting.black.with({ command = "${pkgs.black}/bin/black" }),
|
||||
require('null-ls').builtins.diagnostics.flake8.with({ command = "${pkgs.python310Packages.flake8}/bin/flake8" }),
|
||||
require('null-ls').builtins.formatting.fish_indent.with({ command = "${pkgs.fish}/bin/fish_indent" }),
|
||||
require('null-ls').builtins.formatting.nixfmt.with({ command = "${pkgs.nixfmt}/bin/nixfmt" }),
|
||||
require('null-ls').builtins.formatting.rustfmt.with({ command = "${pkgs.rustfmt}/bin/rustfmt" }),
|
||||
require('null-ls').builtins.diagnostics.shellcheck.with({ command = "${pkgs.shellcheck}/bin/shellcheck" }),
|
||||
require('null-ls').builtins.formatting.shfmt.with({
|
||||
command = "${pkgs.shfmt}/bin/shfmt",
|
||||
extra_args = { '-i', '4', '-ci' },
|
||||
}),
|
||||
require('null-ls').builtins.formatting.terraform_fmt.with({ command = "${pkgs.terraform}/bin/terraform" }),
|
||||
},
|
||||
|
||||
on_attach = function(client, bufnr)
|
||||
if client.supports_method("textDocument/formatting") then
|
||||
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
group = augroup,
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
vim.lsp.buf.format({ bufnr = bufnr })
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
})
|
||||
'';
|
||||
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
{ pkgs, lib, ... }: {
|
||||
{ pkgs, dsl, lib, ... }: {
|
||||
plugins = [
|
||||
pkgs.vimPlugins.vim-surround
|
||||
pkgs.vimPlugins.vim-eunuch
|
||||
pkgs.vimPlugins.vim-vinegar
|
||||
pkgs.vimPlugins.vim-fugitive
|
||||
pkgs.vimPlugins.vim-repeat
|
||||
pkgs.vimPlugins.comment-nvim
|
||||
pkgs.vimPlugins.impatient-nvim
|
||||
pkgs.vimPlugins.vim-surround # Keybinds for surround characters
|
||||
pkgs.vimPlugins.vim-eunuch # File manipulation commands
|
||||
pkgs.vimPlugins.vim-fugitive # Git commands
|
||||
pkgs.vimPlugins.vim-repeat # Better repeat using .
|
||||
pkgs.vimPlugins.comment-nvim # Smart comment commands
|
||||
pkgs.vimPlugins.impatient-nvim # Faster load times
|
||||
];
|
||||
|
||||
setup.Comment = { };
|
||||
|
||||
vim.o.termguicolors = true; # Set to truecolor
|
||||
@ -33,6 +33,12 @@
|
||||
vim.o.mouse = "nv"; # Mouse interaction / scrolling
|
||||
vim.o.inccommand = "split"; # Live preview search and replace
|
||||
|
||||
# Better backup, swap and undo storage
|
||||
vim.o.backup = true; # Easier to recover and more secure
|
||||
vim.bo.swapfile = false; # Instead of swaps, create backups
|
||||
vim.bo.undofile = true; # Keeps undos after quit
|
||||
vim.o.backupdir = dsl.rawLua ''vim.fn.stdpath("cache") .. "/backup"'';
|
||||
|
||||
# Required for nvim-cmp completion
|
||||
vim.opt.completeopt = [ "menu" "menuone" "noselect" ];
|
||||
|
||||
@ -41,4 +47,16 @@
|
||||
${builtins.readFile ../lua/keybinds.lua};
|
||||
${builtins.readFile ../lua/settings.lua};
|
||||
'';
|
||||
|
||||
vimscript = ''
|
||||
" Remember last position when reopening file
|
||||
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
|
||||
|
||||
" LaTeX options
|
||||
au FileType tex inoremap ;bf \textbf{}<Esc>i
|
||||
au BufWritePost *.tex silent! execute "!pdflatex -output-directory=%:p:h % >/dev/null 2>&1" | redraw!
|
||||
|
||||
" Flash highlight when yanking
|
||||
au TextYankPost * silent! lua vim.highlight.on_yank { timeout = 250 }
|
||||
'';
|
||||
}
|
||||
|
@ -1,8 +1,4 @@
|
||||
{ pkgs, dsl, ... }:
|
||||
|
||||
with dsl;
|
||||
|
||||
{
|
||||
{ pkgs, dsl, ... }: {
|
||||
|
||||
plugins = [
|
||||
pkgs.vimPlugins.telescope-nvim
|
||||
@ -16,7 +12,7 @@ with dsl;
|
||||
defaults = {
|
||||
mappings = {
|
||||
i = {
|
||||
"['<esc>']" = rawLua "require('telescope.actions').close";
|
||||
"['<esc>']" = dsl.rawLua "require('telescope.actions').close";
|
||||
"['<C-h>']" = "which_key";
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user