diff options
| author | William Boman <william@redwill.se> | 2021-04-04 18:33:40 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-04 18:33:40 +0200 |
| commit | 98cf5f41c9a925a92363d94a48776514510a83ff (patch) | |
| tree | 9a9e7dbd03ea2ef6c0b003335fc3d0bbac9b791d /lua | |
| parent | init (diff) | |
| download | mason-98cf5f41c9a925a92363d94a48776514510a83ff.tar mason-98cf5f41c9a925a92363d94a48776514510a83ff.tar.gz mason-98cf5f41c9a925a92363d94a48776514510a83ff.tar.bz2 mason-98cf5f41c9a925a92363d94a48776514510a83ff.tar.lz mason-98cf5f41c9a925a92363d94a48776514510a83ff.tar.xz mason-98cf5f41c9a925a92363d94a48776514510a83ff.tar.zst mason-98cf5f41c9a925a92363d94a48776514510a83ff.zip | |
update README and change get_installed_servers() return value (#1)
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-lsp-installer.lua | 13 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/installer.lua | 14 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/installers/typescript-ls.lua | 20 |
3 files changed, 38 insertions, 9 deletions
diff --git a/lua/nvim-lsp-installer.lua b/lua/nvim-lsp-installer.lua index 9febc675..76fd28d6 100644 --- a/lua/nvim-lsp-installer.lua +++ b/lua/nvim-lsp-installer.lua @@ -2,11 +2,22 @@ local installer = require('nvim-lsp-installer.installer') local M = {} -M.get_server_installer = installer.get_server_installer M.get_available_servers = installer.get_available_servers M.get_installed_servers = installer.get_installed_servers M.get_uninstalled_servers = installer.get_uninstalled_servers M.install = installer.install M.uninstall = installer.uninstall +function M.get_installer(server, only_installed) + only_installed = only_installed ~= nil and only_installed or false + local pool = only_installed and installer.get_installed_servers() or installer.get_available_servers() + + for _, server_installer in pairs(pool) do + if server_installer.name == server then + return server_installer + end + end + return nil +end + return M diff --git a/lua/nvim-lsp-installer/installer.lua b/lua/nvim-lsp-installer/installer.lua index 765b0985..d0acd8cf 100644 --- a/lua/nvim-lsp-installer/installer.lua +++ b/lua/nvim-lsp-installer/installer.lua @@ -19,7 +19,7 @@ local function escape_quotes(str) return string.format("%q", str) end -function M.get_server_installer(server) +local function get_server_installer(server) return require('nvim-lsp-installer.installers.' .. server) end @@ -28,9 +28,9 @@ function M.get_available_servers() return _INSTALLERS end function M.get_installed_servers() local installed_servers = {} for _, server in ipairs(M.get_available_servers()) do - local module = M.get_server_installer(server) + local module = get_server_installer(server) if os.execute('test -d ' .. escape_quotes(module.root_dir)) == 0 then - table.insert(installed_servers, server) + table.insert(installed_servers, module) end end return installed_servers @@ -47,7 +47,7 @@ function M.get_uninstalled_servers() end local function _uninstall(server) - local installer = M.get_server_installer(server) + local installer = get_server_installer(server) -- giggity if os.execute('rm -rf ' .. escape_quotes(installer.root_dir)) ~= 0 then @@ -56,7 +56,7 @@ local function _uninstall(server) end local function _install(server) - local installer = M.get_server_installer(server) + local installer = get_server_installer(server) if installer.pre_install then installer.pre_install() @@ -118,10 +118,14 @@ end function M.create_lsp_config_installer(module) return { + name = module.name, install_cmd = module.install_cmd, root_dir = module.root_dir, pre_install = module.pre_install, setup = function(opts) + -- We require the lspconfig server here in order to do it as late as possible. + -- The reason for this is because once a lspconfig server has been imported, it's + -- automatically registered with lspconfig and causes it to show up in :LspInfo and whatnot. require'lspconfig'[module.name].setup( vim.tbl_deep_extend('force', module.default_options, opts) ) diff --git a/lua/nvim-lsp-installer/installers/typescript-ls.lua b/lua/nvim-lsp-installer/installers/typescript-ls.lua index c8b2c03e..eef82503 100644 --- a/lua/nvim-lsp-installer/installers/typescript-ls.lua +++ b/lua/nvim-lsp-installer/installers/typescript-ls.lua @@ -16,8 +16,8 @@ return installer.create_lsp_config_installer { local old_uri = vim.uri_from_fname(old) local new_uri = vim.uri_from_fname(new) - -- maybe filter by client name, only send to tsserver? - for _, client in ipairs(vim.lsp.get_active_clients()) do + -- TODO: send only to tsserver + for _, client in pairs(vim.lsp.get_active_clients()) do client.request( 'workspace/executeCommand', { @@ -31,6 +31,20 @@ return installer.create_lsp_config_installer { } ) end - end + end, + organize_imports = function(bufname) + bufname = bufname or vim.api.nvim_buf_get_name(0) + + -- TODO: send only to tsserver + for _, client in pairs(vim.lsp.get_active_clients()) do + client.request( + 'workspace/executeCommand', + { + command = '_typescript.organizeImports', + arguments = {bufname}, + } + ) + end + end, } } |
