From f06f28643c6449377af7ebf9c8ef5b780858f8a0 Mon Sep 17 00:00:00 2001 From: pr0c3550r Date: Sun, 22 Jan 2023 17:42:07 +0100 Subject: [PATCH] added lsp-functionality with custom colors --- nvim/.config/nvim/after/plugin/lspconfig.lua | 88 ++++++++++++++++++++ nvim/.config/nvim/after/plugin/nvim-cmp.lua | 1 - nvim/.config/nvim/lua/pr073c70r/colors.lua | 10 ++- nvim/.config/nvim/lua/pr073c70r/packer.lua | 7 +- 4 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 nvim/.config/nvim/after/plugin/lspconfig.lua diff --git a/nvim/.config/nvim/after/plugin/lspconfig.lua b/nvim/.config/nvim/after/plugin/lspconfig.lua new file mode 100644 index 0000000..b5a6cb1 --- /dev/null +++ b/nvim/.config/nvim/after/plugin/lspconfig.lua @@ -0,0 +1,88 @@ +local opts = { noremap = true, silent = true } +vim.keymap.set('n', 'e', vim.diagnostic.open_float, 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', 'q', vim.diagnostic.setloclist, opts) + +local on_attach = function(client, bufnr) + -- Enable completion triggered by + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local bufopts = { noremap = true, silent = true, buffer = bufnr } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, bufopts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, bufopts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', 'fm', function() vim.lsp.buf.format { async = true } end, bufopts) +end + +local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } +for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl }) +end + + +local border = { + { "╭", "FloatBorder" }, + { "─", "FloatBorder" }, + { "╮", "FloatBorder" }, + { "│", "FloatBorder" }, + { "╯", "FloatBorder" }, + { "─", "FloatBorder" }, + { "╰", "FloatBorder" }, + { "│", "FloatBorder" }, +} + +vim.diagnostic.config({ + float = { border = border }, + virtual_text = { + prefix = '▎', -- Could be '●', '■', 'x' + } + +}) + +-- LSP settings (for overriding per client) +local handlers = { + ["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = border }), + ["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = border }), +} + +require("mason").setup({ + ui = { + border = "rounded", + icons = { + package_installed = "✔", + package_pending = "➜", + package_uninstalled = "✘" + } + } +}) + +require("mason-lspconfig").setup({ + ensure_installed = { "sumneko_lua" } +}) + +require("mason-lspconfig").setup_handlers { + -- The first entry (without a key) will be the default handler + -- and will be called for each installed server that doesn't have + -- a dedicated handler. + function(server_name) -- default handler (optional) + require("lspconfig")[server_name].setup { + on_attach = on_attach, + handlers = handlers, + } + end, +} diff --git a/nvim/.config/nvim/after/plugin/nvim-cmp.lua b/nvim/.config/nvim/after/plugin/nvim-cmp.lua index 132d04f..99c9e19 100644 --- a/nvim/.config/nvim/after/plugin/nvim-cmp.lua +++ b/nvim/.config/nvim/after/plugin/nvim-cmp.lua @@ -125,7 +125,6 @@ cmp.setup({ }, { }) }) - -- Set configuration for specific filetype. cmp.setup.filetype('gitcommit', { sources = cmp.config.sources({ diff --git a/nvim/.config/nvim/lua/pr073c70r/colors.lua b/nvim/.config/nvim/lua/pr073c70r/colors.lua index 433fee7..f0d6951 100644 --- a/nvim/.config/nvim/lua/pr073c70r/colors.lua +++ b/nvim/.config/nvim/lua/pr073c70r/colors.lua @@ -1,5 +1,4 @@ -- setting colors - -- everforest vim.api.nvim_set_var("everforest_background", "hard") vim.api.nvim_set_var("everforest_transparent_background", "1") @@ -40,6 +39,15 @@ vim.api.nvim_set_hl(0, "VertSplit", {bg = "none", fg = "#1d2021"}) vim.api.nvim_set_hl(0, "Cursorline", {bg = "#141617"}) vim.api.nvim_set_hl(0, "CursorLineNr", {bold = true, bg = "#141617", fg = "#d8a657"}) +-- color of Floats and FloatBorders +vim.api.nvim_set_hl(0, "NormalFloat", {bg = none, fg = none }) +vim.api.nvim_set_hl(0, "FloatBorder", {bg = none, fg = "#d4be98"}) + +vim.api.nvim_set_hl(0, "DiagnosticFloatingWarn", {bg = none, fg = "#d8a657"}) +vim.api.nvim_set_hl(0, "DiagnosticFloatingError", {bg = none, fg = "#ea6962"}) +vim.api.nvim_set_hl(0, "DiagnosticFloatingHint", {bg = none, fg = "#a9b665"}) +vim.api.nvim_set_hl(0, "DiagnosticFloatingInfo", {bg = none, fg = "#d4be98"}) + -- transparent background in active, non active and at the end of buffer for colorschemes which does not support such options -- vim.api.nvim_set_hl(0, "Normal", { bg = "none" }) -- vim.api.nvim_set_hl(0, "NormalNC", { bg = "none" }) diff --git a/nvim/.config/nvim/lua/pr073c70r/packer.lua b/nvim/.config/nvim/lua/pr073c70r/packer.lua index 79455e1..527a207 100644 --- a/nvim/.config/nvim/lua/pr073c70r/packer.lua +++ b/nvim/.config/nvim/lua/pr073c70r/packer.lua @@ -28,9 +28,12 @@ return require('packer').startup(function(use) use 'lukas-reineke/indent-blankline.nvim' -- LSP - + use { + {'williamboman/mason.nvim'}, + {'williamboman/mason-lspconfig.nvim'}, + {'neovim/nvim-lspconfig'}, + } -- Autocomplete - use 'neovim/nvim-lspconfig' use { 'hrsh7th/nvim-cmp', requires = {