From b8de671bbb42921bde88f1f404401ff78d905d87 Mon Sep 17 00:00:00 2001 From: Benjamin Kyd Date: Fri, 17 Mar 2023 16:55:52 +0000 Subject: [PATCH] mason is a bit broken but LSP a lot better --- common/.config/nvim/lua/lsp-general.lua | 128 ++++++---- .../.config/nvim/lua/plugin-config/feline.lua | 233 ++++++++++++++++++ .../nvim/lua/plugin-config/nvim-cmp.lua | 54 ---- common/.config/nvim/lua/plugins.lua | 46 ++-- 4 files changed, 336 insertions(+), 125 deletions(-) create mode 100644 common/.config/nvim/lua/plugin-config/feline.lua delete mode 100644 common/.config/nvim/lua/plugin-config/nvim-cmp.lua diff --git a/common/.config/nvim/lua/lsp-general.lua b/common/.config/nvim/lua/lsp-general.lua index b189ef2..a9aa996 100644 --- a/common/.config/nvim/lua/lsp-general.lua +++ b/common/.config/nvim/lua/lsp-general.lua @@ -1,63 +1,90 @@ -local lspconfig = require('lspconfig'); +local lsp = require('lsp-zero') +local cmp = require ('cmp') +lsp.preset("recommended") + +lsp.ensure_installed({ + 'tsserver', + 'clangd', +}) + +-- Fix Undefined global 'vim' +lsp.configure('lua-language-server', { + settings = { + Lua = { + diagnostics = { + globals = { 'vim' } + } + } + } +}) + +local cmp = require('cmp') +local cmp_select = { behavior = cmp.SelectBehavior.Select } +local cmp_mappings = lsp.defaults.cmp_mappings({ + [""] = cmp.mapping.select_next_item(cmp_select), + [""] = cmp.mapping.select_prev_item(cmp_select), + [""] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }), +}) + +lsp.setup_nvim_cmp({ + mapping = cmp_mappings, +}) + + +cmp.setup.cmdline('/', { + sources = { + { name = 'buffer' } + } +}) + +cmp.setup.cmdline(':', { + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }) +}) + +lsp.set_preferences({ + suggest_lsp_servers = false, + sign_icons = { + error = '', + warn = '', + hint = '', + info = '' + } +}) + require('mason').setup() require('mason-lspconfig').setup({ - ensure_installed = { 'clangd' } + ensure_installed = { 'clangd'} }) -local opts = { noremap = true, silent = true, buffer = bufnr } -vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.definition()', opts) -vim.keymap.set('n', 'gT', 'lua vim.lsp.buf.type_definition()', opts) -vim.keymap.set('n', 'gI', 'lua vim.lsp.buf.implementation()', opts) -vim.keymap.set('n', 'gR', 'lua vim.lsp.buf.references()', opts) --- Glance LSP -vim.keymap.set('n', 'gd', 'Glance definitions', opts) -vim.keymap.set('n', 'gt', 'Glance type_definitions', opts) -vim.keymap.set('n', 'gi', 'Glance implementations', opts) -vim.keymap.set('n', 'gr', 'Glance references', opts) -local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()) - -local on_attatch = function(_, bufnr) +lsp.on_attach(function(_, bufnr) vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') -end + local opts = { noremap = true, silent = true, buffer = bufnr } + vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.definition()', opts) + vim.keymap.set('n', 'gT', 'lua vim.lsp.buf.type_definition()', opts) + vim.keymap.set('n', 'gI', 'lua vim.lsp.buf.implementation()', opts) + vim.keymap.set('n', 'gR', 'lua vim.lsp.buf.references()', opts) + -- Glance LSP + vim.keymap.set('n', 'gd', 'Glance definitions', opts) + vim.keymap.set('n', 'gt', 'Glance type_definitions', opts) + vim.keymap.set('n', 'gi', 'Glance implementations', opts) + vim.keymap.set('n', 'gr', 'Glance references', opts) +end) -require('mason-lspconfig').setup_handlers({ - function(server) - lspconfig[server].setup({ - on_attatch = on_attatch, - capabilities = capabilities, - }) - end, +lsp.setup() + +vim.diagnostic.config({ + virtual_text = true }) -require('rust-tools').setup { - server = { - on_attatch = on_attatch, - capabilities = capabilities, - } -} - --- Specific LSP -lspconfig.rust_analyzer.setup { - settings = { - ["rust-analyzer"] = { - diagnostics = { - enable = true, - disabled = {"unresolved-proc-macro"}, - enableExperimental = true, - }, - }, - }, -} - --- diagnostic symbols -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, numhl = hl }) -end - -- completion symbols vim.lsp.protocol.CompletionItemKind = { "  (Text) ", @@ -86,3 +113,4 @@ vim.lsp.protocol.CompletionItemKind = { "  (Operator)", "  (TypeParameter)" } + diff --git a/common/.config/nvim/lua/plugin-config/feline.lua b/common/.config/nvim/lua/plugin-config/feline.lua new file mode 100644 index 0000000..5eb487b --- /dev/null +++ b/common/.config/nvim/lua/plugin-config/feline.lua @@ -0,0 +1,233 @@ +local line_ok, feline = pcall(require, "feline") +if not line_ok then + return +end + +local one_monokai = { + fg = "#abb2bf", + bg = "#1e2024", + green = "#98c379", + yellow = "#e5c07b", + purple = "#c678dd", + orange = "#d19a66", + peanut = "#f6d5a4", + red = "#e06c75", + aqua = "#61afef", + darkblue = "#282c34", + dark_red = "#f75f5f", +} + +local vi_mode_colors = { + NORMAL = "green", + OP = "green", + INSERT = "yellow", + VISUAL = "purple", + LINES = "orange", + BLOCK = "dark_red", + REPLACE = "red", + COMMAND = "aqua", +} + +local c = { + vim_mode = { + provider = { + name = "vi_mode", + opts = { + show_mode_name = true, + -- padding = "center", -- Uncomment for extra padding. + }, + }, + hl = function() + return { + fg = require("feline.providers.vi_mode").get_mode_color(), + bg = "darkblue", + style = "bold", + name = "NeovimModeHLColor", + } + end, + left_sep = "block", + right_sep = "block", + }, + gitBranch = { + provider = "git_branch", + hl = { + fg = "peanut", + bg = "darkblue", + style = "bold", + }, + left_sep = "block", + right_sep = "block", + }, + gitDiffAdded = { + provider = "git_diff_added", + hl = { + fg = "green", + bg = "darkblue", + }, + left_sep = "block", + right_sep = "block", + }, + gitDiffRemoved = { + provider = "git_diff_removed", + hl = { + fg = "red", + bg = "darkblue", + }, + left_sep = "block", + right_sep = "block", + }, + gitDiffChanged = { + provider = "git_diff_changed", + hl = { + fg = "fg", + bg = "darkblue", + }, + left_sep = "block", + right_sep = "right_filled", + }, + separator = { + provider = "", + }, + fileinfo = { + provider = { + name = "file_info", + opts = { + type = "relative-short", + }, + }, + hl = { + style = "bold", + }, + left_sep = " ", + right_sep = " ", + }, + diagnostic_errors = { + provider = "diagnostic_errors", + hl = { + fg = "red", + }, + }, + diagnostic_warnings = { + provider = "diagnostic_warnings", + hl = { + fg = "yellow", + }, + }, + diagnostic_hints = { + provider = "diagnostic_hints", + hl = { + fg = "aqua", + }, + }, + diagnostic_info = { + provider = "diagnostic_info", + }, + lsp_client_names = { + provider = "lsp_client_names", + hl = { + fg = "purple", + bg = "darkblue", + style = "bold", + }, + left_sep = "left_filled", + right_sep = "block", + }, + file_type = { + provider = { + name = "file_type", + opts = { + filetype_icon = true, + case = "titlecase", + }, + }, + hl = { + fg = "red", + bg = "darkblue", + style = "bold", + }, + left_sep = "block", + right_sep = "block", + }, + file_encoding = { + provider = "file_encoding", + hl = { + fg = "orange", + bg = "darkblue", + style = "italic", + }, + left_sep = "block", + right_sep = "block", + }, + position = { + provider = "position", + hl = { + fg = "green", + bg = "darkblue", + style = "bold", + }, + left_sep = "block", + right_sep = "block", + }, + line_percentage = { + provider = "line_percentage", + hl = { + fg = "aqua", + bg = "darkblue", + style = "bold", + }, + left_sep = "block", + right_sep = "block", + }, + scroll_bar = { + provider = "scroll_bar", + hl = { + fg = "yellow", + style = "bold", + }, + }, +} + +local left = { + c.vim_mode, + c.gitBranch, + c.gitDiffAdded, + c.gitDiffRemoved, + c.gitDiffChanged, + c.separator, +} + +local middle = { + c.fileinfo, + c.diagnostic_errors, + c.diagnostic_warnings, + c.diagnostic_info, + c.diagnostic_hints, +} + +local right = { + c.lsp_client_names, + c.file_type, + c.file_encoding, + c.position, + c.line_percentage, + c.scroll_bar, +} + +local components = { + active = { + left, + middle, + right, + }, + inactive = { + left, + middle, + right, + }, +} + +feline.setup({ + components = components, + theme = one_monokai, + vi_mode_colors = vi_mode_colors, +}) diff --git a/common/.config/nvim/lua/plugin-config/nvim-cmp.lua b/common/.config/nvim/lua/plugin-config/nvim-cmp.lua deleted file mode 100644 index f8c2e65..0000000 --- a/common/.config/nvim/lua/plugin-config/nvim-cmp.lua +++ /dev/null @@ -1,54 +0,0 @@ -local cmp = require 'cmp' - -cmp.setup({ - snippet = { - expand = function(args) - vim.fn["vsnip#anonymous"](args.body) - end, - }, - mapping = { - [""] = cmp.mapping.select_prev_item(), - [""] = cmp.mapping.select_next_item(), - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.complete(), - [""] = cmp.mapping.close(), - [""] = cmp.mapping.confirm({ - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }), - [""] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "s" }), - [""] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "s" }), - }, - sources = { - { name = "nvim_lsp" }, - { name = "vsnip" }, - { name = "path" }, - { name = "buffer" }, - }, -}) - --- Set configuration for specific filetype. -cmp.setup.filetype('gitcommit', { - sources = cmp.config.sources({ - { name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it. - }, { - { 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' } - }) -}) diff --git a/common/.config/nvim/lua/plugins.lua b/common/.config/nvim/lua/plugins.lua index accf8bb..cb110a8 100644 --- a/common/.config/nvim/lua/plugins.lua +++ b/common/.config/nvim/lua/plugins.lua @@ -151,43 +151,47 @@ local packer = require('packer').startup(function(use) -- statusline use { - 'ojroques/nvim-hardline', + 'freddiehaddad/feline.nvim', config = function () - require('hardline').setup({}) + require('plugin-config/feline') end } + -- fancy notifications use 'rcarriga/nvim-notify' -- FUNCTIONAL CODING STUFF - -- lsp config use { - "williamboman/mason.nvim", + 'VonHeikemen/lsp-zero.nvim', + branch = 'v1.x', requires = { - "williamboman/mason-lspconfig.nvim", - "neovim/nvim-lspconfig", - 'simrat39/rust-tools.nvim', + -- LSP Support + {'neovim/nvim-lspconfig'}, + {'williamboman/mason.nvim'}, + {'williamboman/mason-lspconfig.nvim'}, + + -- Special LSP treatment + {'simrat39/rust-tools.nvim'}, + + -- Autocompletion + {'hrsh7th/nvim-cmp'}, + {'hrsh7th/cmp-nvim-lsp'}, + {'hrsh7th/cmp-nvim-lua'}, + {'hrsh7th/cmp-buffer'}, + {'hrsh7th/cmp-path'}, + {'hrsh7th/cmp-cmdline'}, + {'saadparwaiz1/cmp_luasnip'}, + + -- Snippets + {'L3MON4D3/LuaSnip'}, + {'rafamadriz/friendly-snippets'}, }, config = function () require('lsp-general') end } - -- for LSP autocompletion - use { - 'hrsh7th/nvim-cmp', - requires = { - 'hrsh7th/cmp-nvim-lsp', - 'hrsh7th/cmp-buffer', - 'hrsh7th/cmp-path', - 'hrsh7th/cmp-cmdline', - }, - config = function () - require('plugin-config/nvim-cmp') - end - } - -- for lsp signature autocompletion use { 'ray-x/lsp_signature.nvim',