From ea3a7cee7ad47996e29205c0ef44ee0f0c80683e Mon Sep 17 00:00:00 2001 From: Mitchell Allain Date: Sun, 28 Aug 2022 16:31:07 -0500 Subject: [PATCH] Improve LSP diagnostics and completion config, suppress ALE --- README.md | 22 +++- nvim/plugins.lua | 287 +++++++++++++++++++++++------------------ scripts/termescapes.sh | 40 ++++++ vimrcs/plugins.vim | 74 +++++++---- 4 files changed, 270 insertions(+), 153 deletions(-) create mode 100755 scripts/termescapes.sh diff --git a/README.md b/README.md index d503b4a..74cf605 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,24 @@ # dotfiles -This repository tracks my bash shell configuration and the configuration of many tools that I use with Ubuntu (18.04). -This repository uses the awesome [dotbot](https://github.com/anishathalye/dotbot) tool to "bootstrap" my dotfiles. I primarily use it for creating and updating the symlinks from my home folder to the `~/.dotfiles` folder containing this repo, rather than using it to set up new systems. +This repository tracks my bash shell configuration and the configuration of many +tools that I use with Ubuntu (18.04). + +This repository uses the awesome +[dotbot](https://github.com/anishathalye/dotbot) tool to "bootstrap" my +dotfiles. I primarily use it for creating and updating the symlinks from my home +folder to the `~/.dotfiles` folder containing this repo, rather than using it to +set up new systems. ## `private` submodule -The private directory submodule is hosted separately, and contains configuration specific to my work. The `~/.bashrc` file checks the existence of most of these files prior to sourcing them and as such, should succeed without the private directory present. + +The private directory submodule is hosted separately, and contains configuration +specific to my work. The `~/.bashrc` file checks the existence of most of these +files prior to sourcing them and as such, should succeed without the private +directory present. ## References -Credit to Nathaniel Landau's [awesome article "MY MAC OSX BASH PROFILE"](https://natelandau.com/my-mac-osx-bash_profile/) which provided much of the inspiration for my `~/.bashrc`, despite being geared towards Mac OS X. + +Credit to Nathaniel Landau's +[awesome article "MY MAC OSX BASH PROFILE"](https://natelandau.com/my-mac-osx-bash_profile/) +which provided much of the inspiration for my `~/.bashrc`, despite being geared +towards Mac OS X. diff --git a/nvim/plugins.lua b/nvim/plugins.lua index 235f21b..5ab8fdc 100644 --- a/nvim/plugins.lua +++ b/nvim/plugins.lua @@ -3,159 +3,187 @@ -- Inserted from https://github.com/neovim/nvim-lspconfig#suggested-configuration -- Mappings. -- See `:help vim.diagnostic.*` for documentation on any of the below functions -local opts = { noremap=true, silent=true } -vim.keymap.set('n', 'di', 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 opts = { noremap = true, silent = true } +vim.keymap.set("n", "di", 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) -- Use an on_attach function to only map the following keys -- after the language server attaches to the current buffer local on_attach = function(client, bufnr) - -- print('LSP attached - loading keymaps') - -- 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', 'fo', vim.lsp.buf.formatting, bufopts) - vim.keymap.set('v', 'fo', vim.lsp.buf.range_formatting, bufopts) -- this isn't quite working yet + -- print('LSP attached - loading keymaps') + -- 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", "k", 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", "fo", vim.lsp.buf.formatting, bufopts) + vim.keymap.set("v", "fo", vim.lsp.buf.range_formatting, bufopts) -- this isn't quite working yet end +-- luasnip setup +local luasnip = require("luasnip") + +-- nvim-cmp setup +-- https://github.com/hrsh7th/nvim-cmp +local cmp = require("cmp") +cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), + -- [''] = cmp.mapping.confirm { + -- behavior = cmp.ConfirmBehavior.Replace, + -- select = true, + -- }, + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { "i", "s" }), + [""] = 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" }), + }), + sources = { + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "cmp_pandoc" }, + }, +}) + +-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). +-- cmp.setup.cmdline('/', { +-- mapping = cmp.mapping.preset.cmdline(), +-- sources = { +-- { name = 'buffer' } +-- } +-- }) + +-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). +-- cmp.setup.cmdline(':', { +-- mapping = cmp.mapping.preset.cmdline(), +-- sources = cmp.config.sources({ +-- { name = 'path' } +-- }, { +-- { name = 'cmdline' } +-- }) +-- }) + local lsp_flags = { - -- This is the default in Nvim 0.7+ - debounce_text_changes = 150, + -- This is the default in Nvim 0.7+ + debounce_text_changes = 150, } -- From https://github.com/neovim/nvim-lspconfig/wiki/Autocompletion#nvim-cmp -- Add additional capabilities supported by nvim-cmp local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) +capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities) -local lspconfig = require('lspconfig') +local lspconfig = require("lspconfig") -lspconfig['pyright'].setup{ +lspconfig["pyright"].setup({ on_attach = on_attach, flags = lsp_flags, capabilities = capabilities, -} -lspconfig['ccls'].setup{ +}) +lspconfig["ccls"].setup({ on_attach = on_attach, flags = lsp_flags, capabilities = capabilities, -} -lspconfig['rust_analyzer'].setup{ +}) +lspconfig["rust_analyzer"].setup({ on_attach = on_attach, flags = lsp_flags, capabilities = capabilities, -- Server-specific settings... settings = { - ["rust-analyzer"] = {} - } -} + ["rust-analyzer"] = {}, + }, +}) --- luasnip setup -local luasnip = require 'luasnip' +local null_ls = require("null-ls") --- nvim-cmp setup -local cmp = require 'cmp' -cmp.setup { - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - -- [''] = cmp.mapping.confirm { - -- behavior = cmp.ConfirmBehavior.Replace, - -- select = true, - -- }, - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, { 'i', 's' }), - [''] = 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' }), - }), - sources = { - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - }, -} +null_ls.setup({ + sources = { + -- null_ls.builtins.code_actions.gitsigns, + -- null_ls.builtins.completion.spell, + null_ls.builtins.diagnostics.markdownlint, + -- null_ls.builtins.diagnostics.pylint, + null_ls.builtins.diagnostics.cppcheck, + null_ls.builtins.diagnostics.flake8, + null_ls.builtins.formatting.clang_format, -require("null-ls").setup({ - sources = { - -- require("null-ls").builtins.completion.spell, - require("null-ls").builtins.diagnostics.markdownlint, - -- require("null-ls").builtins.diagnostics.pylint, - require("null-ls").builtins.diagnostics.cppcheck, - require("null-ls").builtins.diagnostics.flake8, - require("null-ls").builtins.formatting.clang_format, - - -- had to npm install --global prettier - require("null-ls").builtins.formatting.prettier.with({ - extra_args = { "--print-width", "80", "--prose-wrap", "always" }, - }), - require("null-ls").builtins.formatting.stylua, - }, - on_attach = on_attach, - log_level = "trace", + -- had to npm install --global prettier + null_ls.builtins.formatting.prettier.with({ + extra_args = { "--print-width", "80", "--prose-wrap", "always" }, + filetypes = { "html", "json", "yaml", "markdown", "xml" }, -- overwrite to add xml via plugin + }), + null_ls.builtins.formatting.stylua.with({ + extra_args = { "--indent-type", "Spaces" }, + }), + }, + on_attach = on_attach, + log_level = "warn", }) --- local diagnostics_active = true --- local toggle_diagnostics = function() --- diagnostics_active = not diagnostics_active --- if diagnostics_active then --- print('Showing diagnostics') --- vim.diagnostic.show() --- else --- print('Hiding diagnostics') --- vim.diagnostic.hide() --- end --- end --- vim.keymap.set('n', 'dd', toggle_diagnostics) +local diagnostics_active = true +local toggle_diagnostics = function() + diagnostics_active = not diagnostics_active + if diagnostics_active then + print("Showing diagnostics") + vim.diagnostic.show() + else + print("Hiding diagnostics") + vim.diagnostic.hide() + end +end +vim.keymap.set("n", "dd", toggle_diagnostics) -- Plug-in allows easy toggling of diagnostics features -- start_on currently does not work -- require'toggle_lsp_diagnostics'.init({ start_on = false }) -require('toggle_lsp_diagnostics').init({ - -- underline = false, - virtual_text = { - prefix = "●", - }}) -vim.keymap.set('n', 'dd', '(toggle-lsp-diag)') -vim.keymap.set('n', 'dt', '(toggle-lsp-diag-vtext)') -vim.keymap.set('n', 'de', vim.diagnostic.enable) +-- require("toggle_lsp_diagnostics").init({ +-- underline = true, +-- virtual_text = { +-- prefix = "●", +-- }, +-- }) +-- vim.keymap.set("n", "dd", "(toggle-lsp-diag)") +-- vim.keymap.set("n", "dt", "(toggle-lsp-diag-vtext)") +-- vim.keymap.set("n", "de", vim.diagnostic.enable) -- Diagnostic symbols in the sign column (gutter) -- local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } @@ -164,14 +192,23 @@ vim.keymap.set('n', 'de', vim.diagnostic.enable) -- vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) -- end + vim.diagnostic.config({ - virtual_text = { - prefix = '●' - }, - update_in_insert = false, + severity_sort = true, + underline = true, + update_in_insert = false, + virtual_text = { + spacing = 4, + prefix = "●", + }, + float = { + source = "always", + }, }) -require('colorbuddy').setup() -require('neosolarized').setup({ +-- require("colorbuddy").setup() + +-- from https://github.com/craftzdog/dotfiles-public/blob/1c58c37e96cd5f451d7f43ac1a3b3c5807752ad9/.config/nvim/after/plugin/neosolarized.rc.lua +require("neosolarized").setup({ comment_italics = true, }) diff --git a/scripts/termescapes.sh b/scripts/termescapes.sh new file mode 100755 index 0000000..2bbac16 --- /dev/null +++ b/scripts/termescapes.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# Many terminal emulators are built on VTE +# This test represents the latest escape sequences in VTE 0.52 + +echo -e '\e[1mbold\e[22m' +echo -e '\e[2mdim\e[22m' +echo -e '\e[3mitalic\e[23m' +echo -e '\e[4munderline\e[24m' +echo -e '\e[4:1mthis is also underline (new in 0.52)\e[4:0m' +echo -e '\e[21mdouble underline (new in 0.52)\e[24m' +echo -e '\e[4:2mthis is also double underline (new in 0.52)\e[4:0m' +echo -e '\e[4:3mcurly underline (new in 0.52)\e[4:0m' +echo -e '\e[5mblink (new in 0.52)\e[25m' +echo -e '\e[7mreverse\e[27m' +echo -e '\e[8minvisible\e[28m <- invisible (but copy-pasteable)' +echo -e '\e[9mstrikethrough\e[29m' +echo -e '\e[53moverline (new in 0.52)\e[55m' + +echo -e '\e[31mred\e[39m' +echo -e '\e[91mbright red\e[39m' +echo -e '\e[38:5:42m256-color, de jure standard (ITU-T T.416)\e[39m' +echo -e '\e[38;5;42m256-color, de facto standard (commonly used)\e[39m' +echo -e '\e[38:2::240:143:104mtruecolor, de jure standard (ITU-T T.416) (new in 0.52)\e[39m' +echo -e '\e[38:2:240:143:104mtruecolor, rarely used incorrect format (might be removed at some point)\e[39m' +echo -e '\e[38;2;240;143;104mtruecolor, de facto standard (commonly used)\e[39m' + +echo -e '\e[46mcyan background\e[49m' +echo -e '\e[106mbright cyan background\e[49m' +echo -e '\e[48:5:42m256-color background, de jure standard (ITU-T T.416)\e[49m' +echo -e '\e[48;5;42m256-color background, de facto standard (commonly used)\e[49m' +echo -e '\e[48:2::240:143:104mtruecolor background, de jure standard (ITU-T T.416) (new in 0.52)\e[49m' +echo -e '\e[48:2:240:143:104mtruecolor background, rarely used incorrect format (might be removed at some point)\e[49m' +echo -e '\e[48;2;240;143;104mtruecolor background, de facto standard (commonly used)\e[49m' + +echo -e '\e[21m\e[58:5:42m256-color underline (new in 0.52)\e[59m\e[24m' +echo -e '\e[21m\e[58;5;42m256-color underline (new in 0.52)\e[59m\e[24m' +echo -e '\e[4:3m\e[58:2::240:143:104mtruecolor underline (new in 0.52) (*)\e[59m\e[4:0m' +echo -e '\e[4:3m\e[58:2:240:143:104mtruecolor underline (new in 0.52) (might be removed at some point) (*)\e[59m\e[4:0m' +echo -e '\e[4:3m\e[58;2;240;143;104mtruecolor underline (new in 0.52) (*)\e[59m\e[4:0m' + diff --git a/vimrcs/plugins.vim b/vimrcs/plugins.vim index 9486494..eea9969 100644 --- a/vimrcs/plugins.vim +++ b/vimrcs/plugins.vim @@ -34,7 +34,7 @@ call plug#begin('~/.vim/plugged') " ALE (Asynchronous Lint Engine) is a plugin providing linting " (syntax checking and semantic errors) - Plug 'dense-analysis/ale' + " Plug 'dense-analysis/ale' Plug 'tpope/vim-surround' Plug 'tpope/vim-fugitive' @@ -53,14 +53,34 @@ call plug#begin('~/.vim/plugged') " once you are on the latest stable release (>= v0.7.2) " this is the recommended python setup - Plug 'neovim/nvim-lspconfig' - Plug 'WhoIsSethDaniel/toggle-lsp-diagnostics.nvim' + Plug 'neovim/nvim-lspconfig' " Quickstart configs for built-in LSP client + Plug 'WhoIsSethDaniel/toggle-lsp-diagnostics.nvim' " easily toggle virtual text diagnostics on and off + + " Completion with nvim-cmp + " https://github.com/hrsh7th/nvim-cmp Plug 'hrsh7th/nvim-cmp' " auto-completion plugin + + " List of completion sources + " https://github.com/hrsh7th/nvim-cmp/wiki/List-of-sources Plug 'hrsh7th/cmp-nvim-lsp' " LSP source for nvim-cmp + Plug 'hrsh7th/cmp-buffer' " nvim-cmp source for buffer words + Plug 'hrsh7th/cmp-path' " nvim-cmp source for filesystem paths + " Plug 'hrsh7th/cmp-cmdline' " nvim-cmp source for vim's cmdline, found this to be intrusive + + Plug 'aspeddro/cmp-pandoc.nvim' " nvim-cmp source for markdown / pandoc + Plug 'jbyuki/nabla.nvim' " floating LaTeX equation rendered + + " For luasnip users Plug 'saadparwaiz1/cmp_luasnip' " Snippets source for nvim-cmp Plug 'L3MON4D3/LuaSnip' " Snippets plugin - Plug 'nvim-lua/plenary.nvim' + Plug 'nvim-lua/plenary.nvim' " Lua function library + + " null-ls - Inject diagnostics and formatting through LSP from supported + " binaries on PATH. Note this does not provide the binaries, which must be + " installed seperately with system package manager or lang package manager. + " Built-in support: + " https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/BUILTINS.md Plug 'jose-elias-alvarez/null-ls.nvim' " Zeavim allows to use the offline documentation browser Zeal from Vim. @@ -87,7 +107,8 @@ call plug#begin('~/.vim/plugged') Plug 'preservim/tagbar' " Plug 'github/copilot.vim' - Plug 'ap/vim-css-color' + " Plug 'ap/vim-css-color' + Plug 'chrisbra/Colorizer' call plug#end() @@ -109,6 +130,11 @@ endif set background=dark hi Normal ctermbg=NONE guibg=NONE +""""""""""""""""""""""""""""""" +" => Colorizer +"""""""""""""""""""""""""""""" +let g:colorizer_auto_filetype='vim,lua,css,html' + """"""""""""""""""""""""""""""" " => fzf - fuzzy finder """""""""""""""""""""""""""""" @@ -141,30 +167,30 @@ let g:NERDTreeMapJumpPrevSibling = '' nnoremap t :TagbarToggle -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" => Ale (syntax checker and linter) -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -let g:ale_linters = { -\ 'python': ['flake8'], -\} +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +"" => Ale (syntax checker and linter) +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +"let g:ale_linters = { +"\ 'python': ['flake8'], +"\} -let g:ale_fixers = { -\ 'rust': ['rustfmt', 'trim_whitespace', 'remove_trailing_lines'], -\ 'python': ['yapf', 'trim_whitespace'] -\} +"let g:ale_fixers = { +"\ 'rust': ['rustfmt', 'trim_whitespace', 'remove_trailing_lines'], +"\ 'python': ['yapf', 'trim_whitespace'] +"\} -" Optional, configure as-you-type completions -set completeopt=menu,menuone,preview,noselect,noinsert -let g:ale_completion_enabled = 1 +"" Optional, configure as-you-type completions +"set completeopt=menu,menuone,preview,noselect,noinsert +"let g:ale_completion_enabled = 1 -nmap a (ale_next_wrap) +"nmap a (ale_next_wrap) -" Disabling highlighting -let g:ale_set_highlights = 0 +"" Disabling highlighting +"let g:ale_set_highlights = 0 -" Only run linting when saving the file -let g:ale_lint_on_text_changed = 'never' -let g:ale_lint_on_enter = 0 +"" Only run linting when saving the file +"let g:ale_lint_on_text_changed = 'never' +"let g:ale_lint_on_enter = 0 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""