diff options
| author | Elvis Claros Castro <elvis@claros.ar> | 2024-07-12 11:18:14 -0300 |
|---|---|---|
| committer | Elvis Claros Castro <elvis@claros.ar> | 2024-07-12 11:18:14 -0300 |
| commit | ea0f4bf8ffade657b1d45152dbc183d4679e75c4 (patch) | |
| tree | cc1fb023bc308e019ddce33a4b0aed39f56805dc /lua/pi/lsp | |
| parent | 1fd0af14d592d612c2aaab7717c04c8806ba3daa (diff) | |
| download | nvim-conf-ea0f4bf8ffade657b1d45152dbc183d4679e75c4.tar.gz nvim-conf-ea0f4bf8ffade657b1d45152dbc183d4679e75c4.zip | |
Feat: PI
Diffstat (limited to 'lua/pi/lsp')
| -rw-r--r-- | lua/pi/lsp/attach.lua | 29 | ||||
| -rw-r--r-- | lua/pi/lsp/default.lua | 30 | ||||
| -rw-r--r-- | lua/pi/lsp/flags.lua | 3 | ||||
| -rw-r--r-- | lua/pi/lsp/init.lua | 65 | ||||
| -rw-r--r-- | lua/pi/lsp/mason.lua | 23 | ||||
| -rw-r--r-- | lua/pi/lsp/null-ls.lua | 53 | ||||
| -rw-r--r-- | lua/pi/lsp/servers/emmet_ls.lua | 12 | ||||
| -rw-r--r-- | lua/pi/lsp/servers/html.lua | 14 | ||||
| -rw-r--r-- | lua/pi/lsp/servers/jsonls.lua | 14 | ||||
| -rw-r--r-- | lua/pi/lsp/servers/kotlin_language_server.lua | 12 | ||||
| -rw-r--r-- | lua/pi/lsp/servers/lua_ls.lua | 36 | ||||
| -rw-r--r-- | lua/pi/lsp/servers/phpactor.lua | 80 | ||||
| -rw-r--r-- | lua/pi/lsp/servers/python.lua | 16 | ||||
| -rw-r--r-- | lua/pi/lsp/servers/rust_analyzer.lua | 24 | ||||
| -rw-r--r-- | lua/pi/lsp/servers/texlab.lua | 16 | ||||
| -rw-r--r-- | lua/pi/lsp/servers/tsserver.lua | 33 | ||||
| -rw-r--r-- | lua/pi/lsp/servers/vscode_smarty_langserver.lua | 25 | ||||
| -rw-r--r-- | lua/pi/lsp/tools.lua | 8 |
18 files changed, 493 insertions, 0 deletions
diff --git a/lua/pi/lsp/attach.lua b/lua/pi/lsp/attach.lua new file mode 100644 index 0000000..7c28494 --- /dev/null +++ b/lua/pi/lsp/attach.lua @@ -0,0 +1,29 @@ +local telescope_mapper = require "pi.telescope.mappings" + +return function(client, bufnr) + -- keymaps for lsp + vim.keymap.set("n", "K", vim.lsp.buf.hover, { buffer = 0, desc = "LSP Help information of symbol under the cursor" }) + vim.keymap.set("n", "<leader>vrn", vim.lsp.buf.rename, { buffer = 0, desc = "LSP Rename symbol under cursor" }) + vim.keymap.set("i", "<c-h>", vim.lsp.buf.signature_help, { buffer = 0, desc = "LSP Signature help" }) + vim.keymap.set("n", "<leader>vo", ":LspRestart<cr>", { noremap = true, desc = "LSP Restart Server" }) + vim.keymap.set({ "n", "v" }, "<leader>vca", vim.lsp.buf.code_action, { buffer = 0, desc = "LSP Code actions" }) + vim.keymap.set("n", "<leader>vf", function() + return vim.lsp.buf.format { + async = true, + filter = function(cli) + return cli.name ~= "lua_ls" + end, + } + end, { buffer = 0, desc = "LSP format file" }) + + telescope_mapper("gr", "lsp_references", { buffer = true, desc = "LSP References of symbol on cursor" }) + telescope_mapper("<leader>pv", "find_symbol", { buffer = true, desc = "LSP find symbol on the project" }) + telescope_mapper("<leader>pd", "lsp_document_symbols", { buffer = true, desc = "LSP document symbols" }) + telescope_mapper("gd", "lsp_definitions", { buffer = true, desc = "LSP go to definition" }) + + vim.bo.omnifunc = "v:lua.vim.lsp.omnifunc" + + if client.server_capabilities.inlayHintProvider then + vim.lsp.inlay_hint.enable(bufnr) + end +end diff --git a/lua/pi/lsp/default.lua b/lua/pi/lsp/default.lua new file mode 100644 index 0000000..1405a72 --- /dev/null +++ b/lua/pi/lsp/default.lua @@ -0,0 +1,30 @@ +return { + mason = { + enable = true, + auto_install = false, + }, + servers = { + emmet_ls = { enable = true }, + gopls = { enable = true }, + html = { enable = true }, + jsonls = { enable = true }, + lua_ls = { enable = true, neodev = true }, + nil_ls = { enable = true }, + phpactor = {enable = true }, + rust_analyzer = { enable = true }, + svelte = { enable = true }, + tailwindcss = { enable = true, filetypes = {"blade", "html", "svelte"} }, + tsserver = { enable = true }, + volar = { enable = true }, + texlab = { enable = true, filetypes = {"tex", "bib"} }, + pyright = { enable = true, filetypes = {"python"} }, + kotlin_language_server = { enable = true, filetypes = {"kotlin"}, root_dir = require("lspconfig.util").root_pattern("build.gradle.kts", "pom.xml", ".git") }, + smarty_ls = { enable = true, filetypes = {"smarty"}, root_dir = require("lspconfig.util").root_pattern("composer.json", ".git") }, + }, + default_options = function (options) + return vim.tbl_deep_extend("force", { + on_attach = require"pi.lsp.attach", + flags = require "pi.lsp.flags", + }, options) + end, +} diff --git a/lua/pi/lsp/flags.lua b/lua/pi/lsp/flags.lua new file mode 100644 index 0000000..f70b467 --- /dev/null +++ b/lua/pi/lsp/flags.lua @@ -0,0 +1,3 @@ +return { + debounce_text_changes = 150, +} diff --git a/lua/pi/lsp/init.lua b/lua/pi/lsp/init.lua new file mode 100644 index 0000000..4454639 --- /dev/null +++ b/lua/pi/lsp/init.lua @@ -0,0 +1,65 @@ +return { + setup = function(ops) + ops = vim.tbl_deep_extend("force", require "pi.lsp.default", ops) + + local lspconfig = require "lspconfig" + + local mason_servers = {} + for server, options in pairs(ops.servers) do + if options.enable == true then + local ok, definition = pcall(require, "pi.lsp.servers." .. server) + local server_options + if not ok then + server_options = ops.default_options(options) + else + server_options = definition(options) + end + lspconfig[server].setup(server_options) + table.insert(mason_servers, server) + end + end + + -- Mason + if ops.mason.enable then + local mason_ops = {} + if ops.mason.auto_install == true then + mason_ops.ensure_installed = mason_servers + end + local mason_lspconfig = require "mason-lspconfig" + mason_lspconfig.setup(mason_ops) + end + + -- TODO: implement null ls with options + require "pi.lsp.null-ls" + + local servers = {} + for server, options in pairs(ops.servers) do + table.insert(servers, string.format("%s <%s>", server, options.enable)) + end + + -- TODO: create an auto command that on write of the configuration, calls again the setup and restart the server if it's up. + -- can get the client by name of the file + + vim.api.nvim_create_user_command("AlphaLSP", function() + vim.ui.select(servers, { prompt = "LSP Servers" }, function(server) + if server == nil then + return + end + + server = string.match(server, "^(.+) <") + local path = string.format("%s/lua/pi/lsp/servers/%s.lua", vim.fn.stdpath "config", server) + if vim.fn.filereadable(path) == 0 then + local create = vim.fn.confirm("Server Does Not exist. Create new server?", "&Yes\n&No\n&Cancel") + if create ~= 1 then + return + end + end + + local uri = vim.uri_from_fname(path) + local buffer = vim.uri_to_bufnr(uri) + + vim.api.nvim_win_set_buf(0, buffer) + end) + end, {}) + end, +} diff --git a/lua/pi/lsp/mason.lua b/lua/pi/lsp/mason.lua new file mode 100644 index 0000000..91d0c2b --- /dev/null +++ b/lua/pi/lsp/mason.lua @@ -0,0 +1,23 @@ +local mason_lspconfig = require "mason-lspconfig" +local servers = require "pi.lsp.servers" +local lspconfig = require "lspconfig" + +local mason_servers = {} + +for server, _ in pairs(servers) do + local cmd = lspconfig[server].cmd[1] + if vim.fn.executable(cmd) == 0 then + table.insert(mason_servers, server) + end +end + +mason_lspconfig.setup { + -- ensure_installed = mason_servers, +} + +-- filter the list for the ones not globally installed +-- require("mason-tool-installer").setup { +-- ensure_installed = vim.tbl_filter(function (tool) +-- return vim.fn.executable(tool) == 0 +-- end, require "pi.lsp.tools"), +-- } diff --git a/lua/pi/lsp/null-ls.lua b/lua/pi/lsp/null-ls.lua new file mode 100644 index 0000000..b329ba6 --- /dev/null +++ b/lua/pi/lsp/null-ls.lua @@ -0,0 +1,53 @@ +local null_ls = require "null-ls" +-- local php_actions = require "php-code-actions" +-- local laravel_actions = require("laravel.code-actions") + +null_ls.setup { + sources = { + -- null_ls.builtins.code_actions.gitsigns, + null_ls.builtins.formatting.jq, + null_ls.builtins.code_actions.refactoring, + null_ls.builtins.formatting.alejandra, + null_ls.builtins.diagnostics.luacheck, + null_ls.builtins.formatting.stylua, + + null_ls.builtins.diagnostics.yamllint, + + -- php_actions.getter_setter, + -- php_actions.file_creator, + + -- null_ls.builtins.diagnostics.phpstan.with { + -- to_temp_file = false, + -- method = null_ls.methods.DIAGNOSTICS_ON_SAVE, + -- -- command = "./bin/phpstan", + -- -- condition = function () + -- -- return vim.fn.findfile("bin/phpstan") ~= "" + -- -- end + -- }, + null_ls.builtins.diagnostics.phpcs.with { + method = null_ls.methods.DIAGNOSTICS_ON_SAVE, + condition = function(utils) + return utils.root_has_file "phpcs.xml" + end, + }, + null_ls.builtins.formatting.pint, + }, +} + +vim.keymap.set({ "n", "v" }, "<leader>vca", vim.lsp.buf.code_action, {desc = "LSP (null ls) Code actions"}) +vim.keymap.set("n", "<leader>vf", function() + return vim.lsp.buf.format { async = true } +end, {desc = "LSP (null ls) Format file"}) + +-- function to toogle and possible restart it +vim.api.nvim_create_user_command("NullLsToggle", function() + local sources = vim.tbl_map(function(el) + return el.name + end, null_ls.get_sources()) + vim.ui.select(sources, {}, function(selected) + if not selected then + return + end + null_ls.toggle(selected) + end) +end, {}) diff --git a/lua/pi/lsp/servers/emmet_ls.lua b/lua/pi/lsp/servers/emmet_ls.lua new file mode 100644 index 0000000..717edf8 --- /dev/null +++ b/lua/pi/lsp/servers/emmet_ls.lua @@ -0,0 +1,12 @@ +local lsp_attach = require "pi.lsp.attach" +local lsp_flags = require "pi.lsp.flags" + +return function(ops) + local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + capabilities = capabilities, + filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "blade", "vue" }, + }, ops) +end diff --git a/lua/pi/lsp/servers/html.lua b/lua/pi/lsp/servers/html.lua new file mode 100644 index 0000000..b20553b --- /dev/null +++ b/lua/pi/lsp/servers/html.lua @@ -0,0 +1,14 @@ +local lsp_attach = require "pi.lsp.attach" +local lsp_flags = require "pi.lsp.flags" + +return function(ops) + local config = { + on_attach = lsp_attach, + flags = lsp_flags, + } + if vim.fn.executable "html-languageserver" == 1 then + config.cmd = { "html-languageserver", "--stdio" } + end + + return vim.tbl_extend("force", config, ops) +end diff --git a/lua/pi/lsp/servers/jsonls.lua b/lua/pi/lsp/servers/jsonls.lua new file mode 100644 index 0000000..3fa16e1 --- /dev/null +++ b/lua/pi/lsp/servers/jsonls.lua @@ -0,0 +1,14 @@ +local lsp_attach = require "pi.lsp.attach" +local lsp_flags = require "pi.lsp.flags" + +return function(ops) + local config = { + on_attach = lsp_attach, + flags = lsp_flags, + } + if vim.fn.executable "json-languageserver" == 1 then + config.cmd = { "json-languageserver", "--stdio" } + end + + return vim.tbl_extend("force", config, ops) +end diff --git a/lua/pi/lsp/servers/kotlin_language_server.lua b/lua/pi/lsp/servers/kotlin_language_server.lua new file mode 100644 index 0000000..59e9406 --- /dev/null +++ b/lua/pi/lsp/servers/kotlin_language_server.lua @@ -0,0 +1,12 @@ +local lsp_attach = require "pi.lsp.attach" +local lsp_flags = require "pi.lsp.flags" +return function(ops) + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + settings = { + ["kotlin-language-server"] = { + } + } + }, ops) +end diff --git a/lua/pi/lsp/servers/lua_ls.lua b/lua/pi/lsp/servers/lua_ls.lua new file mode 100644 index 0000000..3975310 --- /dev/null +++ b/lua/pi/lsp/servers/lua_ls.lua @@ -0,0 +1,36 @@ +local lsp_attach = require "pi.lsp.attach" +local lsp_flags = require "pi.lsp.flags" + +return function(ops) + if ops.neodev == true then + require("neodev").setup() + end + + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + settings = { + Lua = { + runtime = { + version = "LuaJIT", + }, + diagnostics = { + globals = { "vim" }, + }, + workspace = { + library = vim.api.nvim_get_runtime_file("", true), + checkThirdParty = false, + }, + telemetry = { + enable = false, + }, + hint = { + enable = true, + }, + completion = { + callSnippet = "Replace", + }, + }, + }, + }, ops) +end diff --git a/lua/pi/lsp/servers/phpactor.lua b/lua/pi/lsp/servers/phpactor.lua new file mode 100644 index 0000000..e5a92ed --- /dev/null +++ b/lua/pi/lsp/servers/phpactor.lua @@ -0,0 +1,80 @@ +local lsp_attach = require "pi.lsp.attach" +local lsp_flags = require "pi.lsp.flags" + +local function phpactor_attach(_, bufnr) + vim.api.nvim_buf_create_user_command(bufnr, "LspPhpactorReindex", function() + vim.lsp.buf_notify(bufnr, "phpactor/index/reindex", {}) + end, {}) + + vim.api.nvim_buf_create_user_command(bufnr, "LspPhpactorStatus", function() + local results, _ = vim.lsp.buf_request_sync(bufnr, "phpactor/status", { ["return"] = true }) + + local content = "" + + for _, res in pairs(results or {}) do + if res ~= nil and res["result"] ~= nil then + content = content .. res["result"] + end + end + + local Popup = require "nui.popup" + local event = require("nui.utils.autocmd").event + + local popup = Popup { + enter = true, + focusable = true, + border = { + style = "rounded", + }, + position = "50%", + size = { + width = "80%", + height = "60%", + }, + } + + -- mount/open the component + popup:mount() + + -- unmount component when cursor leaves buffer + popup:on(event.BufLeave, function() + popup:unmount() + end) + local out = {} + for match in string.gmatch(content, "[^\n]+") do + table.insert(out, match) + end + + -- vim.api.nvim_buf_set_option(popup.bufnr, "filetype", "markdown") + vim.api.nvim_buf_set_lines(popup.bufnr, 0, 1, false, out) + end, {}) +end + +return function(ops) + return vim.tbl_extend("force", { + on_attach = function(client, bufnr) + lsp_attach(client, bufnr) + phpactor_attach(client, bufnr) + end, + flags = lsp_flags, + filetypes = { "php", "blade" }, + init_options = { + ["language_server_worse_reflection.inlay_hints.enable"] = true, + ["language_server_worse_reflection.inlay_hints.params"] = true, + ["language_server_worse_reflection.inlay_hints.types"] = true, + ["language_server_configuration.auto_config"] = false, + ["code_transform.import_globals"] = true, + ["language_server_phpstan.enabled"] = true, + ["language_server_phpstan.level"] = 7, + ["language_server_phpstan.bin"] = "phpstan", + }, + handlers = { + ["textDocument/inlayHint"] = function(err, result, ...) + for _, res in ipairs(result) do + res.label = res.label .. ": " + end + vim.lsp.handlers["textDocument/inlayHint"](err, result, ...) + end, + }, + }, ops) +end diff --git a/lua/pi/lsp/servers/python.lua b/lua/pi/lsp/servers/python.lua new file mode 100644 index 0000000..db561aa --- /dev/null +++ b/lua/pi/lsp/servers/python.lua @@ -0,0 +1,16 @@ +local lsp_attach = require "pi.lsp.attach" +local lsp_flags = require "pi.lsp.flags" +return function (ops) + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + settings = { + ["pyright"] = { + disableOrganizeImports = false, + disableDiagnostics = false, + disableLanguageServices = false, + typeCheckingMode = "strict", + } + } + }, ops) +end diff --git a/lua/pi/lsp/servers/rust_analyzer.lua b/lua/pi/lsp/servers/rust_analyzer.lua new file mode 100644 index 0000000..8999ef8 --- /dev/null +++ b/lua/pi/lsp/servers/rust_analyzer.lua @@ -0,0 +1,24 @@ +local lsp_attach = require "pi.lsp.attach" +local lsp_flags = require "pi.lsp.flags" + +return function(ops) + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + settings = { + ["rust-analyzer"] = { + checkOnSave = { + allFeatures = true, + overrideCommand = { + "cargo", + "clippy", + "--workspace", + "--message-format=json", + "--all-targets", + "--all-features", + }, + }, + }, + }, + }, ops) +end diff --git a/lua/pi/lsp/servers/texlab.lua b/lua/pi/lsp/servers/texlab.lua new file mode 100644 index 0000000..523628b --- /dev/null +++ b/lua/pi/lsp/servers/texlab.lua @@ -0,0 +1,16 @@ +local lsp_attach = require "pi.lsp.attach" +local lsp_flags = require "pi.lsp.flags" +return function(ops) + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + settings = { + ["texlab"] = { + latexFormatter = "latexindent", + latexindent = { + modifyLineBreaks = false + } + } + } + }, ops) +end diff --git a/lua/pi/lsp/servers/tsserver.lua b/lua/pi/lsp/servers/tsserver.lua new file mode 100644 index 0000000..c68c894 --- /dev/null +++ b/lua/pi/lsp/servers/tsserver.lua @@ -0,0 +1,33 @@ +local lsp_attach = require "pi.lsp.attach" +local lsp_flags = require "pi.lsp.flags" + +return function(ops) + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + settings = { + typescript = { + inlayHints = { + includeInlayParameterNameHints = "all", + includeInlayParameterNameHintsWhenArgumentMatchesName = false, + includeInlayFunctionParameterTypeHints = true, + includeInlayVariableTypeHints = true, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayEnumMemberValueHints = true, + }, + }, + javascript = { + inlayHints = { + includeInlayParameterNameHints = "all", + includeInlayParameterNameHintsWhenArgumentMatchesName = false, + includeInlayFunctionParameterTypeHints = true, + includeInlayVariableTypeHints = true, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayEnumMemberValueHints = true, + }, + }, + }, + }, ops) +end diff --git a/lua/pi/lsp/servers/vscode_smarty_langserver.lua b/lua/pi/lsp/servers/vscode_smarty_langserver.lua new file mode 100644 index 0000000..bf29082 --- /dev/null +++ b/lua/pi/lsp/servers/vscode_smarty_langserver.lua @@ -0,0 +1,25 @@ +local lsp_attach = require "pi.lsp.attach" +local lsp_flags = require "pi.lsp.flags" + +return function(ops) + return vim.tbl_extend("force", { + on_attach = lsp_attach, + flags = lsp_flags, + settings = { + css = { + validate = true + }, + smarty = { + pluginDirs = {} + }, + ["smarty_ls"] = { + checkOnSave = { + overrideCommand = { + "smarty-language-server", + "--stdio", + }, + }, + }, + }, + }, ops) +end diff --git a/lua/pi/lsp/tools.lua b/lua/pi/lsp/tools.lua new file mode 100644 index 0000000..7919521 --- /dev/null +++ b/lua/pi/lsp/tools.lua @@ -0,0 +1,8 @@ +return { + "codelldb", + "go-debug-adapter", + "js-debug-adapter", + "php-debug-adapter", + "phpcs", + "phpstan", +} |