Change completion engine to a more modern one, add neogit for git

operations
This commit is contained in:
Haak Saxberg 2023-01-24 23:07:14 -08:00
parent 0b89134c20
commit 823a2ecfe2
3 changed files with 167 additions and 175 deletions

View file

@ -69,51 +69,21 @@ with builtins;
''; '';
} }
vim-surround vim-surround
fugitive neogit
{ gitsigns-nvim
plugin = easymotion;
config = ''
map / <Plug>(easymotion-sn)
omap / <Plug>(easymotion-tn)
map n <Plug>(easymotion-next)
map N <Plug>(easymotion-prev)
let g:EasyMotion_landing_highlight = 0
'';
}
vinegar vinegar
undotree undotree
vim-goyo
{ {
plugin = nvim-compe; plugin = nvim-cmp;
config = '' config = ''
set completeopt=menuone,noselect lua << EOF
let g:compe = {} ${ readFile (./nvim-cmp.lua) }
let g:compe.enabled = v:true EOF
let g:compe.autocomplete = v:true
let g:compe.debug = v:false
let g:compe.min_length = 1
let g:compe.preselect = 'enable'
let g:compe.throttle_time = 80
let g:compe.source_timeout = 200
let g:compe.resolve_timeout = 800
let g:compe.incomplete_delay = 400
let g:compe.max_abbr_width = 100
let g:compe.max_kind_width = 100
let g:compe.max_menu_width = 100
let g:compe.documentation = v:true
let g:compe.source = {}
let g:compe.source.path = v:true
let g:compe.source.buffer = v:true
let g:compe.source.calc = v:true
let g:compe.source.nvim_lsp = v:true
let g:compe.source.nvim_lua = v:true
let g:compe.source.vsnip = v:true
let g:compe.source.ultisnips = v:true
let g:compe.source.luasnip = v:true
let g:compe.source.emoji = v:true
''; '';
} }
vim-goyo luasnip
cmp-nvim-lsp
{ {
plugin = nvim-lspconfig; plugin = nvim-lspconfig;
config = '' config = ''

View file

@ -0,0 +1,29 @@
local cmp = require("cmp")
cmp.setup({
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
-- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
}, {
{ name = 'buffer' },
})
})

View file

@ -1,165 +1,158 @@
local nvim_lsp = require("lspconfig") local nvim_lsp = require("lspconfig")
--
-- https://vonheikemen.github.io/devlog/tools/setup-nvim-lspconfig-plus-nvim-cmp/
local lsp_defaults = nvim_lsp.util.default_config
lsp_defaults.capabilities = vim.tbl_deep_extend(
'force',
lsp_defaults.capabilities,
require("cmp_nvim_lsp").default_capabilities()
)
-- local format_async = function(err, _, result, _, bufnr) vim.api.nvim_create_autocmd("LspAttach", {
-- if err ~= nil or result == nil then return end desc = "LSP actions",
-- if not vim.api.nvim_buf_get_option(bufnr, "modified") then callback = function()
-- local view = vim.fn.winsaveview() local bufmap = function(mode, lhs, rhs)
-- vim.lsp.util.apply_text_edits(result, bufnr) local opts = { buffer = true }
-- vim.fn.winrestview(view) vim.keymap.set(mode, lhs, rhs, opts)
-- if bufnr == vim.api.nvim_get_current_buf() then
-- vim.api.nvim_command("noautocmd :update")
-- end
-- end
-- end
-- vim.lsp.handlers["textDocument/formatting"] = format_async
local on_attach = function(client, bufnr)
local buf_map = vim.api.nvim_buf_set_keymap
vim.cmd("command! LspDef lua vim.lsp.buf.definition()")
vim.cmd("command! LspFormatting lua vim.lsp.buf.formatting()")
vim.cmd("command! LspCodeAction lua vim.lsp.buf.code_action()")
vim.cmd("command! LspHover lua vim.lsp.buf.hover()")
vim.cmd("command! LspRename lua vim.lsp.buf.rename()")
vim.cmd("command! LspOrganize lua lsp_organize_imports()")
vim.cmd("command! LspRefs lua vim.lsp.buf.references()")
vim.cmd("command! LspTypeDef lua vim.lsp.buf.type_definition()")
vim.cmd("command! LspImplementation lua vim.lsp.buf.implementation()")
vim.cmd("command! LspDiagPrev lua vim.lsp.diagnostic.goto_prev()")
vim.cmd("command! LspDiagNext lua vim.lsp.diagnostic.goto_next()")
vim.cmd("command! LspDiagLine lua vim.lsp.diagnostic.show_line_diagnostics()")
vim.cmd("command! LspSignatureHelp lua vim.lsp.buf.signature_help()")
buf_map(bufnr, "n", "gd", ":LspDef<CR>", {silent = true})
buf_map(bufnr, "n", "gr", ":LspRename<CR>", {silent = true})
buf_map(bufnr, "n", "gR", ":LspRefs<CR>", {silent = true})
buf_map(bufnr, "n", "gy", ":LspTypeDef<CR>", {silent = true})
buf_map(bufnr, "n", "K", ":LspHover<CR>", {silent = true})
buf_map(bufnr, "n", "gs", ":LspOrganize<CR>", {silent = true})
buf_map(bufnr, "n", "[a", ":LspDiagPrev<CR>", {silent = true})
buf_map(bufnr, "n", "]a", ":LspDiagNext<CR>", {silent = true})
buf_map(bufnr, "n", "ga", ":LspCodeAction<CR>", {silent = true})
buf_map(bufnr, "n", "<Leader>a", ":LspDiagLine<CR>", {silent = true})
buf_map(bufnr, "i", "<C-x><C-x>", "<cmd> LspSignatureHelp<CR>", {silent = true})
if client.resolved_capabilities.document_formatting then
vim.api.nvim_exec([[
augroup LspAutocommands
autocmd! * <buffer>
autocmd BufWritePost <buffer> LspFormatting
augroup END
]], true)
end end
end
-- Displays hover information about the symbol under the cursor
bufmap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>')
-- Jump to the definition
bufmap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>')
-- Jump to declaration
bufmap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>')
-- Lists all the implementations for the symbol under the cursor
bufmap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>')
-- Jumps to the definition of the type symbol
bufmap('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>')
-- Lists all the references
bufmap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>')
-- Displays a function's signature information
bufmap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<cr>')
-- Renames all references to the symbol under the cursor
bufmap('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<cr>')
-- Selects a code action available at the current cursor position
bufmap('n', '<F4>', '<cmd>lua vim.lsp.buf.code_action()<cr>')
bufmap('x', '<F4>', '<cmd>lua vim.lsp.buf.range_code_action()<cr>')
-- Show diagnostics in a floating window
bufmap('n', 'gl', '<cmd>lua vim.diagnostic.open_float()<cr>')
-- Move to the previous diagnostic
bufmap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<cr>')
-- Move to the next diagnostic
bufmap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<cr>')
end
})
nvim_lsp.diagnosticls.setup { nvim_lsp.diagnosticls.setup {
on_attach = on_attach; filetypes = { 'javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'css', 'scss', 'markdown', 'pandoc' },
filetypes = { 'javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'css', 'scss', 'markdown', 'pandoc' }, init_options = {
init_options = { linters = {
linters = { eslint = {
eslint = { command = 'eslint',
command = 'eslint', rootPatterns = { '.git' },
rootPatterns = { '.git' }, debounce = 100,
debounce = 100, args = { '--stdin', '--stdin-filename', '%filepath', '--format', 'json' },
args = { '--stdin', '--stdin-filename', '%filepath', '--format', 'json' }, sourceName = 'eslint',
sourceName = 'eslint', parseJson = {
parseJson = { errorsRoot = '[0].messages',
errorsRoot = '[0].messages', line = 'line',
line = 'line', column = 'column',
column = 'column', endLine = 'endLine',
endLine = 'endLine', endColumn = 'endColumn',
endColumn = 'endColumn', message = '[eslint] ${message} [${ruleId}]',
message = '[eslint] ${message} [${ruleId}]', security = 'severity'
security = 'severity'
},
securities = {
[2] = 'error',
[1] = 'warning'
}
}, },
markdownlint = { securities = {
command = 'markdownlint', [2] = 'error',
rootPatterns = { '.git' }, [1] = 'warning'
isStderr = true, }
debounce = 100, },
args = { '--stdin' }, markdownlint = {
offsetLine = 0, command = 'markdownlint',
offsetColumn = 0, rootPatterns = { '.git' },
sourceName = 'markdownlint', isStderr = true,
securities = { debounce = 100,
undefined = 'hint' args = { '--stdin' },
}, offsetLine = 0,
formatLines = 1, offsetColumn = 0,
formatPattern = { sourceName = 'markdownlint',
'^.*:(\\d+)\\s+(.*)$', securities = {
{ undefined = 'hint'
line = 1, },
column = -1, formatLines = 1,
message = 2, formatPattern = {
} '^.*:(\\d+)\\s+(.*)$',
{
line = 1,
column = -1,
message = 2,
} }
} }
},
filetypes = {
javascript = 'eslint',
javascriptreact = 'eslint',
typescript = 'eslint',
typescriptreact = 'eslint',
markdown = 'markdownlint',
pandoc = 'markdownlint'
},
formatters = {
prettier = {
command = 'prettier',
args = { '--stdin-filepath', '%filename' }
}
},
formatFiletypes = {
css = 'prettier',
javascript = 'prettier',
javascriptreact = 'prettier',
json = 'prettier',
scss = 'prettier',
typescript = 'prettier',
typescriptreact = 'prettier'
} }
},
filetypes = {
javascript = 'eslint',
javascriptreact = 'eslint',
typescript = 'eslint',
typescriptreact = 'eslint',
markdown = 'markdownlint',
pandoc = 'markdownlint'
},
formatters = {
prettier = {
command = 'prettier',
args = { '--stdin-filepath', '%filename' }
}
},
formatFiletypes = {
css = 'prettier',
javascript = 'prettier',
javascriptreact = 'prettier',
json = 'prettier',
scss = 'prettier',
typescript = 'prettier',
typescriptreact = 'prettier'
} }
}
} }
nvim_lsp.elmls.setup{ nvim_lsp.elmls.setup {
on_attach = on_attach;
} }
nvim_lsp.tsserver.setup { nvim_lsp.tsserver.setup {
on_attach = function(client)
-- Avoid conflict with prettier and eslint
client.resolved_capabilities.document_formatting = false
on_attach(client)
end
} }
nvim_lsp.elixirls.setup{ nvim_lsp.elixirls.setup {
cmd = { "elixir-ls" }; cmd = { "elixir-ls" };
on_attach = on_attach;
} }
nvim_lsp.rnix.setup{ nvim_lsp.rnix.setup {
cmd = { "@rnix_lsp@/bin/rnix-lsp" }; cmd = { "@rnix_lsp@/bin/rnix-lsp" };
on_attach = on_attach;
}
nvim_lsp.rust_analyzer.setup{
on_attach = on_attach;
} }
nvim_lsp.rust_analyzer.setup {}
nvim_lsp.sumneko_lua.setup{ nvim_lsp.sumneko_lua.setup {
cmd = { "@lua_ls@/bin/lua-language-server" }; cmd = { "@lua_ls@/bin/lua-language-server" };
on_attach = on_attach; single_file_support = true,
flags = {
debounce_text_changes = 150,
},
settings = { settings = {
Lua = { Lua = {
diagnostics = { diagnostics = {
globals = { 'vim' } globals = { 'vim' }
} }
} }
}; };
} }
nvim_lsp.texlab.setup{ nvim_lsp.texlab.setup {}
on_attach = on_attach;
}