Adds lsp configuration and servers for go, elixir, typescript and python

This commit is contained in:
Mariano Uvalle 2021-06-21 19:57:46 -05:00
parent e042914777
commit 35d7f6d756
13 changed files with 313 additions and 35 deletions

6
elixir-ls.lua Normal file
View file

@ -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};
}

View file

@ -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')

8
lua/lsp/elixir-ls.lua Normal file
View file

@ -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()')

46
lua/lsp/go-ls.lua Normal file
View file

@ -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)")

View file

@ -3,9 +3,5 @@ vim.cmd('nnoremap <silent> gD <cmd>lua vim.lsp.buf.declaration()<CR>')
vim.cmd('nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>')
vim.cmd('nnoremap <silent> gi <cmd>lua vim.lsp.buf.implementation()<CR>')
vim.api.nvim_set_keymap('n', '<Leader>lr', '<cmd>lua vim.lsp.buf.rename()<CR>', {noremap = true, silent = true})
vim.cmd('nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR>')
-- scroll down hover doc or scroll in definition preview
vim.cmd('nnoremap <silent> <C-f> <cmd>lua require(\'lspsaga.action\').smart_scroll_with_saga(1)<CR>')
-- scroll up hover doc
vim.cmd('nnoremap <silent> <C-b> <cmd>lua require(\'lspsaga.action\').smart_scroll_with_saga(-1)<CR>')

37
lua/lsp/lua-ls.lua Normal file
View file

@ -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}
}
}
}
}

View file

@ -1,2 +1,4 @@
require'lspconfig'.pyright.setup{}
require'lspconfig'.pyright.setup{
cmd = {DATA_PATH .. "/lspinstall/python/node_modules/.bin/pyright-langserver", "--stdio"},
}

View file

@ -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")
}

View file

@ -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 "<C-n>"
-- else
-- return t "<Tab>"
-- end
--end
--_G.tab_complete = function()
-- if vim.fn.pumvisible() == 1 then
-- return t "<C-n>"
-- elseif vim.fn.call("vsnip#available", {1}) == 1 then
-- return t "<Plug>(vsnip-expand-or-jump)"
-- elseif check_back_space() then
-- return t "<Tab>"
-- else
-- return vim.fn['compe#complete']()
-- end
--end
--_G.s_tab_complete = function()
-- if vim.fn.pumvisible() == 1 then
-- return t "<C-p>"
-- elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then
-- return t "<Plug>(vsnip-jump-prev)"
-- else
-- return t "<S-Tab>"
-- end
--end
_G.comp_jump_if_avail = function()
if vim.fn.pumvisible() == 1 then
return t "<C-n>"
else
return t "<Tab>"
end
end
_G.comp_jump_prev_if_avail = function()
if vim.fn.pumvisible() == 1 then
return t "<C-p>"
end
end
_G.tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-n>"
elseif vim.fn.call("vsnip#available", {1}) == 1 then
return t "<Plug>(vsnip-expand-or-jump)"
elseif check_back_space() then
return vim.fn['compe#confirm']('')
else
return t "<Tab>"
else
return vim.fn['compe#complete']()
end
end
_G.s_tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-p>"
elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then
return t "<Plug>(vsnip-jump-prev)"
else
return t "<S-Tab>"
end
end
vim.api.nvim_set_keymap("i", "<C-j>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("s", "<C-j>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete_only()", {expr = true})
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete_only()", {expr = true})
vim.api.nvim_set_keymap("i", "<C-k>", "v:lua.s_tab_complete()", {expr = true})
vim.api.nvim_set_keymap("s", "<C-k>", "v:lua.s_tab_complete()", {expr = true})
vim.api.nvim_set_keymap("i", "<C-j>", "v:lua.comp_jump_if_avail()", {expr = true})
vim.api.nvim_set_keymap("s", "<C-j>", "v:lua.comp_jump_if_avail()", {expr = true})
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("i", "<C-k>", "v:lua.comp_jump_prev_if_avail()", {expr = true})
vim.api.nvim_set_keymap("s", "<C-k>", "v:lua.comp_jump_prev_if_avail()", {expr = true})

2
lua/nv-globals.lua Normal file
View file

@ -0,0 +1,2 @@
DATA_PATH = vim.fn.stdpath('data')
CACHE_PATH = vim.fn.stdpath('cache')

View file

@ -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'

View file

@ -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")

119
plugin/packer_compiled.vim Normal file
View file

@ -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