From 35d7f6d7562c38f9158f95a269071946f043a20a Mon Sep 17 00:00:00 2001 From: AYM1607 Date: Mon, 21 Jun 2021 19:57:46 -0500 Subject: [PATCH] Adds lsp configuration and servers for go, elixir, typescript and python --- elixir-ls.lua | 6 ++ init.lua | 9 ++- lua/lsp/elixir-ls.lua | 8 +++ lua/lsp/go-ls.lua | 46 ++++++++++++++ lua/lsp/init.lua | 6 +- lua/lsp/lua-ls.lua | 37 ++++++++++++ lua/lsp/python-ls.lua | 4 +- lua/lsp/typescript-ls.lua | 6 +- lua/nv-compe/init.lua | 65 ++++++++++++-------- lua/nv-globals.lua | 2 + lua/plugins.lua | 16 ++++- lua/settings.lua | 24 +++++++- plugin/packer_compiled.vim | 119 +++++++++++++++++++++++++++++++++++++ 13 files changed, 313 insertions(+), 35 deletions(-) create mode 100644 elixir-ls.lua create mode 100644 lua/lsp/elixir-ls.lua create mode 100644 lua/lsp/go-ls.lua create mode 100644 lua/lsp/lua-ls.lua create mode 100644 lua/nv-globals.lua create mode 100644 plugin/packer_compiled.vim diff --git a/elixir-ls.lua b/elixir-ls.lua new file mode 100644 index 0000000..fc0a1b0 --- /dev/null +++ b/elixir-ls.lua @@ -0,0 +1,6 @@ +local elixir_ls_binary = "/Users/" .. USER .. "/.config/nvim/lang-srvrs/elixir-ls/language_server.sh" + +require'lspconfig'.elixirls.setup{ + -- Unix + cmd = {elixir_ls_binary}; +} diff --git a/init.lua b/init.lua index 68520c7..52eabd5 100644 --- a/init.lua +++ b/init.lua @@ -1,11 +1,18 @@ +require('nv-globals') require('plugins') require('colorscheme') -require('keymappings') require('settings') +require('keymappings') +-- LSP require('lsp') require('lsp.typescript-ls') require('lsp.python-ls') +require('lsp.lua-ls') +require('lsp.elixir-ls') +require('lsp.go-ls') + +-- Completion require('nv-compe') require('nv-prettier') diff --git a/lua/lsp/elixir-ls.lua b/lua/lsp/elixir-ls.lua new file mode 100644 index 0000000..f111c8b --- /dev/null +++ b/lua/lsp/elixir-ls.lua @@ -0,0 +1,8 @@ +local elixir_ls_binary = "/Users/" .. USER .. "/.config/nvim/lang-srvrs/elixir-ls/language_server.sh" + +require'lspconfig'.elixirls.setup{ + cmd = { elixir_ls_binary }; +} + +vim.api.nvim_command('autocmd BufWritePost *.ex :lua vim.lsp.buf.formatting()') +vim.api.nvim_command('autocmd BufWritePost *.exs :lua vim.lsp.buf.formatting()') diff --git a/lua/lsp/go-ls.lua b/lua/lsp/go-ls.lua new file mode 100644 index 0000000..f4a9daf --- /dev/null +++ b/lua/lsp/go-ls.lua @@ -0,0 +1,46 @@ +lspconfig = require "lspconfig" +lspconfig.gopls.setup { + cmd = {"gopls", "serve"}, + settings = { + gopls = { + analyses = { + unusedparams = true, + }, + staticcheck = true, + }, + }, + root_dir = lspconfig.util.root_pattern(".git","go.mod"), + init_options = {usePlaceholders = true, completeUnimported = true}, +} + +function goimports(timeout_ms) + local context = { source = { organizeImports = true } } + vim.validate { context = { context, "t", true } } + + local params = vim.lsp.util.make_range_params() + params.context = context + + -- See the implementation of the textDocument/codeAction callback + -- (lua/vim/lsp/handler.lua) for how to do this properly. + local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, timeout_ms) + if not result or next(result) == nil then return end + local actions = result[1].result + if not actions then return end + local action = actions[1] + + -- textDocument/codeAction can return either Command[] or CodeAction[]. If it + -- is a CodeAction, it can have either an edit, a command or both. Edits + -- should be executed first. + if action.edit or type(action.command) == "table" then + if action.edit then + vim.lsp.util.apply_workspace_edit(action.edit) + end + if type(action.command) == "table" then + vim.lsp.buf.execute_command(action.command) + end + else + vim.lsp.buf.execute_command(action) + end +end + +vim.cmd("autocmd BufWritePre *.go lua goimports(1000)") diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 2d1e79c..7dec359 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -3,9 +3,5 @@ vim.cmd('nnoremap gD lua vim.lsp.buf.declaration()') vim.cmd('nnoremap gr lua vim.lsp.buf.references()') vim.cmd('nnoremap gi lua vim.lsp.buf.implementation()') +vim.api.nvim_set_keymap('n', 'lr', 'lua vim.lsp.buf.rename()', {noremap = true, silent = true}) vim.cmd('nnoremap K lua vim.lsp.buf.hover()') - --- scroll down hover doc or scroll in definition preview -vim.cmd('nnoremap lua require(\'lspsaga.action\').smart_scroll_with_saga(1)') --- scroll up hover doc -vim.cmd('nnoremap lua require(\'lspsaga.action\').smart_scroll_with_saga(-1)') diff --git a/lua/lsp/lua-ls.lua b/lua/lsp/lua-ls.lua new file mode 100644 index 0000000..0974674 --- /dev/null +++ b/lua/lsp/lua-ls.lua @@ -0,0 +1,37 @@ +-- https://github.com/sumneko/lua-language-server/wiki/Build-and-Run-(Standalone) +USER = vim.fn.expand('$USER') + +local sumneko_root_path = "" +local sumneko_binary = "" + +if vim.fn.has("mac") == 1 then + sumneko_root_path = "/Users/" .. USER .. "/.config/nvim/lang-srvrs/lua-language-server" + sumneko_binary = "/Users/" .. USER .. "/.config/nvim/lang-srvrs/lua-language-server/bin/macOS/lua-language-server" +elseif vim.fn.has("unix") == 1 then + sumneko_root_path = "/home/" .. USER .. "/.config/nvim/lang-srvrs/lua-language-server" + sumneko_binary = "/home/" .. USER .. "/.config/nvim/lang-srvrs/lua-language-server/bin/Linux/lua-language-server" +else + print("Unsupported system for sumneko") +end + +require'lspconfig'.sumneko_lua.setup { + cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"}, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + -- Setup your lua path + path = vim.split(package.path, ';') + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = {'vim'} + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = {[vim.fn.expand('$VIMRUNTIME/lua')] = true, [vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true} + } + } + } +} diff --git a/lua/lsp/python-ls.lua b/lua/lsp/python-ls.lua index 422ae0d..d8e8a34 100644 --- a/lua/lsp/python-ls.lua +++ b/lua/lsp/python-ls.lua @@ -1,2 +1,4 @@ -require'lspconfig'.pyright.setup{} +require'lspconfig'.pyright.setup{ + cmd = {DATA_PATH .. "/lspinstall/python/node_modules/.bin/pyright-langserver", "--stdio"}, +} diff --git a/lua/lsp/typescript-ls.lua b/lua/lsp/typescript-ls.lua index c5016c8..336a58b 100644 --- a/lua/lsp/typescript-ls.lua +++ b/lua/lsp/typescript-ls.lua @@ -1,2 +1,6 @@ -require'lspconfig'.tsserver.setup{} +require'lspconfig'.tsserver.setup{ + cmd = {DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", "--stdio"}, + filetypes = { "javascript", "javascriptreact", "javascript.jsx", "typescript", "typescriptreact", "typescript.tsx" }, + root_dir = require('lspconfig/util').root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git") +} diff --git a/lua/nv-compe/init.lua b/lua/nv-compe/init.lua index b18f897..8a9f296 100644 --- a/lua/nv-compe/init.lua +++ b/lua/nv-compe/init.lua @@ -43,37 +43,54 @@ end -- Use (s-)tab to: --- move to prev/next item in completion menuone --- jump to prev/next snippet's placeholder -_G.tab_complete_only = function() +--_G.tab_complete_only = function() +-- if vim.fn.pumvisible() == 1 then +-- return t "" +-- else +-- return t "" +-- end +--end +--_G.tab_complete = function() +-- if vim.fn.pumvisible() == 1 then +-- return t "" +-- elseif vim.fn.call("vsnip#available", {1}) == 1 then +-- return t "(vsnip-expand-or-jump)" +-- elseif check_back_space() then +-- return t "" +-- else +-- return vim.fn['compe#complete']() +-- end +--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 +_G.comp_jump_if_avail = function() if vim.fn.pumvisible() == 1 then return t "" - else - return t "" + end +end +_G.comp_jump_prev_if_avail = function() + if vim.fn.pumvisible() == 1 then + return t "" end end _G.tab_complete = function() if vim.fn.pumvisible() == 1 then - return t "" - elseif vim.fn.call("vsnip#available", {1}) == 1 then - return t "(vsnip-expand-or-jump)" - elseif check_back_space() then + return vim.fn['compe#confirm']('') + else return t "" - else - return vim.fn['compe#complete']() - end -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("i", "", "v:lua.tab_complete()", {expr = true}) -vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", {expr = true}) -vim.api.nvim_set_keymap("i", "", "v:lua.tab_complete_only()", {expr = true}) -vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete_only()", {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}) +vim.api.nvim_set_keymap("i", "", "v:lua.comp_jump_if_avail()", {expr = true}) +vim.api.nvim_set_keymap("s", "", "v:lua.comp_jump_if_avail()", {expr = true}) +vim.api.nvim_set_keymap("i", "", "v:lua.tab_complete()", {expr = true}) +vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", {expr = true}) +vim.api.nvim_set_keymap("i", "", "v:lua.comp_jump_prev_if_avail()", {expr = true}) +vim.api.nvim_set_keymap("s", "", "v:lua.comp_jump_prev_if_avail()", {expr = true}) diff --git a/lua/nv-globals.lua b/lua/nv-globals.lua new file mode 100644 index 0000000..60fadff --- /dev/null +++ b/lua/nv-globals.lua @@ -0,0 +1,2 @@ +DATA_PATH = vim.fn.stdpath('data') +CACHE_PATH = vim.fn.stdpath('cache') diff --git a/lua/plugins.lua b/lua/plugins.lua index f814270..191facf 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -15,10 +15,11 @@ return require('packer').startup(function(use) -- LSP use 'neovim/nvim-lspconfig' use 'glepnir/lspsaga.nvim' + use 'kabouzeid/nvim-lspinstall' -- Autocomplete use 'hrsh7th/nvim-compe' - + -- Theme use 'drewtempelmeyer/palenight.vim' use 'kyazdani42/nvim-web-devicons' @@ -27,16 +28,27 @@ return require('packer').startup(function(use) use 'sheerun/vim-polyglot' use {'prettier/vim-prettier', run = "yarn install"} use {'styled-components/vim-styled-components', branch = "main"} - + -- FZF use '/usr/local/opt/fzf' use 'junegunn/fzf.vim' + use 'airblade/vim-rooter' use { 'nvim-telescope/telescope.nvim', requires = {{'nvim-lua/popup.nvim'}, {'nvim-lua/plenary.nvim'}} } + -- Git symobls. + use { + 'lewis6991/gitsigns.nvim', + requires = { + 'nvim-lua/plenary.nvim' + }, + config = function() + require('gitsigns').setup() + end + } use 'jiangmiao/auto-pairs' use 'itchyny/lightline.vim' diff --git a/lua/settings.lua b/lua/settings.lua index 69ed98c..83de9d0 100644 --- a/lua/settings.lua +++ b/lua/settings.lua @@ -1,2 +1,24 @@ -vim.api.nvim_set_option('signcolumn', 'yes') +-- Comes from the Chris@Machine config. + +vim.cmd('set iskeyword+=-') -- treat dash separated words as a word text object" +vim.o.hidden = true -- Required to keep multiple buffers open multiple buffers +vim.wo.wrap = false -- Display long lines as just one line +vim.o.fileencoding = "utf-8" -- The encoding written to file +vim.o.splitbelow = true -- Horizontal splits will automatically be below +vim.o.splitright = true -- Vertical splits will automatically be to the right +vim.o.conceallevel = 0 -- So that I can see `` in markdown files +vim.cmd('set ts=4') -- Insert 2 spaces for a tab +vim.cmd('set sw=4') -- Change the number of space characters inserted for indentation +vim.bo.expandtab = true -- Converts tabs to spaces +vim.bo.smartindent = true -- Makes indenting smart +vim.wo.number = true -- set numbered lines +vim.wo.cursorline = true -- Enable highlighting of the current line +--vim.o.showtabline = 2 -- Always show tabs +vim.o.showmode = false -- We don't need to see things like -- INSERT -- anymore +vim.o.backup = false -- This is recommended by coc +vim.o.writebackup = false -- This is recommended by coc +vim.wo.signcolumn = "yes" -- Always show the signcolumn, otherwise it would shift the text each time +vim.o.updatetime = 300 -- Faster completion +vim.o.timeoutlen = 500 -- By default timeoutlen is 1000 ms + vim.cmd(":set number relativenumber") diff --git a/plugin/packer_compiled.vim b/plugin/packer_compiled.vim new file mode 100644 index 0000000..84211a4 --- /dev/null +++ b/plugin/packer_compiled.vim @@ -0,0 +1,119 @@ +" Automatically generated packer.nvim plugin loader code + +if !has('nvim-0.5') + echohl WarningMsg + echom "Invalid Neovim version for packer.nvim!" + echohl None + finish +endif + +packadd packer.nvim + +try + +lua << END +local package_path_str = "/Users/marianouvalle/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?.lua;/Users/marianouvalle/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?/init.lua;/Users/marianouvalle/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?.lua;/Users/marianouvalle/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?/init.lua" +local install_cpath_pattern = "/Users/marianouvalle/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/?.so" +if not string.find(package.path, package_path_str, 1, true) then + package.path = package.path .. ';' .. package_path_str +end + +if not string.find(package.cpath, install_cpath_pattern, 1, true) then + package.cpath = package.cpath .. ';' .. install_cpath_pattern +end + +local function try_loadstring(s, component, name) + local success, result = pcall(loadstring(s)) + if not success then + print('Error running ' .. component .. ' for ' .. name) + error(result) + end + return result +end + +_G.packer_plugins = { + ["auto-pairs"] = { + loaded = true, + path = "/Users/marianouvalle/.local/share/nvim/site/pack/packer/start/auto-pairs" + }, + fzf = { + loaded = true, + path = "/Users/marianouvalle/.local/share/nvim/site/pack/packer/start/fzf" + }, + ["fzf.vim"] = { + loaded = true, + path = "/Users/marianouvalle/.local/share/nvim/site/pack/packer/start/fzf.vim" + }, + ["gitsigns.nvim"] = { + config = { "\27LJ\2\n6\0\0\3\0\3\0\0066\0\0\0'\2\1\0B\0\2\0029\0\2\0B\0\1\1K\0\1\0\nsetup\rgitsigns\frequire\0" }, + loaded = true, + path = "/Users/marianouvalle/.local/share/nvim/site/pack/packer/start/gitsigns.nvim" + }, + ["lightline.vim"] = { + loaded = true, + path = "/Users/marianouvalle/.local/share/nvim/site/pack/packer/start/lightline.vim" + }, + ["lspsaga.nvim"] = { + loaded = true, + path = "/Users/marianouvalle/.local/share/nvim/site/pack/packer/start/lspsaga.nvim" + }, + ["nvim-compe"] = { + loaded = true, + path = "/Users/marianouvalle/.local/share/nvim/site/pack/packer/start/nvim-compe" + }, + ["nvim-lspconfig"] = { + loaded = true, + path = "/Users/marianouvalle/.local/share/nvim/site/pack/packer/start/nvim-lspconfig" + }, + ["nvim-web-devicons"] = { + loaded = true, + path = "/Users/marianouvalle/.local/share/nvim/site/pack/packer/start/nvim-web-devicons" + }, + ["packer.nvim"] = { + loaded = true, + path = "/Users/marianouvalle/.local/share/nvim/site/pack/packer/start/packer.nvim" + }, + ["palenight.vim"] = { + loaded = true, + path = "/Users/marianouvalle/.local/share/nvim/site/pack/packer/start/palenight.vim" + }, + ["plenary.nvim"] = { + loaded = true, + path = "/Users/marianouvalle/.local/share/nvim/site/pack/packer/start/plenary.nvim" + }, + ["popup.nvim"] = { + loaded = true, + path = "/Users/marianouvalle/.local/share/nvim/site/pack/packer/start/popup.nvim" + }, + ["telescope.nvim"] = { + loaded = true, + path = "/Users/marianouvalle/.local/share/nvim/site/pack/packer/start/telescope.nvim" + }, + ["vim-polyglot"] = { + loaded = true, + path = "/Users/marianouvalle/.local/share/nvim/site/pack/packer/start/vim-polyglot" + }, + ["vim-prettier"] = { + loaded = true, + path = "/Users/marianouvalle/.local/share/nvim/site/pack/packer/start/vim-prettier" + }, + ["vim-rooter"] = { + loaded = true, + path = "/Users/marianouvalle/.local/share/nvim/site/pack/packer/start/vim-rooter" + }, + ["vim-styled-components"] = { + loaded = true, + path = "/Users/marianouvalle/.local/share/nvim/site/pack/packer/start/vim-styled-components" + } +} + +-- Config for: gitsigns.nvim +try_loadstring("\27LJ\2\n6\0\0\3\0\3\0\0066\0\0\0'\2\1\0B\0\2\0029\0\2\0B\0\1\1K\0\1\0\nsetup\rgitsigns\frequire\0", "config", "gitsigns.nvim") +END + +catch + echohl ErrorMsg + echom "Error in packer_compiled: " .. v:exception + echom "Please check your config for correctness" + echohl None +endtry