From 6105bf7d42fe451e2dbb7b3097d6d9a5a5268771 Mon Sep 17 00:00:00 2001 From: Szwendacz99 Date: Fri, 28 Oct 2022 20:55:05 +0200 Subject: [PATCH] Pure built-in lsp config finished (probably) --- init.vim | 18 ++++-- lua/general.lua | 36 +++++------- lua/my-lint.lua | 12 +++- lua/my-lspconfig.lua | 131 +++++++++++++++++++++++++++++++------------ 4 files changed, 132 insertions(+), 65 deletions(-) diff --git a/init.vim b/init.vim index ce28c1e..915589f 100644 --- a/init.vim +++ b/init.vim @@ -11,25 +11,23 @@ Plug 'hrsh7th/cmp-buffer' Plug 'hrsh7th/nvim-cmp' Plug 'williamboman/mason.nvim' Plug 'williamboman/mason-lspconfig.nvim' -Plug 'jose-elias-alvarez/null-ls.nvim' Plug 'mfussenegger/nvim-lint' "Plug 'dense-analysis/ale' " various plugins +Plug 'airblade/vim-gitgutter' Plug 'akinsho/bufferline.nvim', { 'tag': 'v3.*' } Plug 'gorbit99/codewindow.nvim' -Plug 'vim-perl/vim-perl', { 'for': 'perl', 'do': 'make clean carp dancer highlight-all-pragmas moose test-more try-tiny' } Plug 'preservim/nerdcommenter' -Plug 'mhinz/vim-startify' Plug 'rmagatti/auto-session' Plug 'tpope/vim-fugitive' Plug 'Glench/Vim-Jinja2-Syntax' Plug 'vmware-archive/salt-vim' Plug 'vim-airline/vim-airline' Plug 'vim-airline/vim-airline-themes' -Plug 'honza/vim-snippets' Plug 'itchyny/vim-cursorword' Plug 'sheerun/vim-polyglot' +Plug 'f-person/git-blame.nvim' " themes Plug 'navarasu/onedark.nvim' @@ -53,9 +51,9 @@ call plug#end() set termguicolors " load main lua file with additional configs +lua require("general") lua require("my-lspconfig") lua require("my-lint") -lua require("general") " highlight all .conf files as apache config (:]) autocmd BufEnter *.conf :setlocal filetype=apache @@ -106,6 +104,16 @@ nnoremap fg Telescope live_grep nnoremap fb Telescope buffers nnoremap fh Telescope help_tags +" gitgutter setup +let g:gitgutter_sign_added = '|' +let g:gitgutter_sign_modified = '|' +let g:gitgutter_sign_removed = '|' +let g:gitgutter_sign_removed_first_line = '|' +let g:gitgutter_sign_removed_above_and_below = '|' +let g:gitgutter_sign_modified_removed = '|' +let g:gitgutter_preview_win_floating = 1 +nnoremap GitGutterPreviewHunk + " general configs set modeline let g:sls_use_jinja_syntax = 1 diff --git a/lua/general.lua b/lua/general.lua index bb0df77..dfb126e 100644 --- a/lua/general.lua +++ b/lua/general.lua @@ -1,16 +1,27 @@ --- load lsp and dependencies (help for both coc and independent lsp setup) +-- load lsp and dependencies require("mason").setup() require("mason-lspconfig").setup({ ensure_installed = { "bashls", "pyright", + "pylsp", + --"pyre", "perlnavigator", "salt_ls", "dockerls", "kotlin_language_server", "intelephense", - "phpactor", - "eslint" + "eslint", + "tsserver", + "markdownlint", + "cssls", + "cssmodules_ls", + "diagnosticls", + "jsonls", + "sumneko_lua", + "sqlls", + "yamlls", + "lemminx" } }) @@ -28,21 +39,10 @@ codewindow.setup({ codewindow.apply_default_keybinds() - - -- Set up nvim-cmp. local cmp = require'cmp' cmp.setup({ - snippet = { - -- REQUIRED - you must specify a snippet engine - expand = function(args) - vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. - -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. - -- require('snippy').expand_snippet(args.body) -- For `snippy` users. - -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. - end, - }, window = { -- completion = cmp.config.window.bordered(), -- documentation = cmp.config.window.bordered(), @@ -92,14 +92,6 @@ cmp.setup.cmdline(':', { }) }) --- Set up lspconfig. -local capabilities = require('cmp_nvim_lsp').default_capabilities() --- Replace with each lsp server you've enabled. -require('lspconfig')[''].setup { - capabilities = capabilities -} - -require'lspconfig'.tsserver.setup{} require("nvim-tree").setup({ create_in_closed_folder = true, diff --git a/lua/my-lint.lua b/lua/my-lint.lua index be424ef..6b85c19 100644 --- a/lua/my-lint.lua +++ b/lua/my-lint.lua @@ -1,8 +1,16 @@ require('lint').linters_by_ft = { - python = {'flake8', 'pylint', 'pycodestyle',} + python = {'flake8', 'pylint', 'pycodestyle', 'pydocstyle',}, + php = {'phpcs'}, + markdown = {'markdownlint'} } -vim.api.nvim_create_autocmd({ "TextChanged" }, { +vim.api.nvim_create_autocmd({ "BufWritePost" }, { + callback = function() + require("lint").try_lint() + end, +}) + +vim.api.nvim_create_autocmd({ "BufEnter" }, { callback = function() require("lint").try_lint() end, diff --git a/lua/my-lspconfig.lua b/lua/my-lspconfig.lua index 1f2005d..dffa70b 100644 --- a/lua/my-lspconfig.lua +++ b/lua/my-lspconfig.lua @@ -1,7 +1,7 @@ -- setup nvim-lspconfig -- Mappings. -- See `:help vim.diagnostic.*` for documentation on any of the below functions -local opts = { noremap=true, silent=true } +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) @@ -10,70 +10,129 @@ 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) - -- Enable completion triggered by - vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + -- 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', 'f', function() vim.lsp.buf.format { async = true } end, bufopts) + -- 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', 'f', function() vim.lsp.buf.format { async = true } end, bufopts) end local capabilities = require('cmp_nvim_lsp').default_capabilities() -require'lspconfig'.pyright.setup{ +require 'lspconfig'.pyright.setup { on_attach = on_attach, capabilities = capabilities, } -require'lspconfig'.bashls.setup{ +require 'lspconfig'.pylsp.setup { on_attach = on_attach, capabilities = capabilities, } -require'lspconfig'.salt_ls.setup{ +require 'lspconfig'.pyre.setup { on_attach = on_attach, capabilities = capabilities, } -require'lspconfig'.dockerls.setup{ +require 'lspconfig'.bashls.setup { on_attach = on_attach, capabilities = capabilities, } -require'lspconfig'.kotlin_language_server.setup{ +require 'lspconfig'.salt_ls.setup { on_attach = on_attach, capabilities = capabilities, } -require'lspconfig'.intelephense.setup{ +require 'lspconfig'.dockerls.setup { on_attach = on_attach, capabilities = capabilities, } -require'lspconfig'.eslint.setup{ +require 'lspconfig'.kotlin_language_server.setup { on_attach = on_attach, capabilities = capabilities, } -require'lspconfig'.perlnavigator.setup{ +require 'lspconfig'.intelephense.setup { + on_attach = on_attach, + capabilities = capabilities, +} +require 'lspconfig'.eslint.setup { + on_attach = on_attach, + capabilities = capabilities, +} +require 'lspconfig'.tsserver.setup { + on_attach = on_attach, + capabilities = capabilities, +} +require 'lspconfig'.perlnavigator.setup { settings = { - perlnavigator = { - perlPath = 'perl', - enableWarnings = true, - perltidyProfile = '', - perlcriticProfile = '', - perlcriticEnabled = true, - } + perlnavigator = { + perlPath = 'perl', + enableWarnings = true, + perltidyProfile = '', + perlcriticProfile = '', + perlcriticEnabled = true, + } }, on_attach = on_attach, capabilities = capabilities, } +require 'lspconfig'.cssls.setup { + on_attach = on_attach, + capabilities = capabilities, +} + +require 'lspconfig'.cssmodules_ls.setup { + on_attach = on_attach, + capabilities = capabilities, +} + +require 'lspconfig'.diagnosticls.setup { + on_attach = on_attach, + capabilities = capabilities, +} + +require 'lspconfig'.jsonls.setup { + on_attach = on_attach, + capabilities = capabilities, +} + +require 'lspconfig'.sumneko_lua.setup { + on_attach = on_attach, + capabilities = capabilities, + settings = { + Lua = { + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { 'vim' }, + }, + }, + }, +} + +require 'lspconfig'.sqlls.setup { + on_attach = on_attach, + capabilities = capabilities, +} + +require 'lspconfig'.yamlls.setup { + on_attach = on_attach, + capabilities = capabilities, +} + +require 'lspconfig'.lemminx.setup { + on_attach = on_attach, + capabilities = capabilities, +}