From 3f99900ede573e56530610d977dedc63150e5213 Mon Sep 17 00:00:00 2001 From: peturparkur Date: Wed, 19 Jun 2024 10:02:57 +0100 Subject: [PATCH] add mason util and lsp changes for current state --- lua/kickstart/plugins/lsp.lua | 75 +++++++++++++++++++++++++++-------- lua/utils/mason.lua | 35 ++++++++++++++++ 2 files changed, 94 insertions(+), 16 deletions(-) create mode 100644 lua/utils/mason.lua diff --git a/lua/kickstart/plugins/lsp.lua b/lua/kickstart/plugins/lsp.lua index 681b5dea..5765b080 100644 --- a/lua/kickstart/plugins/lsp.lua +++ b/lua/kickstart/plugins/lsp.lua @@ -1,4 +1,6 @@ -return { -- LSP Configuration & Plugins +return { + { + -- LSP Configuration & Plugins 'neovim/nvim-lspconfig', dependencies = { -- Automatically install LSPs and related tools to stdpath for Neovim @@ -157,21 +159,31 @@ return { -- LSP Configuration & Plugins local servers = { -- clangd = {}, -- gopls = {}, - pyright = {}, - pylsp = { - on_attach = on_attach, - capabilities = capabilities, - settings = { - pylsp = { - plugins = { - pycodestyle = { - ignore = {}, - maxLineLength = 120, - }, - }, - }, + pyright = { + settings = { + python = { + analysis = { + autoSearchPaths = true, + diagnosticMode = 'workspace', + useLibraryCodeForTypes = true, + autoImportCompletions = true, + }, }, + }, + disableLanguageServices = false, }, + -- pylsp = { + -- settings = { + -- pylsp = { + -- plugins = { + -- pycodestyle = { + -- ignore = {}, + -- maxLineLength = 120, + -- }, + -- }, + -- } + -- } + -- }, -- rust_analyzer = {}, -- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs -- @@ -212,7 +224,18 @@ return { -- LSP Configuration & Plugins vim.list_extend(ensure_installed, { 'stylua', -- Used to format Lua code }) - 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 + -- 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', + 'bash-language-server', + -- "rnix-lsp", + 'lua-language-server', + -- "docker-compose-language-service", + -- "nil", + } require('mason-lspconfig').setup { handlers = { @@ -227,4 +250,24 @@ return { -- LSP Configuration & Plugins }, } end, -} \ No newline at end of file + }, + -- Show LSP explorer of functions and classes etc. + { + 'hedyhli/outline.nvim', + lazy = true, + cmd = { 'Outline', 'OutlineOpen' }, + keys = { -- Example mapping to toggle outline + { 'o', 'Outline', desc = 'Toggle outline' }, + }, + opts = {}, + }, + + -- Shows where you are in the file LSP wise (which class/function etc) + { + 'ray-x/lsp_signature.nvim', + event = 'VeryLazy', + config = function(_, opts) + require('lsp_signature').setup(opts) + end, + }, +} diff --git a/lua/utils/mason.lua b/lua/utils/mason.lua new file mode 100644 index 00000000..f4ca5d0d --- /dev/null +++ b/lua/utils/mason.lua @@ -0,0 +1,35 @@ +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", +} + +M.install = function(ensure_installed) + -- 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 + + 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) +end + +return M \ No newline at end of file