From 7e32c663aca70e9d147d9200b127e6c01b691976 Mon Sep 17 00:00:00 2001 From: siduck76 Date: Fri, 12 Mar 2021 00:30:34 +0530 Subject: [PATCH] finally nvim lsp workin! --- init.lua | 7 ++++++ lua/coc/lua.lua | 43 --------------------------------- lua/nvim-compe/lua.lua | 49 ++++++++++++++++++++++++++++++++++++++ lua/nvim-lspconfig/lua.lua | 32 +++++++++++++++++++++++++ lua/pluginsList/lua.lua | 7 ++++-- plugin/packer_compiled.vim | 16 +++++-------- 6 files changed, 99 insertions(+), 55 deletions(-) create mode 100644 lua/nvim-compe/lua.lua create mode 100644 lua/nvim-lspconfig/lua.lua diff --git a/init.lua b/init.lua index 09ba2e8..c7855c3 100644 --- a/init.lua +++ b/init.lua @@ -7,6 +7,11 @@ require('nvimTree.lua') require('bufferline.lua') require('statusline.lua') +-- lsp +require('nvim-lspconfig.lua') +require('nvim-compe.lua') +require('coc.lua') + require('gitsigns.lua') require'colorizer'.setup() @@ -39,3 +44,5 @@ cmd("hi EndOfBuffer guifg=#282c34") -- tree folder name , icon color cmd("highlight NvimTreeFolderIcon guifg = #61afef") cmd("highlight NvimTreeFolderName guifg = #61afef") + +require('nvim-autopairs').setup() diff --git a/lua/coc/lua.lua b/lua/coc/lua.lua index e047993..e69de29 100644 --- a/lua/coc/lua.lua +++ b/lua/coc/lua.lua @@ -1,43 +0,0 @@ -vim.api.nvim_exec([[ - -set fillchars=eob:\ - -tnoremap -" start terminal in insert mode -au BufEnter * if &buftype == 'terminal' | :startinsert | endif - -" open terminal on the bottom -function! OpenTerminal() - split term://bash - resize 10 -endfunction -nnoremap :call OpenTerminal() -nnoremap :vnew term://bash - -set ignorecase -set noswapfile -set title -set shortmess+=c -set updatetime=250 "for gitsigns" - -" new tab and switching between em - -nnoremap : tabnew -nnoremap : tabp -nnoremap : tabn - -map k -map j -map l -map h - -inoremap kk - -let g:indentLine_enabled = 3 -let g:indentLine_char_list = ['▏'] - -norm! gg=G - -set expandtab sw=2 - -]]) diff --git a/lua/nvim-compe/lua.lua b/lua/nvim-compe/lua.lua new file mode 100644 index 0000000..575fe22 --- /dev/null +++ b/lua/nvim-compe/lua.lua @@ -0,0 +1,49 @@ +vim.cmd [[packadd nvim-lspconfig]] +vim.cmd [[packadd nvim-compe]] + +vim.o.completeopt = "menuone,noselect" + +require'compe'.setup { + enabled = true; + autocomplete = true; + debug = false; + min_length = 1; + preselect = 'enable'; + throttle_time = 80; + source_timeout = 200; + incomplete_delay = 400; + max_abbr_width = 100; + max_kind_width = 100; + max_menu_width = 100; + documentation = false; + + source = { + path = true; + buffer = true; + calc = true; + vsnip = true; + nvim_lsp = true; + nvim_lua = true; + spell = true; + tags = true; + snippets_nvim = true; + treesitter = true; + }; +} + +local t = function(str) + return vim.api.nvim_replace_termcodes(str, true, true, true) +end +_G.s_tab_complete = function() + if vim.fn.pumvisible() == 1 then + return t "" + elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then + return t "(vsnip-jump-prev)" + else + return t "" + end +end + +vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", {expr = true}) +vim.api.nvim_set_keymap("i", "", "v:lua.s_tab_complete()", {expr = true}) +vim.api.nvim_set_keymap("s", "", "v:lua.s_tab_complete()", {expr = true}) diff --git a/lua/nvim-lspconfig/lua.lua b/lua/nvim-lspconfig/lua.lua new file mode 100644 index 0000000..7d5a6f8 --- /dev/null +++ b/lua/nvim-lspconfig/lua.lua @@ -0,0 +1,32 @@ +vim.cmd [[packadd nvim-lspconfig]] +vim.cmd [[packadd nvim-compe]] + +local function map(mode, lhs, rhs, opts) + local options = {noremap = true} + if opts then options = vim.tbl_extend('force', options, opts) end + vim.api.nvim_set_keymap(mode, lhs, rhs, options) +end + +local opts = { noremap=true, silent=true } + + -- Mappings. + map('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + map('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + map('n', 'gr', 'lua vim.lsp.buf.references()', opts) + + map('n', 'K', 'lua vim.lsp.buf.hover()', opts) + map('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + map('n', '', 'lua vim.lsp.buf.signature_help()', opts) + map('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) + map('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) + map('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) + map('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) + map('n', 'rn', 'lua vim.lsp.buf.rename()', opts) + map('n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) + map('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) + map('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) + map('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) + +require'lspconfig'.tsserver.setup{} +require'lspconfig'.cssls.setup{} +require'lspconfig'.html.setup{} diff --git a/lua/pluginsList/lua.lua b/lua/pluginsList/lua.lua index d85c0dd..6ed0273 100644 --- a/lua/pluginsList/lua.lua +++ b/lua/pluginsList/lua.lua @@ -5,11 +5,9 @@ return require('packer').startup(function() use {'wbthomason/packer.nvim', opt = true} use { 'kyazdani42/nvim-web-devicons'} use { 'kyazdani42/nvim-tree.lua'} - use { 'neoclide/coc.nvim' , branch = 'release'} use { 'nvim-lua/plenary.nvim'} use { 'lewis6991/gitsigns.nvim'} use { 'glepnir/galaxyline.nvim'} - use { 'tweekmonster/startuptime.vim'} use { 'akinsho/nvim-bufferline.lua'} use { '907th/vim-auto-save'} use { 'nvim-treesitter/nvim-treesitter'} @@ -18,4 +16,9 @@ return require('packer').startup(function() use { 'Yggdroot/indentLine'} use { 'ryanoasis/vim-devicons'} use { 'sbdchd/neoformat'} + use { 'neovim/nvim-lspconfig'} + use { 'hrsh7th/nvim-compe'} + use { 'windwp/nvim-autopairs'} + use { 'alvan/vim-closetag'} + use { 'tweekmonster/startuptime.vim'} end) diff --git a/plugin/packer_compiled.vim b/plugin/packer_compiled.vim index 29285aa..b919611 100644 --- a/plugin/packer_compiled.vim +++ b/plugin/packer_compiled.vim @@ -36,9 +36,9 @@ _G.packer_plugins = { loaded = true, path = "/home/sid/.local/share/nvim/site/pack/packer/start/base16-vim" }, - ["coc.nvim"] = { + ["completion-nvim"] = { loaded = true, - path = "/home/sid/.local/share/nvim/site/pack/packer/start/coc.nvim" + path = "/home/sid/.local/share/nvim/site/pack/packer/start/completion-nvim" }, ["galaxyline.nvim"] = { loaded = true, @@ -52,14 +52,6 @@ _G.packer_plugins = { loaded = true, path = "/home/sid/.local/share/nvim/site/pack/packer/start/indentLine" }, - ["lualine.nvim"] = { - loaded = true, - path = "/home/sid/.local/share/nvim/site/pack/packer/start/lualine.nvim" - }, - neoformat = { - loaded = true, - path = "/home/sid/.local/share/nvim/site/pack/packer/start/neoformat" - }, ["nvim-bufferline.lua"] = { loaded = true, path = "/home/sid/.local/share/nvim/site/pack/packer/start/nvim-bufferline.lua" @@ -68,6 +60,10 @@ _G.packer_plugins = { loaded = true, path = "/home/sid/.local/share/nvim/site/pack/packer/start/nvim-colorizer.lua" }, + ["nvim-lspconfig"] = { + loaded = true, + path = "/home/sid/.local/share/nvim/site/pack/packer/start/nvim-lspconfig" + }, ["nvim-tree.lua"] = { loaded = true, path = "/home/sid/.local/share/nvim/site/pack/packer/start/nvim-tree.lua"