feat: embrace neovim lsp
parent
eeb0baf8b0
commit
23fbc255a2
|
@ -8,17 +8,27 @@
|
||||||
vimdiffAlias = true;
|
vimdiffAlias = true;
|
||||||
withPython3 = true;
|
withPython3 = true;
|
||||||
extraPackages = with pkgs; [
|
extraPackages = with pkgs; [
|
||||||
|
ansible-language-server
|
||||||
|
beancount-language-server
|
||||||
black
|
black
|
||||||
|
docker-compose-language-service
|
||||||
efm-langserver
|
efm-langserver
|
||||||
|
gcc
|
||||||
hlint
|
hlint
|
||||||
jq
|
ltex-ls
|
||||||
|
lua-language-server
|
||||||
lua54Packages.luacheck
|
lua54Packages.luacheck
|
||||||
nixfmt
|
nixd
|
||||||
|
nixpkgs-fmt
|
||||||
|
nodePackages.dockerfile-language-server-nodejs
|
||||||
nodePackages.pyright
|
nodePackages.pyright
|
||||||
pylint
|
ruff-lsp
|
||||||
ruff
|
shellcheck
|
||||||
shfmt
|
shfmt
|
||||||
stylua
|
sqlfluff
|
||||||
|
terraform-ls
|
||||||
|
tflint
|
||||||
|
vscode-langservers-extracted
|
||||||
];
|
];
|
||||||
extraPython3Packages = pyPkgs: with pyPkgs; [ pylint ];
|
extraPython3Packages = pyPkgs: with pyPkgs; [ pylint ];
|
||||||
plugins = [ pkgs.vimPlugins.packer-nvim ];
|
plugins = [ pkgs.vimPlugins.packer-nvim ];
|
||||||
|
|
|
@ -1,85 +1,90 @@
|
||||||
-- luacheck: globals vim
|
-- luacheck: globals vim
|
||||||
|
|
||||||
require("packer").startup(function(use)
|
require("packer").startup(function(use)
|
||||||
use("tpope/vim-sensible")
|
use("tpope/vim-sensible")
|
||||||
|
|
||||||
use("vimwiki/vimwiki")
|
use("vimwiki/vimwiki")
|
||||||
use("freitass/todo.txt-vim")
|
use("freitass/todo.txt-vim")
|
||||||
use("ledger/vim-ledger")
|
use("ledger/vim-ledger")
|
||||||
|
|
||||||
use("Shougo/deoplete.nvim")
|
use("psliwka/vim-smoothie")
|
||||||
use("dense-analysis/ale")
|
|
||||||
|
|
||||||
use("psliwka/vim-smoothie")
|
-- navigation
|
||||||
|
use("easymotion/vim-easymotion")
|
||||||
|
use("tpope/vim-unimpaired")
|
||||||
|
use("tpope/vim-surround")
|
||||||
|
use("christoomey/vim-tmux-navigator")
|
||||||
|
|
||||||
-- navigation
|
-- fern
|
||||||
use("easymotion/vim-easymotion")
|
use("lambdalisue/fern.vim")
|
||||||
use("tpope/vim-unimpaired")
|
use("lambdalisue/nerdfont.vim")
|
||||||
use("tpope/vim-surround")
|
use("lambdalisue/fern-renderer-nerdfont.vim")
|
||||||
use("christoomey/vim-tmux-navigator")
|
use("lambdalisue/glyph-palette.vim")
|
||||||
|
use("lambdalisue/fern-git-status.vim")
|
||||||
|
use("lambdalisue/fern-mapping-git.vim") -- to check
|
||||||
|
use("lambdalisue/fern-hijack.vim")
|
||||||
|
|
||||||
-- fern
|
-- airline
|
||||||
use("lambdalisue/fern.vim")
|
use("vim-airline/vim-airline")
|
||||||
use("lambdalisue/nerdfont.vim")
|
use("vim-airline/vim-airline-themes")
|
||||||
use("lambdalisue/fern-renderer-nerdfont.vim")
|
|
||||||
use("lambdalisue/glyph-palette.vim")
|
|
||||||
use("lambdalisue/fern-git-status.vim")
|
|
||||||
use("lambdalisue/fern-mapping-git.vim") -- to check
|
|
||||||
use("lambdalisue/fern-hijack.vim")
|
|
||||||
|
|
||||||
-- airline
|
use("tpope/vim-fugitive")
|
||||||
use("vim-airline/vim-airline")
|
use("airblade/vim-gitgutter")
|
||||||
use("vim-airline/vim-airline-themes")
|
|
||||||
|
|
||||||
use("tpope/vim-fugitive")
|
use("honza/vim-snippets")
|
||||||
use("airblade/vim-gitgutter")
|
use("SirVer/ultisnips")
|
||||||
|
|
||||||
use("honza/vim-snippets")
|
use("junegunn/fzf.vim")
|
||||||
use("SirVer/ultisnips")
|
|
||||||
|
|
||||||
use("junegunn/fzf.vim")
|
use("junegunn/goyo.vim")
|
||||||
|
use("junegunn/limelight.vim")
|
||||||
|
|
||||||
use("junegunn/goyo.vim")
|
use("preservim/nerdcommenter")
|
||||||
use("junegunn/limelight.vim")
|
|
||||||
|
|
||||||
use("preservim/nerdcommenter")
|
use("luochen1990/rainbow")
|
||||||
|
use("ap/vim-css-color")
|
||||||
|
|
||||||
use("luochen1990/rainbow")
|
use("Yggdroot/indentLine")
|
||||||
use("ap/vim-css-color")
|
|
||||||
|
|
||||||
use("Yggdroot/indentLine")
|
use("gruvbox-community/gruvbox")
|
||||||
|
|
||||||
use("gruvbox-community/gruvbox")
|
-- language support
|
||||||
|
use("darrikonn/vim-gofmt")
|
||||||
|
use("Glench/Vim-Jinja2-Syntax")
|
||||||
|
use("preservim/vim-markdown")
|
||||||
|
use("LnL7/vim-nix")
|
||||||
|
use("hashivim/vim-terraform")
|
||||||
|
use("LaTeX-Box-Team/LaTeX-Box")
|
||||||
|
use("vito-c/jq.vim")
|
||||||
|
use("tpope/vim-haml")
|
||||||
|
use({ "psf/black", branch = "stable" })
|
||||||
|
use("elzr/vim-json")
|
||||||
|
|
||||||
-- language support
|
use("jpalardy/vim-slime")
|
||||||
use("darrikonn/vim-gofmt")
|
|
||||||
use("Glench/Vim-Jinja2-Syntax")
|
|
||||||
use("preservim/vim-markdown")
|
|
||||||
use("LnL7/vim-nix")
|
|
||||||
use("hashivim/vim-terraform")
|
|
||||||
use("LaTeX-Box-Team/LaTeX-Box")
|
|
||||||
use("vito-c/jq.vim")
|
|
||||||
use("tpope/vim-haml")
|
|
||||||
use({ "psf/black", branch = "stable" })
|
|
||||||
use("elzr/vim-json")
|
|
||||||
use("z0mbix/vim-shfmt")
|
|
||||||
use("ckipp01/stylua-nvim")
|
|
||||||
|
|
||||||
use("jpalardy/vim-slime")
|
use("neovim/nvim-lspconfig")
|
||||||
use("neovim/nvim-lspconfig")
|
use("hrsh7th/nvim-cmp") -- Autocompletion plugin
|
||||||
use("lukas-reineke/lsp-format.nvim")
|
use("hrsh7th/cmp-nvim-lsp") -- LSP source for nvim-cmp
|
||||||
|
use("hrsh7th/cmp-buffer")
|
||||||
|
use("hrsh7th/cmp-path")
|
||||||
|
use("saadparwaiz1/cmp_luasnip") -- Snippets source for nvim-cmp
|
||||||
|
use("L3MON4D3/LuaSnip") -- Snippets plugin
|
||||||
|
use("lukas-reineke/lsp-format.nvim")
|
||||||
|
|
||||||
use("sheerun/vim-polyglot")
|
use("sheerun/vim-polyglot")
|
||||||
|
|
||||||
|
use("nvim-treesitter/nvim-treesitter")
|
||||||
|
use("nvim-orgmode/orgmode")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local o = vim.opt
|
local o = vim.opt
|
||||||
|
|
||||||
local function map(mode, shortcut, command)
|
local function map(mode, shortcut, command)
|
||||||
vim.api.nvim_set_keymap(mode, shortcut, command, { noremap = true, silent = true })
|
vim.api.nvim_set_keymap(mode, shortcut, command, { noremap = true, silent = true })
|
||||||
end
|
end
|
||||||
|
|
||||||
local function nmap(shortcut, command)
|
local function nmap(shortcut, command)
|
||||||
map("n", shortcut, command)
|
map("n", shortcut, command)
|
||||||
end
|
end
|
||||||
|
|
||||||
--local function imap(shortcut, command)
|
--local function imap(shortcut, command)
|
||||||
|
@ -89,19 +94,19 @@ end
|
||||||
o.wrap = false
|
o.wrap = false
|
||||||
o.number = true
|
o.number = true
|
||||||
o.compatible = false
|
o.compatible = false
|
||||||
o.mouse = "a" -- mouse support
|
o.mouse = "a" -- mouse support
|
||||||
o.showcmd = true -- show incomplete cmds down the bottom
|
o.showcmd = true -- show incomplete cmds down the bottom
|
||||||
o.showmode = true -- show current mode
|
o.showmode = true -- show current mode
|
||||||
o.showmatch = true -- set show matching parenthesis
|
o.showmatch = true -- set show matching parenthesis
|
||||||
o.visualbell = true -- no sounds
|
o.visualbell = true -- no sounds
|
||||||
o.autoread = true -- reload files changed outside of vim
|
o.autoread = true -- reload files changed outside of vim
|
||||||
o.backspace = [[indent,eol,start]] -- allow backspacing over everything in insert mode
|
o.backspace = [[indent,eol,start]] -- allow backspacing over everything in insert mode
|
||||||
o.ignorecase = true -- ignore case when searching
|
o.ignorecase = true -- ignore case when searching
|
||||||
o.shiftround = true -- use multiple of shiftwidth when indenting with '<' and '>'
|
o.shiftround = true -- use multiple of shiftwidth when indenting with '<' and '>'
|
||||||
o.smartcase = true -- ignore case if searching pattern is all lowecase, case-sensitive otherwise
|
o.smartcase = true -- ignore case if searching pattern is all lowecase, case-sensitive otherwise
|
||||||
o.smarttab = true -- insert tabs on the start of a line according to shiftwidth, not tabstop
|
o.smarttab = true -- insert tabs on the start of a line according to shiftwidth, not tabstop
|
||||||
o.hlsearch = true -- highlight search terms
|
o.hlsearch = true -- highlight search terms
|
||||||
o.incsearch = true -- show search matches as you type
|
o.incsearch = true -- show search matches as you type
|
||||||
o.hidden = true
|
o.hidden = true
|
||||||
o.ruler = true
|
o.ruler = true
|
||||||
o.clipboard = "unnamed" -- system clipboard
|
o.clipboard = "unnamed" -- system clipboard
|
||||||
|
@ -111,9 +116,9 @@ vim.cmd("syntax on")
|
||||||
vim.cmd("filetype plugin on")
|
vim.cmd("filetype plugin on")
|
||||||
|
|
||||||
if vim.fn.has("multi_byte") == 1 and vim.o.encoding == "utf-8" then
|
if vim.fn.has("multi_byte") == 1 and vim.o.encoding == "utf-8" then
|
||||||
o.listchars = [[tab:▸ ,extends:❯,precedes:❮,nbsp:±,trail:…]]
|
o.listchars = [[tab:▸ ,extends:❯,precedes:❮,nbsp:±,trail:…]]
|
||||||
else
|
else
|
||||||
o.listchars = [[tab:> ,extends:>,precedes:<,nbsp:.,trail:_]]
|
o.listchars = [[tab:> ,extends:>,precedes:<,nbsp:.,trail:_]]
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.g.mapleader = ","
|
vim.g.mapleader = ","
|
||||||
|
@ -192,7 +197,7 @@ augroup my-glyph-palette
|
||||||
augroup END
|
augroup END
|
||||||
]])
|
]])
|
||||||
nmap("<leader>t", ":Fern . -drawer -toggle<cr>")
|
nmap("<leader>t", ":Fern . -drawer -toggle<cr>")
|
||||||
nmap("<leader>f", ":Files<cr>")
|
-- nmap("<leader>f", ":Files<cr>")
|
||||||
nmap("<leader>rg", ":Rg<cr>")
|
nmap("<leader>rg", ":Rg<cr>")
|
||||||
nmap("<leader><Bs>", ": cd ..<cr>")
|
nmap("<leader><Bs>", ": cd ..<cr>")
|
||||||
nmap("<leader>b", ": Buffers<cr>")
|
nmap("<leader>b", ": Buffers<cr>")
|
||||||
|
@ -213,50 +218,163 @@ vim.g["airline_theme"] = "base16_gruvbox_dark_hard"
|
||||||
vim.g["airline#extensions#tabline#enabled"] = 1
|
vim.g["airline#extensions#tabline#enabled"] = 1
|
||||||
vim.g["airline#extensions#ale#enabled"] = 1
|
vim.g["airline#extensions#ale#enabled"] = 1
|
||||||
|
|
||||||
vim.g["ale_lint_on_text_changed"] = "never"
|
|
||||||
vim.g["ale_lint_on_insert_leave"] = 0
|
|
||||||
vim.g["ale_lint_on_enter"] = 0
|
|
||||||
|
|
||||||
vim.g["deoplete#enable_at_startup"] = 1
|
vim.g["deoplete#enable_at_startup"] = 1
|
||||||
|
|
||||||
-- vim.g["black_virtualenv"] = "/Users/rilla/virtualenvs/black"
|
|
||||||
|
|
||||||
vim.g["shfmt_extra_args"] = "-i 4"
|
|
||||||
vim.g["NERDDefaultAlign"] = "left"
|
vim.g["NERDDefaultAlign"] = "left"
|
||||||
|
|
||||||
vim.g["UltiSnipsExpandTrigger"] = "<tab>"
|
vim.g["UltiSnipsExpandTrigger"] = "<tab>"
|
||||||
vim.g["UltiSnipsJumpForwardTrigger"] = "<c-b>"
|
vim.g["UltiSnipsJumpForwardTrigger"] = "<c-b>"
|
||||||
vim.g["UltiSnipsJumpBackwardTrigger"] = "<c-z>"
|
vim.g["UltiSnipsJumpBackwardTrigger"] = "<c-z>"
|
||||||
|
|
||||||
local formatters = {
|
local lspconfig = require("lspconfig")
|
||||||
go = ":GoFmt<CR>",
|
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||||
json = ":%!jq --indent 4 .<CR>",
|
|
||||||
nix = ":%!nixfmt < %<CR>",
|
lspconfig.pyright.setup { capabilities = capabilities }
|
||||||
-- python = ":Black<CR>",
|
lspconfig.ruff_lsp.setup { capabilities = capabilities }
|
||||||
python = [[<cmd>lua vim.lsp.buf.format()<CR>]],
|
|
||||||
sh = ":Shfmt<CR>",
|
lspconfig.nixd.setup { capabilities = capabilities }
|
||||||
sql = ":%!sqlfluff fix -<CR>",
|
lspconfig.jsonls.setup { capabilities = capabilities }
|
||||||
terraform = ":TerraformFmt<CR>",
|
lspconfig.ansiblels.setup { capabilities = capabilities }
|
||||||
lua = [[<cmd>lua require("stylua-nvim").format_file()<CR>]],
|
lspconfig.beancount.setup { capabilities = capabilities }
|
||||||
|
lspconfig.ltex.setup { capabilities = capabilities }
|
||||||
|
|
||||||
|
lspconfig.terraformls.setup { capabilities = capabilities }
|
||||||
|
lspconfig.tflint.setup { capabilities = capabilities }
|
||||||
|
|
||||||
|
lspconfig.docker_compose_language_service.setup {
|
||||||
|
root_dir = lspconfig.util.root_pattern("docker-compose.yaml", "docker-compose.yml"),
|
||||||
|
filetypes = { "yaml", "yaml.docker-compose" },
|
||||||
|
capabilities = capabilities,
|
||||||
|
}
|
||||||
|
lspconfig.dockerls.setup { capabilities = capabilities }
|
||||||
|
|
||||||
|
-- lspconfig.sqlls.setup {capabilities = capabilities}
|
||||||
|
|
||||||
|
lspconfig.lua_ls.setup {
|
||||||
|
settings = {
|
||||||
|
Lua = {
|
||||||
|
runtime = {
|
||||||
|
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
|
||||||
|
version = "LuaJIT",
|
||||||
|
},
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
capabilities = capabilities
|
||||||
}
|
}
|
||||||
|
|
||||||
for pattern, command in pairs(formatters) do
|
lspconfig.efm.setup {
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
init_options = { documentFormatting = true },
|
||||||
pattern = pattern,
|
filetypes = { "python", "sh" },
|
||||||
callback = function()
|
settings = {
|
||||||
nmap("<C-f>", command)
|
rootMarkers = { ".git/", "pyproject.toml" },
|
||||||
end,
|
languages = {
|
||||||
})
|
python = { { formatCommand = "black -", formatStdin = true } },
|
||||||
end
|
sql = { {
|
||||||
|
formatCommand = "sqlfluff fix --dialect bigquery -",
|
||||||
|
formatStdin = true
|
||||||
|
} },
|
||||||
|
sh = { {
|
||||||
|
formatCommand = "shfmt -i 4 -bn -sr -p -ci",
|
||||||
|
formatStdin = true,
|
||||||
|
lintCommand = "shellcheck -f gcc -x",
|
||||||
|
lintSource = "shellcheck",
|
||||||
|
lintFormats = {
|
||||||
|
"%f:%l:%c: %trror: %m",
|
||||||
|
"%f:%l:%c: %tarning: %m",
|
||||||
|
"%f:%l:%c: %tote: %m",
|
||||||
|
}
|
||||||
|
} },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
capabilities = capabilities
|
||||||
|
}
|
||||||
|
|
||||||
require("lspconfig").pyright.setup({})
|
local luasnip = require 'luasnip'
|
||||||
|
local cmp = require 'cmp'
|
||||||
|
cmp.setup {
|
||||||
|
snippet = {
|
||||||
|
expand = function(args)
|
||||||
|
luasnip.lsp_expand(args.body)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
mapping = cmp.mapping.preset.insert({
|
||||||
|
['<C-u>'] = cmp.mapping.scroll_docs(-4), -- Up
|
||||||
|
['<C-d>'] = cmp.mapping.scroll_docs(4), -- Down
|
||||||
|
-- C-b (back) C-f (forward) for snippet placeholder navigation.
|
||||||
|
['<C-Space>'] = cmp.mapping.complete(),
|
||||||
|
['<CR>'] = cmp.mapping.confirm {
|
||||||
|
behavior = cmp.ConfirmBehavior.Replace,
|
||||||
|
select = true,
|
||||||
|
},
|
||||||
|
['<Tab>'] = cmp.mapping(function(fallback)
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.select_next_item()
|
||||||
|
elseif luasnip.expand_or_jumpable() then
|
||||||
|
luasnip.expand_or_jump()
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end, { 'i', 's' }),
|
||||||
|
['<S-Tab>'] = cmp.mapping(function(fallback)
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.select_prev_item()
|
||||||
|
elseif luasnip.jumpable(-1) then
|
||||||
|
luasnip.jump(-1)
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end, { 'i', 's' }),
|
||||||
|
}),
|
||||||
|
sources = {
|
||||||
|
{ name = 'nvim_lsp' },
|
||||||
|
{ name = 'luasnip' },
|
||||||
|
{ name = 'buffer' },
|
||||||
|
{ name = 'path' },
|
||||||
|
{ name = 'orgmode' },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
require("lspconfig").efm.setup({
|
local orgmode = require("orgmode")
|
||||||
init_options = { documentFormatting = true },
|
|
||||||
settings = {
|
orgmode.setup_ts_grammar()
|
||||||
rootMarkers = { ".git/", "pyproject.toml" },
|
require("nvim-treesitter.configs").setup {
|
||||||
languages = {
|
-- If TS highlights are not enabled at all, or disabled via `disable` prop,
|
||||||
python = { { formatCommand = "black -", formatStdin = true } },
|
-- highlighting will fallback to default Vim syntax highlighting
|
||||||
},
|
highlight = {
|
||||||
},
|
enable = true,
|
||||||
|
-- Required for spellcheck, some LaTex highlights and
|
||||||
|
-- code block highlights that do not have ts grammar
|
||||||
|
additional_vim_regex_highlighting = { "org" },
|
||||||
|
},
|
||||||
|
ensure_installed = { "org" }, -- Or run :TSUpdate org
|
||||||
|
}
|
||||||
|
|
||||||
|
orgmode.setup {
|
||||||
|
org_agenda_files = { "~/Nextcloud/org/*" },
|
||||||
|
org_default_notes_file = "~/Nextcloud/org/refile.org",
|
||||||
|
}
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd("LspAttach", {
|
||||||
|
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
|
||||||
|
callback = function(ev)
|
||||||
|
-- Enable completion triggered by <c-x><c-o>
|
||||||
|
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
|
||||||
|
|
||||||
|
local opts = { buffer = ev.buf }
|
||||||
|
vim.keymap.set("n", "<C-f>", function()
|
||||||
|
vim.lsp.buf.format({ async = true })
|
||||||
|
end, opts)
|
||||||
|
end,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue