feat: install plugin lspinstaller
This commit is contained in:
parent
7459b2c0f7
commit
7f07f9707e
@ -1,10 +1,11 @@
|
|||||||
local lspconfig = require('lspconfig')
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
-- debounce_text_changes = delay, between changing something and lsp updating
|
-- debounce_text_changes = delay, between changing something and lsp updating
|
||||||
M.flags = { debounce_text_changes = 150 }
|
M.flags = { debounce_text_changes = 150 }
|
||||||
|
|
||||||
M.default_settings = {
|
local general_settings = { }
|
||||||
|
M.server_settings = {
|
||||||
|
sumneko_lua = {
|
||||||
Lua = {
|
Lua = {
|
||||||
runtime = {
|
runtime = {
|
||||||
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
|
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
|
||||||
@ -23,11 +24,17 @@ M.default_settings = {
|
|||||||
telemetry = { enable = false }
|
telemetry = { enable = false }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Apply general settings for each server
|
||||||
|
for _, settings in ipairs(M.server_settings) do
|
||||||
|
M.server_settings = vim.tbl_deep_extend("keep", settings, general_settings)
|
||||||
|
end
|
||||||
|
|
||||||
-- Use an on_attach function to only map the following keys
|
-- Use an on_attach function to only map the following keys
|
||||||
-- after the language server attaches to the current buffer
|
-- after the language server attaches to the current buffer
|
||||||
---@diagnostic disable-next-line: unused-local
|
---@diagnostic disable-next-line: unused-local
|
||||||
local function on_attach(client, bufnr)
|
function M.on_attach(client, bufnr)
|
||||||
-- Mappings.
|
-- Mappings.
|
||||||
local opts = { noremap = true, silent = true }
|
local opts = { noremap = true, silent = true }
|
||||||
|
|
||||||
@ -43,7 +50,10 @@ local function on_attach(client, bufnr)
|
|||||||
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>')
|
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>')
|
||||||
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>')
|
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>')
|
||||||
buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>')
|
buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>')
|
||||||
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>')
|
|
||||||
|
-- Conflicts with movement between panes
|
||||||
|
-- buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>')
|
||||||
|
|
||||||
-- buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>')
|
-- buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>')
|
||||||
-- buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>')
|
-- buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>')
|
||||||
-- buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>')
|
-- buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>')
|
||||||
@ -62,64 +72,28 @@ local function on_attach(client, bufnr)
|
|||||||
-- autocmd BufWritePre *.py lua vim.lsp.buf.formatting_sync(nil, 100)
|
-- autocmd BufWritePre *.py lua vim.lsp.buf.formatting_sync(nil, 100)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.get_capabilities()
|
||||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||||
|
|
||||||
if packer_plugins['cmp-nvim-lsp'] and packer_plugins['cmp-nvim-lsp'].loaded then
|
if packer_plugins['cmp-nvim-lsp'] and packer_plugins['cmp-nvim-lsp'].loaded then
|
||||||
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
|
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_init(initialize_params, config)
|
return capabilities
|
||||||
-- print(vim.inspect(capabilities))
|
|
||||||
-- print(vim.inspect(config))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- https://github.com/sumneko/lua-language-server/wiki/Build-and-Run-(Standalone)
|
function M.on_init(initialize_params, config)
|
||||||
local function getSumnekoPaths()
|
-- print("lsp init")
|
||||||
USER = vim.fn.expand('$USER')
|
|
||||||
|
|
||||||
if vim.fn.has("mac") == 1 then
|
|
||||||
local sumneko_root_path = "/Users/" .. USER .. "/.config/nvim/lua-language-server"
|
|
||||||
local sumneko_binary = "/Users/" .. USER .. "/.config/nvim/lua-language-server/bin/macOS/lua-language-server"
|
|
||||||
return sumneko_root_path, sumneko_binary
|
|
||||||
elseif vim.fn.has("unix") == 1 then
|
|
||||||
local sumneko_root_path = "/home/" .. USER .. "/.config/nvim/lua-language-server"
|
|
||||||
local sumneko_binary = "/home/" .. USER .. "/.config/nvim/lua-language-server/bin/Linux/lua-language-server"
|
|
||||||
return sumneko_root_path, sumneko_binary
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function setupLuaServer()
|
function M.get_server_settings(name)
|
||||||
local sumneko_root_path, sumneko_binary = getSumnekoPaths()
|
return M.server_settings[name]
|
||||||
|
|
||||||
if not sumneko_root_path then
|
|
||||||
print("Unsupported system for sumneko")
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
lspconfig.sumneko_lua.setup {
|
---@diagnostic disable-next-line: empty-block
|
||||||
cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"},
|
if packer_plugins['nvim-lsp-installer'] and packer_plugins['nvim-lsp-installer'].loaded then
|
||||||
on_attach = on_attach,
|
-- local lspconfig = require('lspconfig')
|
||||||
filetypes = {"lua"},
|
-- TODO: Manually do "server:setup{}" if lspinstaller is not loaded
|
||||||
capabilities = capabilities,
|
|
||||||
on_init = on_init,
|
|
||||||
flags = M.flags,
|
|
||||||
settings = M.default_settings
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
setupLuaServer()
|
|
||||||
|
|
||||||
-- Use a loop to conveniently call 'setup' on multiple servers and
|
|
||||||
-- map buffer local keybindings when the language server attaches
|
|
||||||
local servers = { 'tsserver' }
|
|
||||||
for _, name in ipairs(servers) do
|
|
||||||
lspconfig[name].setup {
|
|
||||||
on_attach = on_attach,
|
|
||||||
capabilities = capabilities,
|
|
||||||
on_init = on_init,
|
|
||||||
flags = M.flags,
|
|
||||||
settings = M.default_settings
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
27
lua/config/lspinstaller.lua
Normal file
27
lua/config/lspinstaller.lua
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
local lspconfig_config = require 'config.lspconfig'
|
||||||
|
local lsp_instller = require 'nvim-lsp-installer'
|
||||||
|
local lsp_installer_servers = require'nvim-lsp-installer.servers'
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
local autoinstall_servers = {"sumneko_lua"}
|
||||||
|
for _, name in ipairs(autoinstall_servers) do
|
||||||
|
local ok, server = lsp_installer_servers.get_server(name)
|
||||||
|
if ok and not server:is_installed() then
|
||||||
|
server:install()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local capabilities = lspconfig_config.get_capabilities()
|
||||||
|
|
||||||
|
lsp_instller.on_server_ready(function(server)
|
||||||
|
server:setup{
|
||||||
|
on_attach = lspconfig_config.on_attach,
|
||||||
|
on_init = lspconfig_config.on_init,
|
||||||
|
flags = lspconfig_config.flags,
|
||||||
|
capabilities = capabilities,
|
||||||
|
settings = lspconfig_config.get_server_settings(server.name)
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
|
||||||
|
return M
|
||||||
|
|
@ -80,6 +80,11 @@ local function usePlugins(use)
|
|||||||
'neovim/nvim-lspconfig',
|
'neovim/nvim-lspconfig',
|
||||||
config = [[require 'config.lspconfig']],
|
config = [[require 'config.lspconfig']],
|
||||||
}
|
}
|
||||||
|
use {
|
||||||
|
'williamboman/nvim-lsp-installer',
|
||||||
|
requires = 'neovim/nvim-lspconfig',
|
||||||
|
config = [[require 'config.lspinstaller']]
|
||||||
|
}
|
||||||
|
|
||||||
-- Completion
|
-- Completion
|
||||||
use { 'onsails/lspkind-nvim' }
|
use { 'onsails/lspkind-nvim' }
|
||||||
|
Loading…
Reference in New Issue
Block a user