Browse Source

Wed 28 Dec 2022 18:53:00 ACDT

master
Tovi Jaeschke-Rogers 2 years ago
parent
commit
9d2e828b21
2 changed files with 102 additions and 4 deletions
  1. +101
    -0
      .config/nvim/lua/config/lsp.lua
  2. +1
    -4
      update.sh

+ 101
- 0
.config/nvim/lua/config/lsp.lua View File

@ -0,0 +1,101 @@
local lsp = require('lsp-zero')
lsp.preset('recommended')
local luasnip = require("luasnip")
lsp.ensure_installed({
'tsserver',
'eslint',
'sumneko_lua',
'gopls'
})
local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match "%s" == nil
end
local cmp = require('cmp')
-- local cmp_select = {behavior = cmp.SelectBehavior.Select}
local cmp_mappings = lsp.defaults.cmp_mappings({
["<C-k>"] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "c" }),
["<C-j>"] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "c" }),
["<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-e>"] = cmp.mapping { i = cmp.mapping.close(), c = cmp.mapping.close() },
["<CR>"] = cmp.mapping {
i = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = false },
c = function(fallback)
if cmp.visible() then
cmp.confirm { behavior = cmp.ConfirmBehavior.Replace, select = false }
else
fallback()
end
end,
},
["<Tab>"] = cmp.mapping(
function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end,
{
"i",
"s",
"c",
}),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end,
{
"i",
"s",
"c",
}),
})
lsp.setup_nvim_cmp({
mapping = cmp_mappings,
window = {
documentation = {
border = { "", "", "", "", "", "", "", "" },
winhighlight = "NormalFloat:NormalFloat,FloatBorder:TelescopeBorder",
},
},
})
lsp.on_attach(function(client, bufnr)
local opts = {buffer = bufnr, remap = false}
-- Key mappings
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
vim.keymap.set("n", "[e", function () vim.diagnostic.goto_prev({severity = vim.diagnostic.severity.ERROR}) end, opts)
vim.keymap.set("n", "]e", function () vim.diagnostic.goto_next({severity = vim.diagnostic.severity.ERROR}) end, opts)
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts)
vim.keymap.set("n", "<leader>ka", vim.lsp.buf.code_action, opts)
vim.keymap.set("n", "<leader>of", vim.diagnostic.open_float, opts)
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
-- vim.keymap.set("n", "gr", function() vim.lsp.buf.references({ includeDeclaration = false }) end, opts)
vim.keymap.set("n", "gh", vim.lsp.buf.signature_help, opts)
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
vim.keymap.set("n", "gT", vim.lsp.buf.type_definition, opts)
end)
lsp.setup()

+ 1
- 4
update.sh View File

@ -12,7 +12,6 @@ declare -a FILES=(
.config/nvim/lua/packer-plugins.lua
.config/nvim/lua/helper/toggle-tab-width.lua
.config/nvim/lua/config/tmux.lua
.config/nvim/lua/config/barbar.lua
.config/nvim/lua/config/treesitter.lua
.config/nvim/lua/config/php-doc.lua
.config/nvim/lua/config/go.lua
@ -24,9 +23,7 @@ declare -a FILES=(
.config/nvim/lua/config/general/init.lua
.config/nvim/lua/config/gitsigns.lua
.config/nvim/lua/config/luasnip.lua
.config/nvim/lua/config/lsp/init.lua
.config/nvim/lua/config/lsp/keymaps.lua
.config/nvim/lua/config/lsp/installer.lua
.config/nvim/lua/config/lsp.lua
.config/nvim/lua/config/nvim-neo-tree.lua
.config/nvim/lua/config/lualine.lua
.config/nvim/lua/config/telescope.lua


Loading…
Cancel
Save