lsp and completion tweaks

This commit is contained in:
Noah Masur 2022-07-11 02:47:54 +00:00
parent df6ac12204
commit e1ac175333
5 changed files with 58 additions and 13 deletions

View File

@ -35,7 +35,7 @@
# Always run packer.nvim sync
home.activation.nvimPackerSync =
config.home-manager.users.${config.user}.lib.dag.entryAfter
[ "writeBoundary" ] ''
[ "onFilesChange" ] ''
$DRY_RUN_CMD nvim +PackerSync +qa
'';

View File

@ -74,7 +74,7 @@ key("n", "gr", telescope.lsp_references, { silent = true })
key("n", "<Leader>R", vim.lsp.buf.rename, { silent = true })
key("n", "]e", vim.diagnostic.goto_next, { silent = true })
key("n", "[e", vim.diagnostic.goto_prev, { silent = true })
key("n", "<Leader>e", vim.lsp.diagnostic.show_line_diagnostics, { silent = true })
key("n", "<Leader>e", vim.diagnostic.open_float, { silent = true })
key("n", "<Leader>E", vim.lsp.buf.code_action, { silent = true })
-- File commands

View File

@ -21,11 +21,15 @@ M.packer = function(use)
config = function()
local cmp = require("cmp")
cmp.setup({
-- Setup snippet completion
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
-- Setup completion keybinds
mapping = {
["<C-d>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }),
["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }),
@ -36,8 +40,6 @@ M.packer = function(use)
})
vim.cmd("stopinsert") --- Abort and leave insert mode
end,
-- ['<Tab>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 's' }),
-- ['<S-Tab>'] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 's' }),
["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert,
select = true,
@ -52,11 +54,13 @@ M.packer = function(use)
end
end, { "i", "s" }),
},
-- Setup completion engines
sources = {
{ name = "nvim_lua" },
{ name = "nvim_lsp" },
{ name = "path" },
{ name = "luasnip" },
{ name = "path" },
{ name = "buffer", keyword_length = 3, max_item_count = 10 },
{
name = "rg",
@ -65,6 +69,30 @@ M.packer = function(use)
option = { additional_arguments = "--ignore-case" },
},
},
-- Visual presentation
formatting = {
fields = { "abbr", "menu" },
format = function(entry, vim_item)
vim_item.menu = ({
luasnip = "[Snippet]",
buffer = "[Buffer]",
path = "[Path]",
rg = "[Grep]",
nvim_lsp = "[LSP]",
nvim_lua = "[Lua]",
})[entry.source.name]
return vim_item
end,
},
-- Docs
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
-- Extra features
experimental = {
native_menu = false, --- Use cmp menu instead of Vim menu
ghost_text = true, --- Show preview auto-completion

View File

@ -4,19 +4,32 @@
local M = {}
function on_path(program)
return vim.fn.executable(program) == 1
end
M.packer = function(use)
-- Language server engine
use({
"neovim/nvim-lspconfig",
requires = { "hrsh7th/cmp-nvim-lsp" },
config = function()
local function on_path(program)
return vim.fn.executable(program) == 1
end
local capabilities = require("cmp_nvim_lsp").update_capabilities(
vim.lsp.protocol.make_client_capabilities()
)
if on_path("lua-language-server") then
require("lspconfig").sumneko_lua.setup({
capabilities = capabilities,
-- Turn off errors for vim global variable
settings = {
Lua = {
diagnostics = {
globals = { "vim" },
},
},
},
})
end
if on_path("rust-analyzer") then
require("lspconfig").rust_analyzer.setup({ capabilities = capabilities })
end
@ -50,6 +63,10 @@ M.packer = function(use)
"neovim/nvim-lspconfig",
},
config = function()
local function on_path(program)
return vim.fn.executable(program) == 1
end
require("null-ls").setup({
sources = {
require("null-ls").builtins.formatting.stylua.with({

View File

@ -1,8 +1,8 @@
{ config, pkgs, ... }: {
home-manager.users.${config.user}.home.packages = with pkgs;
[
stylua # Lua formatter
];
home-manager.users.${config.user}.home.packages = with pkgs; [
stylua # Lua formatter
sumneko-lua-language-server # Lua LSP
];
}