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 = {
-- clangd = {},
-- gopls = {},
-- pyright = {
-- settings = {
-- python = {
-- analysis = {
-- autoSearchPaths = true,
-- diagnosticMode = 'workspace',
-- useLibraryCodeForTypes = true,
-- autoImportCompletions = true,
-- },
-- },
-- },
-- disableLanguageServices = false,
-- },
pyright = {
settings = {
python = {
analysis = {
autoSearchPaths = true,
diagnosticMode = 'workspace',
useLibraryCodeForTypes = true,
autoImportCompletions = true,
},
},
},
disableLanguageServices = false,
},
basedpyright = {
settings = {
basedpyright = {
@ -255,11 +255,15 @@ return {
-- But for many setups, the LSP (`tsserver`) will work just fine
-- tsserver = {},
--
nixd = {},
bashls = {
alias = 'bash-language-server',
},
lua_ls = {
-- cmd = {...},
-- filetypes = { ...},
-- capabilities = {},
alias = 'lua-language-server',
settings = {
Lua = {
completion = {
@ -289,16 +293,28 @@ return {
-- 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
-- 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 {
-- "python-lsp-server",
'pyright',
'basedpyright',
'bash-language-server',
-- "rnix-lsp",
'lua-language-server',
-- "docker-compose-language-service",
-- "nil",
}
local installed = {}
local i = 0
for server, config in pairs(servers) do
if config.alias then
installed[i] = config.alias
else
installed[i] = server
end
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'

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

Loading…
Cancel
Save