better lsp handling + utility to only check mason if not found locally installed

pull/1705/head
peturparkur 1 year ago
parent 33554a5315
commit 7db85cf0ae

@ -211,19 +211,19 @@ return {
local servers = { local servers = {
-- clangd = {}, -- clangd = {},
-- gopls = {}, -- gopls = {},
-- pyright = { pyright = {
-- settings = { settings = {
-- python = { python = {
-- analysis = { analysis = {
-- autoSearchPaths = true, autoSearchPaths = true,
-- diagnosticMode = 'workspace', diagnosticMode = 'workspace',
-- useLibraryCodeForTypes = true, useLibraryCodeForTypes = true,
-- autoImportCompletions = true, autoImportCompletions = true,
-- }, },
-- }, },
-- }, },
-- disableLanguageServices = false, disableLanguageServices = false,
-- }, },
basedpyright = { basedpyright = {
settings = { settings = {
basedpyright = { basedpyright = {
@ -255,11 +255,15 @@ return {
-- But for many setups, the LSP (`tsserver`) will work just fine -- But for many setups, the LSP (`tsserver`) will work just fine
-- tsserver = {}, -- tsserver = {},
-- --
nixd = {},
bashls = {
alias = 'bash-language-server',
},
lua_ls = { lua_ls = {
-- cmd = {...}, -- cmd = {...},
-- filetypes = { ...}, -- filetypes = { ...},
-- capabilities = {}, -- capabilities = {},
alias = 'lua-language-server',
settings = { settings = {
Lua = { Lua = {
completion = { completion = {
@ -289,16 +293,28 @@ return {
-- require('mason-tool-installer').setup { ensure_installed = ensure_installed } -- require('mason-tool-installer').setup { ensure_installed = ensure_installed }
-- INFO: Using my own utils function instead of mason-lspconfig as it checks if the stuff is already installed -- INFO: Using my own utils function instead of mason-lspconfig as it checks if the stuff is already installed
-- outside of mason. This is useful for NixOS setup where mason version just doesn't work sometimes due to libc issues. -- outside of mason. This is useful for NixOS setup where mason version just doesn't work sometimes due to libc issues.
require('utils.mason').install { local installed = {}
-- "python-lsp-server", local i = 0
'pyright', for server, config in pairs(servers) do
'basedpyright', if config.alias then
'bash-language-server', installed[i] = config.alias
-- "rnix-lsp", else
'lua-language-server', installed[i] = server
-- "docker-compose-language-service", end
-- "nil", i = i + 1
} end
table.insert(installed, 'stylua')
require('utils.mason').install(installed)
-- require('utils.mason').install {
-- -- "python-lsp-server",
-- 'pyright',
-- 'basedpyright',
-- 'bash-language-server',
-- -- "rnix-lsp",
-- 'lua-language-server',
-- -- "docker-compose-language-service",
-- -- "nil",
-- }
local lsp = require 'lspconfig' local lsp = require 'lspconfig'

@ -2,34 +2,36 @@ local M = {}
-- any cases where name of package is different from the binary name -- any cases where name of package is different from the binary name
local name_to_bin = { local name_to_bin = {
["csharp-language-server"] = "csharp-ls", ['csharp-language-server'] = 'csharp-ls',
["python-lsp-server"] = "pylsp", ['python-lsp-server'] = 'pylsp',
["docker-compose-language-service"] = "docker-compose-langserver", ['docker-compose-language-service'] = 'docker-compose-langserver',
} }
M.install = function(ensure_installed) M.install = function(ensure_installed)
-- Allow for passing in a single string -- Allow for passing in a single string
if type(ensure_installed) == "string" then if type(ensure_installed) == 'string' then
ensure_installed = { ensure_installed } ensure_installed = { ensure_installed }
end end
-- Function to check if the executable exists in the PATH -- Function to check if the executable exists in the PATH
local function executable_exists(name) local function executable_exists(name)
if name_to_bin[name] then if name_to_bin[name] then
return vim.fn.executable(name) == 1 or vim.fn.executable(name_to_bin[name]) == 1 return vim.fn.executable(name_to_bin[name]) == 1
end end
return vim.fn.executable(name) == 1 return vim.fn.executable(name) == 1
end end
local registry = require("mason-registry") local registry = require 'mason-registry'
registry.refresh(function() registry.refresh(function()
for _, pkg_name in ipairs(ensure_installed) do for _, pkg_name in ipairs(ensure_installed) do
local pkg = registry.get_package(pkg_name) if not executable_exists(pkg_name) then
if not executable_exists(pkg_name) and not pkg:is_installed() then local pkg = registry.get_package(pkg_name)
pkg:install() if not pkg:is_installed() then
end pkg:install()
end end
end) end
end
end)
end end
return M return M
Loading…
Cancel
Save