feat: install plugin lspinstaller
This commit is contained in:
parent
7459b2c0f7
commit
7f07f9707e
@ -1,33 +1,40 @@
|
||||
local lspconfig = require('lspconfig')
|
||||
local M = {}
|
||||
|
||||
-- debounce_text_changes = delay, between changing something and lsp updating
|
||||
M.flags = { debounce_text_changes = 150 }
|
||||
|
||||
M.default_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', 'packer_plugins'}
|
||||
},
|
||||
workspace = {
|
||||
-- Make the server aware of Neovim runtime files
|
||||
library = vim.api.nvim_get_runtime_file("", true)
|
||||
},
|
||||
telemetry = { enable = false }
|
||||
local general_settings = { }
|
||||
M.server_settings = {
|
||||
sumneko_lua = {
|
||||
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', 'packer_plugins'}
|
||||
},
|
||||
workspace = {
|
||||
-- Make the server aware of Neovim runtime files
|
||||
library = vim.api.nvim_get_runtime_file("", true)
|
||||
},
|
||||
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
|
||||
-- after the language server attaches to the current buffer
|
||||
---@diagnostic disable-next-line: unused-local
|
||||
local function on_attach(client, bufnr)
|
||||
function M.on_attach(client, bufnr)
|
||||
-- Mappings.
|
||||
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', 'gi', '<cmd>lua vim.lsp.buf.implementation()<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>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>')
|
||||
@ -62,64 +72,28 @@ local function on_attach(client, bufnr)
|
||||
-- autocmd BufWritePre *.py lua vim.lsp.buf.formatting_sync(nil, 100)
|
||||
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
|
||||
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
|
||||
end
|
||||
|
||||
local function on_init(initialize_params, config)
|
||||
-- print(vim.inspect(capabilities))
|
||||
-- print(vim.inspect(config))
|
||||
end
|
||||
|
||||
-- https://github.com/sumneko/lua-language-server/wiki/Build-and-Run-(Standalone)
|
||||
local function getSumnekoPaths()
|
||||
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
|
||||
|
||||
local function setupLuaServer()
|
||||
local sumneko_root_path, sumneko_binary = getSumnekoPaths()
|
||||
|
||||
if not sumneko_root_path then
|
||||
print("Unsupported system for sumneko")
|
||||
return
|
||||
if packer_plugins['cmp-nvim-lsp'] and packer_plugins['cmp-nvim-lsp'].loaded then
|
||||
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
|
||||
end
|
||||
|
||||
lspconfig.sumneko_lua.setup {
|
||||
cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"},
|
||||
on_attach = on_attach,
|
||||
filetypes = {"lua"},
|
||||
capabilities = capabilities,
|
||||
on_init = on_init,
|
||||
flags = M.flags,
|
||||
settings = M.default_settings
|
||||
}
|
||||
return capabilities
|
||||
end
|
||||
|
||||
setupLuaServer()
|
||||
function M.on_init(initialize_params, config)
|
||||
-- print("lsp init")
|
||||
end
|
||||
|
||||
-- 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
|
||||
}
|
||||
function M.get_server_settings(name)
|
||||
return M.server_settings[name]
|
||||
end
|
||||
|
||||
---@diagnostic disable-next-line: empty-block
|
||||
if packer_plugins['nvim-lsp-installer'] and packer_plugins['nvim-lsp-installer'].loaded then
|
||||
-- local lspconfig = require('lspconfig')
|
||||
-- TODO: Manually do "server:setup{}" if lspinstaller is not loaded
|
||||
end
|
||||
|
||||
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',
|
||||
config = [[require 'config.lspconfig']],
|
||||
}
|
||||
use {
|
||||
'williamboman/nvim-lsp-installer',
|
||||
requires = 'neovim/nvim-lspconfig',
|
||||
config = [[require 'config.lspinstaller']]
|
||||
}
|
||||
|
||||
-- Completion
|
||||
use { 'onsails/lspkind-nvim' }
|
||||
|
Loading…
Reference in New Issue
Block a user