mirror of
https://github.com/zoriya/dotfiles.git
synced 2026-08-15 18:43:47 +00:00
Adding nvim completion
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
local cmp_status_ok, cmp = pcall(require, "cmp")
|
||||
if not cmp_status_ok then
|
||||
return
|
||||
end
|
||||
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
require('luasnip').lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
mapping = {
|
||||
["<C-k>"] = cmp.mapping.select_prev_item(),
|
||||
["<C-j>"] = cmp.mapping.select_next_item(),
|
||||
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
|
||||
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
|
||||
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
|
||||
['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
|
||||
['<C-e>'] = cmp.mapping({
|
||||
i = cmp.mapping.abort(),
|
||||
c = cmp.mapping.close(),
|
||||
}),
|
||||
['<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" },
|
||||
{ name = "path" },
|
||||
})
|
||||
})
|
||||
|
||||
cmp.setup.cmdline('/', {
|
||||
sources = {
|
||||
{ name = 'buffer' }
|
||||
}
|
||||
})
|
||||
|
||||
cmp.setup.cmdline(':', {
|
||||
sources = cmp.config.sources({
|
||||
{ name = 'path' }
|
||||
}, {
|
||||
{ name = 'cmdline' }
|
||||
})
|
||||
})
|
||||
@@ -1,7 +1,76 @@
|
||||
local M = {}
|
||||
|
||||
local on_attach = function(client, bufnr)
|
||||
local wk = require("which-key")
|
||||
M.icons = {
|
||||
Class = " ",
|
||||
Color = " ",
|
||||
Constant = " ",
|
||||
Constructor = " ",
|
||||
Enum = "了 ",
|
||||
EnumMember = " ",
|
||||
Field = " ",
|
||||
File = " ",
|
||||
Folder = " ",
|
||||
Function = " ",
|
||||
Interface = "ﰮ ",
|
||||
Keyword = " ",
|
||||
Method = "ƒ ",
|
||||
Module = " ",
|
||||
Property = " ",
|
||||
Snippet = " ",
|
||||
Struct = " ",
|
||||
Text = " ",
|
||||
Unit = " ",
|
||||
Value = " ",
|
||||
Variable = " ",
|
||||
}
|
||||
|
||||
M.setup = function()
|
||||
local signs = {
|
||||
{ name = "DiagnosticSignError", text = "" },
|
||||
{ name = "DiagnosticSignWarn", text = "" },
|
||||
{ name = "DiagnosticSignInfo", text = "" },
|
||||
{ name = "DiagnosticSignHint", text = "" },
|
||||
}
|
||||
for _, sign in ipairs(signs) do
|
||||
vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" })
|
||||
end
|
||||
|
||||
vim.diagnostic.config({
|
||||
virtual_text = false,
|
||||
update_in_insert = true,
|
||||
})
|
||||
|
||||
local kinds = vim.lsp.protocol.CompletionItemKind
|
||||
for i, kind in ipairs(kinds) do
|
||||
kinds[i] = M.icons[kind] or kind
|
||||
end
|
||||
end
|
||||
|
||||
local function lsp_highlight_document(client)
|
||||
if client.resolved_capabilities.document_highlight then
|
||||
vim.cmd [[
|
||||
augroup lsp_document_highlight
|
||||
autocmd! * <buffer>
|
||||
autocmd! CursorHold <buffer> lua vim.lsp.buf.document_highlight()
|
||||
autocmd! CursorMoved <buffer> lua vim.lsp.buf.clear_references()
|
||||
augroup END
|
||||
]]
|
||||
end
|
||||
end
|
||||
|
||||
local wk = require("which-key")
|
||||
wk.register({
|
||||
["[d"] = { '<cmd>lua vim.diagnostic.goto_prev()<CR>', "Prev diagnostic" },
|
||||
["]d"] = { '<cmd>lua vim.diagnostic.goto_next()<CR>', "Next diagnostic" },
|
||||
gl = { "<cmd>lua vim.diagnostic.open_float()<CR>", "See diagnostics" },
|
||||
["<leader>l"] = {
|
||||
name = "LSP",
|
||||
i = { "<cmd>LspInfo<cr>", "Info" },
|
||||
I = { "<cmd>LspInstallInfo<cr>", "Installer Info" },
|
||||
},
|
||||
})
|
||||
|
||||
local lsp_keymaps = function(bufnr)
|
||||
wk.register({
|
||||
g = {
|
||||
D = { '<cmd>lua vim.lsp.buf.declaration()<CR>', "Go to declaration" },
|
||||
@@ -12,7 +81,6 @@ local on_attach = function(client, bufnr)
|
||||
K = { '<cmd>lua vim.lsp.buf.hover()<CR>', "See LSP tooltip" },
|
||||
["<C-k>"] = { '<cmd>lua vim.lsp.buf.signature_help()<CR>', "See signature help" },
|
||||
["<leader>l"] = {
|
||||
name = "LSP",
|
||||
r = { '<cmd>lua vim.lsp.buf.rename()<CR>', "Rename" },
|
||||
a = { '<cmd>lua vim.lsp.buf.code_action()<CR>', "Code action" },
|
||||
f = { '<cmd>lua vim.lsp.buf.formatting()<CR>', "Format" },
|
||||
@@ -24,6 +92,17 @@ end
|
||||
|
||||
M.on_attach = function(client, bufnr)
|
||||
lsp_keymaps(bufnr)
|
||||
lsp_highlight_document(client)
|
||||
end
|
||||
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
|
||||
local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
|
||||
if not status_ok then
|
||||
return M
|
||||
end
|
||||
|
||||
M.capabilities = cmp_nvim_lsp.update_capabilities(capabilities)
|
||||
|
||||
|
||||
return M
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
require "lsp.lsp-install"
|
||||
require("lsp.handlers").setup()
|
||||
require "lsp.cmp"
|
||||
|
||||
|
||||
@@ -56,6 +56,14 @@ return packer.startup(function(use)
|
||||
'neovim/nvim-lspconfig',
|
||||
'williamboman/nvim-lsp-installer',
|
||||
}
|
||||
use {
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
"hrsh7th/cmp-buffer",
|
||||
"hrsh7th/cmp-path",
|
||||
"hrsh7th/cmp-cmdline",
|
||||
"hrsh7th/nvim-cmp",
|
||||
"L3MON4D3/LuaSnip",
|
||||
}
|
||||
|
||||
if PACKER_BOOTSTRAP then
|
||||
require("packer").sync()
|
||||
|
||||
Reference in New Issue
Block a user