Skip to content

Commit

Permalink
(nvim) wip: bunch of clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
emilford committed Dec 27, 2021
1 parent 64071a2 commit 0f53813
Showing 1 changed file with 82 additions and 109 deletions.
191 changes: 82 additions & 109 deletions .config/nvim/lua/em/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,140 +13,113 @@ local on_attach = function(client, bufnr)
local opts = { noremap=true, silent=true }

-- See `:help vim.lsp.*` for documentation on any of the below functions
buf_set_keymap("n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts)
buf_set_keymap("n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts)
buf_set_keymap("n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
buf_set_keymap("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
buf_set_keymap("n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
buf_set_keymap("n", "<space>wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>", opts)
buf_set_keymap("n", "<space>wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>", opts)
buf_set_keymap("n", "<space>wl", "<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>", opts)
buf_set_keymap("n", "<space>D", "<cmd>lua vim.lsp.buf.type_definition()<CR>", opts)
buf_set_keymap("n", "<space>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
buf_set_keymap("n", "<space>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts)
buf_set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
buf_set_keymap("n", "<space>e", "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>", opts)
buf_set_keymap("n", "[d", "<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", opts)
buf_set_keymap("n", "]d", "<cmd>lua vim.lsp.diagnostic.goto_next()<CR>", opts)
buf_set_keymap("n", "<space>q", "<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>", opts)
buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
buf_set_keymap("n", "gD", "<cmd>lua vim.lsp.buf.declaration()<cr>", opts)
buf_set_keymap("n", "gd", "<cmd>lua vim.lsp.buf.definition()<cr>", opts)
buf_set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<cr>", opts)
buf_set_keymap("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<cr>", opts)
buf_set_keymap("n", "K", "<cmd>lua vim.lsp.buf.hover()<cr>", opts)
buf_set_keymap("n", "<c-k>", "<cmd>lua vim.lsp.buf.signature_help()<cr>", opts)
buf_set_keymap("n", "<space>wl", "<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<cr>", opts)
buf_set_keymap("n", "<space>D", "<cmd>lua vim.lsp.buf.type_definition()<cr>", opts)
buf_set_keymap("n", "<space>rn", "<cmd>lua vim.lsp.buf.rename()<cr>", opts)
buf_set_keymap("n", "<space>ca", "<cmd>lua vim.lsp.buf.code_action()<cr>", opts)
buf_set_keymap("n", "<space>e", "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<cr>", opts)
buf_set_keymap("n", "<space>q", "<cmd>lua vim.lsp.diagnostic.set_loclist()<cr>", opts)
buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<cr>", opts)
buf_set_keymap("n", "[d", "<cmd>lua vim.lsp.diagnostic.goto_prev()<cr>", opts)
buf_set_keymap("n", "]d", "<cmd>lua vim.lsp.diagnostic.goto_next()<cr>", opts)

require "lsp_signature".on_attach()
end

-- -- Use a loop to conveniently call "setup" on multiple servers and
-- -- map buffer local keybindings when the language server attaches
-- local servers = { "tsserver" }
-- for _, lsp in ipairs(servers) do
-- nvim_lsp[lsp].setup {
-- on_attach = on_attach,
-- flags = {
-- debounce_text_changes = 150,
-- }
-- }
-- end

local lsp_installer = require("nvim-lsp-installer")

-- Register a handler that will be called for all installed servers.
-- Alternatively, you may also register handlers on specific server instances instead (see example below).
lsp_installer.on_server_ready(function(server)
local opts = {
on_attach = on_attach,
flags = {
debounce_text_changes = 150,
},
capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities())
}
local opts = {
on_attach = on_attach,
flags = {
debounce_text_changes = 150,
},
capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities())
}

-- (optional) Customize the options passed to the server
-- if server.name == "tsserver" then
-- opts.root_dir = function() ... end
-- end
-- (optional) Customize the options passed to the server
-- if server.name == "tsserver" then
-- opts.root_dir = function() ... end
-- end

-- This setup() function is exactly the same as lspconfig"s setup function.
-- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
server:setup(opts)
-- This setup() function is exactly the same as lspconfig"s setup function.
-- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
server:setup(opts)
end)

local cmp = require"cmp"

cmp.setup({
snippet = {
expand = function(args)
vim.fn["UltiSnips#Anon"](args.body)
end,
},
mapping = {
["<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 }),
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
--["<C-y>"] = cmp.mapping.complete(),
-- ["<C-e>"] = cmp.mapping.close(),
["<C-y>"] = cmp.mapping.confirm({ select = true }),
cmp.setup({
snippet = {
expand = function(args)
vim.fn["UltiSnips#Anon"](args.body)
end,
},
mapping = {
["<c-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }),
["<c-f>"] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }),
["<c-u>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }),
["<c-d>"] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }),
["<C-e>"] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
}),
["<cr>"] = cmp.mapping.confirm({ select = true }),
["<c-y>"] = cmp.mapping.confirm({ select = true }),
},
sources = cmp.config.sources(
{
{ name = "nvim_lsp" },
{ name = "ultisnips" },
{ name = "cmp_git" },
},
sources = cmp.config.sources(
{
{ name = "nvim_lsp" },
{ name = "ultisnips" },
{ name = "cmp_git" },
},
{
{ name = "buffer" },
}
),
formatting = {
format = require("lspkind").cmp_format({
with_text = true,
preset = "codicons",
menu = ({
buffer = "[buffer]",
nvim_lsp = "[lsp]",
nvim_lua = "[lua]",
ultisnips = "[ultisnips]"
})
{
{ name = "buffer" },
}
),
formatting = {
format = require("lspkind").cmp_format({
with_text = true,
preset = "codicons",
menu = ({
buffer = "[buffer]",
nvim_lsp = "[lsp]",
nvim_lua = "[lua]",
ultisnips = "[ultisnips]"
})
},
})
})
},
})

-- Use buffer source for `/` (if you enabled `native_menu`, this won"t work anymore).
cmp.setup.cmdline("/", {
sources = {
{ name = "buffer" }
}
})
-- Use buffer source for `/` (if you enabled `native_menu`, this won"t work anymore).
cmp.setup.cmdline("/", {
sources = {
{ name = "buffer" }
}
})

-- Use cmdline & path source for ":" (if you enabled `native_menu`, this won"t work anymore).
cmp.setup.cmdline(":", {
sources = cmp.config.sources({
{ name = "path" }
}, {
{ name = "cmdline" }
})
-- Use cmdline & path source for ":" (if you enabled `native_menu`, this won"t work anymore).
cmp.setup.cmdline(":", {
sources = cmp.config.sources({
{ name = "path" }
}, {
{ name = "cmdline" }
})

-- Setup lspconfig.
-- local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities())
-- -- Replace <YOUR_LSP_SERVER> with each lsp server you"ve enabled.
-- require("lspconfig")["<YOUR_LSP_SERVER>"].setup {
-- capabilities = capabilities
-- }
})

vim.diagnostic.config({
virtual_text = false,
-- signs = true,
-- underline = true,
-- update_in_insert = false,
severity_sort = true, --show higher severities first in signs and virtual text
})

local signs = { Error = "", Warn = "", Hint = "", Info = "" }
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
Expand Down

0 comments on commit 0f53813

Please sign in to comment.