From 3fd34351b9e0750a148a791ff0fe12ec8604cdab Mon Sep 17 00:00:00 2001 From: Szwendacz99 Date: Thu, 27 Oct 2022 19:14:44 +0200 Subject: [PATCH] initial lsp setup --- coc-settings.json | 85 ----------------------------------------------- init.vim | 81 +++----------------------------------------- lua/general.lua | 78 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 162 deletions(-) delete mode 100644 coc-settings.json diff --git a/coc-settings.json b/coc-settings.json deleted file mode 100644 index 07edc9b..0000000 --- a/coc-settings.json +++ /dev/null @@ -1,85 +0,0 @@ -{ - "codeLens.enable": true, - "codeLens.position": "top", - "coc.preferences.extensionUpdateCheck": "daily", - "coc.preferences.enableMessageDialog": true, - "coc.preferences.formatOnType": true, - "coc.preferences.willSaveHandlerTimeout": 1000, - "coc.preferences.enableLinkedEditing": true, - "coc.preferences.formatOnSaveFiletypes": [ - "c", - "go", - "python", - "rust", - "markdown", - "javascript", - "typescript", - "json", - "jsonc" - ], - "coc.source.file.ignoreHidden": false, - "diagnostic.floatConfig": { - "rounded": true, - "border": true - }, - "diagnostic.autoRefresh": true, - "diagnostic.refreshOnInsertMode": true, - "diagnostic.format": "[%severity] %message [%source]", - "diagnostic.virtualText": true, - "diagnostic.level": "hint", - "diagnostic.checkCurrentLine": true, - "diagnostic.separateRelatedInformationAsDiagnostics": true, - "eslint.autoFixOnSave": true, - "eslint.format.enable": true, - "eslint.packageManager": "yarn", - "git.addGBlameToVirtualText": true, - "git.blameUseRealTime": true, - "hover.floatConfig": { - "rounded": true, - "border": true - }, - "list.normalMappings": { - "": "do:exit" - }, - "list.insertMappings": { - "": "do:exit" - }, - "python.formatting.provider": "yapf", - "python.linting.enabled": true, - "python.analysis.diagnosticMode": "workspace", - "python.linting.pylintEnabled": true, - "python.linting.flake8Enabled": true, - "python.linting.pylamaEnabled": true, - "python.linting.banditEnabled": true, - "python.linting.pycodestyleEnabled": true, - "python.linting.mypyEnabled": false, - "python.linting.pytypeEnabled": true, - "python.analysis.typeCheckingMode": "basic", - "semanticTokens.enable": true, - "signature.target": "echo", - "suggest.detailField": "abbr", - "suggest.defaultSortMethod": "none", - "suggest.selection": "recentlyUsedByPrefix", - "suggest.noselect": false, - "suggest.floatConfig": { - "rounded": true, - "border": true - }, - "signature.floatConfig": { - "rounded": true, - "border": true - }, - "snippet.choicesMenuPicker": true, - "languageserver": { - "bash": { - "command": "bash-language-server", - "args": ["start"], - "filetypes": ["sh"] - }, - "kotlin": { - "command": "kotlin-language-server", - "filetypes": ["kotlin"] - } - }, - "git.enableGutters": true -} diff --git a/init.vim b/init.vim index f5bedeb..fe2f5e9 100644 --- a/init.vim +++ b/init.vim @@ -6,15 +6,18 @@ Plug 'nvim-tree/nvim-tree.lua' " neovim lsp plugins and depencencies Plug 'neovim/nvim-lspconfig' +Plug 'hrsh7th/cmp-nvim-lsp' +Plug 'hrsh7th/cmp-buffer' +Plug 'hrsh7th/nvim-cmp' Plug 'williamboman/mason.nvim' Plug 'williamboman/mason-lspconfig.nvim' Plug 'jose-elias-alvarez/null-ls.nvim' + " various plugins 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 'neoclide/coc.nvim', {'branch': 'release'} Plug 'preservim/nerdcommenter' Plug 'mhinz/vim-startify' Plug 'rmagatti/auto-session' @@ -62,14 +65,6 @@ nnoremap :NvimTreeToggle nmap NERDCommenterToggle vmap NERDCommenterToggle -" saving with Ctrl+s -"nnoremap :update -"inoremap :update -"vnoremap :updategv " gv to preserve visual selection - -" show uncommited git changes in current part of the code -nnoremap :CocCommand git.chunkInfo - "theme configuration syntax enable let g:onedark_config = { @@ -102,80 +97,12 @@ imap < >gv vmap and for scroll float windows/popups. -if has('nvim-0.4.0') || has('patch-8.2.0750') - nnoremap coc#float#has_scroll() ? coc#float#scroll(1) : "\" - nnoremap coc#float#has_scroll() ? coc#float#scroll(0) : "\" - inoremap coc#float#has_scroll() ? "\=coc#float#scroll(1)\" : "\" - inoremap coc#float#has_scroll() ? "\=coc#float#scroll(0)\" : "\" - vnoremap coc#float#has_scroll() ? coc#float#scroll(1) : "\" - vnoremap coc#float#has_scroll() ? coc#float#scroll(0) : "\" -endif - " Find files using Telescope command-line sugar. nnoremap ff Telescope find_files nnoremap fg Telescope live_grep nnoremap fb Telescope buffers nnoremap fh Telescope help_tags -"""""""""""""""""""""""""""" -" config for coc#pum#visible -"""""""""""""""""""""""""""" - -" Some servers have issues with backup files, see #649. -set nobackup -set nowritebackup - -" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable -" delays and poor user experience. -set updatetime=300 - -" Always show the signcolumn, otherwise it would shift the text each time -" diagnostics appear/become resolved. -set signcolumn=yes - - -" Symbol renaming. -nmap rn (coc-rename) - -" Formatting selected code. -xmap ft (coc-format-selected) -nmap ft (coc-format-selected) - -" GoTo code navigation. -nmap gd (coc-definition) -nmap gy (coc-type-definition) -nmap gi (coc-implementation) -nmap gr (coc-references) - -" Use tab for trigger completion with characters ahead and navigate. -" NOTE: There's always complete item selected by default, you may want to enable -" no select by `"suggest.noselect": true` in your configuration file. -" NOTE: Use command ':verbose imap ' to make sure tab is not mapped by -" other plugin before putting this into your config. -inoremap - \ coc#pum#visible() ? coc#pum#next(1) : - \ CheckBackspace() ? "\" : - \ coc#refresh() -inoremap coc#pum#visible() ? coc#pum#prev(1) : "\" - -" Make to accept selected completion item or notify coc.nvim to format -" u breaks current undo, please make your own choice. -inoremap coc#pum#visible() ? coc#pum#confirm() - \: "\u\\=coc#on_enter()\" - -function! CheckBackspace() abort - let col = col('.') - 1 - return !col || getline('.')[col - 1] =~# '\s' -endfunction - -" Use to trigger completion. -if has('nvim') - inoremap coc#refresh() -else - inoremap coc#refresh() -endif - " general configs set modeline diff --git a/lua/general.lua b/lua/general.lua index 7e02508..29cecac 100644 --- a/lua/general.lua +++ b/lua/general.lua @@ -39,6 +39,13 @@ codewindow.setup({ }) codewindow.apply_default_keybinds() +require'lspconfig'.pyright.setup{} +require'lspconfig'.bashls.setup{} +require'lspconfig'.salt_ls.setup{} +require'lspconfig'.dockerls.setup{} +require'lspconfig'.kotlin_language_server.setup{} +require'lspconfig'.intelephense.setup{} +require'lspconfig'.eslint.setup{} -- load perl lsp require'lspconfig'.perlnavigator.setup{ @@ -53,6 +60,77 @@ require'lspconfig'.perlnavigator.setup{ } } +-- 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(), + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'vsnip' }, -- For vsnip users. + -- { name = 'luasnip' }, -- For luasnip users. + -- { name = 'ultisnips' }, -- For ultisnips users. + -- { name = 'snippy' }, -- For snippy users. + }, { + { 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 `/` and `?` (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' } + }) +}) + +-- 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, hijack_cursor = true,