mirror of
https://github.com/nmasur/dotfiles
synced 2024-11-23 01:05:38 +00:00
lsp and completion tweaks
This commit is contained in:
parent
df6ac12204
commit
e1ac175333
@ -35,7 +35,7 @@
|
|||||||
# Always run packer.nvim sync
|
# Always run packer.nvim sync
|
||||||
home.activation.nvimPackerSync =
|
home.activation.nvimPackerSync =
|
||||||
config.home-manager.users.${config.user}.lib.dag.entryAfter
|
config.home-manager.users.${config.user}.lib.dag.entryAfter
|
||||||
[ "writeBoundary" ] ''
|
[ "onFilesChange" ] ''
|
||||||
$DRY_RUN_CMD nvim +PackerSync +qa
|
$DRY_RUN_CMD nvim +PackerSync +qa
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ key("n", "gr", telescope.lsp_references, { silent = true })
|
|||||||
key("n", "<Leader>R", vim.lsp.buf.rename, { 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_next, { silent = true })
|
||||||
key("n", "[e", vim.diagnostic.goto_prev, { 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 })
|
key("n", "<Leader>E", vim.lsp.buf.code_action, { silent = true })
|
||||||
|
|
||||||
-- File commands
|
-- File commands
|
||||||
|
@ -21,11 +21,15 @@ M.packer = function(use)
|
|||||||
config = function()
|
config = function()
|
||||||
local cmp = require("cmp")
|
local cmp = require("cmp")
|
||||||
cmp.setup({
|
cmp.setup({
|
||||||
|
|
||||||
|
-- Setup snippet completion
|
||||||
snippet = {
|
snippet = {
|
||||||
expand = function(args)
|
expand = function(args)
|
||||||
require("luasnip").lsp_expand(args.body)
|
require("luasnip").lsp_expand(args.body)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
-- Setup completion keybinds
|
||||||
mapping = {
|
mapping = {
|
||||||
["<C-d>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }),
|
["<C-d>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }),
|
||||||
["<C-f>"] = 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
|
vim.cmd("stopinsert") --- Abort and leave insert mode
|
||||||
end,
|
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({
|
["<CR>"] = cmp.mapping.confirm({
|
||||||
behavior = cmp.ConfirmBehavior.Insert,
|
behavior = cmp.ConfirmBehavior.Insert,
|
||||||
select = true,
|
select = true,
|
||||||
@ -52,11 +54,13 @@ M.packer = function(use)
|
|||||||
end
|
end
|
||||||
end, { "i", "s" }),
|
end, { "i", "s" }),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
-- Setup completion engines
|
||||||
sources = {
|
sources = {
|
||||||
{ name = "nvim_lua" },
|
{ name = "nvim_lua" },
|
||||||
{ name = "nvim_lsp" },
|
{ name = "nvim_lsp" },
|
||||||
{ name = "path" },
|
|
||||||
{ name = "luasnip" },
|
{ name = "luasnip" },
|
||||||
|
{ name = "path" },
|
||||||
{ name = "buffer", keyword_length = 3, max_item_count = 10 },
|
{ name = "buffer", keyword_length = 3, max_item_count = 10 },
|
||||||
{
|
{
|
||||||
name = "rg",
|
name = "rg",
|
||||||
@ -65,6 +69,30 @@ M.packer = function(use)
|
|||||||
option = { additional_arguments = "--ignore-case" },
|
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 = {
|
experimental = {
|
||||||
native_menu = false, --- Use cmp menu instead of Vim menu
|
native_menu = false, --- Use cmp menu instead of Vim menu
|
||||||
ghost_text = true, --- Show preview auto-completion
|
ghost_text = true, --- Show preview auto-completion
|
||||||
|
@ -4,19 +4,32 @@
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
function on_path(program)
|
|
||||||
return vim.fn.executable(program) == 1
|
|
||||||
end
|
|
||||||
|
|
||||||
M.packer = function(use)
|
M.packer = function(use)
|
||||||
-- Language server engine
|
-- Language server engine
|
||||||
use({
|
use({
|
||||||
"neovim/nvim-lspconfig",
|
"neovim/nvim-lspconfig",
|
||||||
requires = { "hrsh7th/cmp-nvim-lsp" },
|
requires = { "hrsh7th/cmp-nvim-lsp" },
|
||||||
config = function()
|
config = function()
|
||||||
|
local function on_path(program)
|
||||||
|
return vim.fn.executable(program) == 1
|
||||||
|
end
|
||||||
|
|
||||||
local capabilities = require("cmp_nvim_lsp").update_capabilities(
|
local capabilities = require("cmp_nvim_lsp").update_capabilities(
|
||||||
vim.lsp.protocol.make_client_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
|
if on_path("rust-analyzer") then
|
||||||
require("lspconfig").rust_analyzer.setup({ capabilities = capabilities })
|
require("lspconfig").rust_analyzer.setup({ capabilities = capabilities })
|
||||||
end
|
end
|
||||||
@ -50,6 +63,10 @@ M.packer = function(use)
|
|||||||
"neovim/nvim-lspconfig",
|
"neovim/nvim-lspconfig",
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
|
local function on_path(program)
|
||||||
|
return vim.fn.executable(program) == 1
|
||||||
|
end
|
||||||
|
|
||||||
require("null-ls").setup({
|
require("null-ls").setup({
|
||||||
sources = {
|
sources = {
|
||||||
require("null-ls").builtins.formatting.stylua.with({
|
require("null-ls").builtins.formatting.stylua.with({
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
{ config, pkgs, ... }: {
|
{ config, pkgs, ... }: {
|
||||||
|
|
||||||
home-manager.users.${config.user}.home.packages = with pkgs;
|
home-manager.users.${config.user}.home.packages = with pkgs; [
|
||||||
[
|
stylua # Lua formatter
|
||||||
stylua # Lua formatter
|
sumneko-lua-language-server # Lua LSP
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user