diff --git a/lua/custom/lspconfig.lua b/lua/custom/lspconfig.lua index ab63206..c04e14d 100644 --- a/lua/custom/lspconfig.lua +++ b/lua/custom/lspconfig.lua @@ -1,209 +1,166 @@ -- import lspconfig plugin safely local lspconfig_status, lspconfig = pcall(require, "lspconfig") if not lspconfig_status then - return + return end -- import cmp-nvim-lsp plugin safely local cmp_nvim_lsp_status, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") if not cmp_nvim_lsp_status then - return + return end local keymap = vim.keymap -- for conciseness ---------- border >------------------------------ -local _border = "single" -require('lspconfig.ui.windows').default_options = { - border = _border -} -vim.lsp.handlers["textDocument/hover"] = vim.lsp.with( - vim.lsp.handlers.hover, { - border = _border - } -) - -vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with( - vim.lsp.handlers.signature_help, { - border = _border - } -) - -vim.diagnostic.config { - float = { border = _border } -} +local orig_floating_preview = vim.lsp.util.open_floating_preview +vim.lsp.util.open_floating_preview = function(contents, syntax, opts, ...) + opts = opts or {} + opts.border = "rounded" -- You can also use "single", "double", or "shadow" + return orig_floating_preview(contents, syntax, opts, ...) +end ---------- lua vim.lsp.buf.document_symbol()", opts) - -- keymap.set("n", "gr", "lua vim.lsp.buf.references()", opts) - keymap.set("n", "gD", "lua vim.lsp.buf.declaration()", opts) -- got to declaration - keymap.set("n", "gd", "lua vim.lsp.buf.definition()", opts) -- see definition and make edits in window - keymap.set("n", "gi", "lua vim.lsp.buf.implementation()", opts) -- go to implementation - keymap.set("n", "l", "lua vim.lsp.buf.format()", opts) -- format code - keymap.set("n", "rn", "lua vim.lsp.buf.rename()", opts) -- format code - -- keymap.set("n", "ca", "lua vim.lsp.buf.code_action()", opts) -- see available code actions - -- keymap.set("n", "ed", "Telescope diagnostics", opts) -- jump to previous diagnostic in buffer - -- keymap.set("n", "K", "lua vim.lsp.buf.hover()", opts) -- show documentation for what is under cursor - keymap.set( - "n", - "cbf", - ":!phpcbf -w --standard=PSR12 %", - { noremap = true, silent = false, buffer = bufnr } - ) + keymap.set("n", "g0", "lua vim.lsp.buf.document_symbol()", opts) + -- keymap.set("n", "gr", "lua vim.lsp.buf.references()", opts) keymap.set("n", "gD", "lua vim.lsp.buf.declaration()", opts) -- got to declaration + keymap.set("n", "gd", "lua vim.lsp.buf.definition()", opts) -- see definition and make edits in window + keymap.set("n", "gi", "lua vim.lsp.buf.implementation()", opts) -- go to implementation + keymap.set("n", "l", "lua vim.lsp.buf.format()", opts) -- format code + keymap.set("n", "rn", "lua vim.lsp.buf.rename()", opts) -- format code + -- keymap.set("n", "ca", "lua vim.lsp.buf.code_action()", opts) -- see available code actions + -- keymap.set("n", "ed", "Telescope diagnostics", opts) -- jump to previous diagnostic in buffer + -- keymap.set("n", "K", "lua vim.lsp.buf.hover()", opts) -- show documentation for what is under cursor + keymap.set( + "n", + "cbf", + ":!phpcbf -w --standard=PSR12 %", + { noremap = true, silent = false, buffer = bufnr } + ) - keymap.set("n", "o", "Lspsaga outline", opts) -- see outline on right hand side - keymap.set("n", "ss", "Telescope lsp_dynamic_workspace_symbols", opts) -- workspace symbols + keymap.set("n", "o", "Lspsaga outline", opts) -- see outline on right hand side + keymap.set("n", "ss", "Telescope lsp_dynamic_workspace_symbols", opts) -- workspace symbols - -- LSP Saga - keymap.set("n", "gsd", "Lspsaga peek_definition", opts) -- see definition and make edits in window - keymap.set("n", "gr", "Lspsaga finder", opts) -- see definition and make edits in window - keymap.set("n", "rn", "Lspsaga rename", opts) -- smart rename - keymap.set("n", "ca", "Lspsaga code_action", opts) -- see available code actions - keymap.set("n", "K", "Lspsaga hover_doc", opts) -- show documentation for what is under cursor - keymap.set("n", "ge", "Lspsaga show_line_diagnostics", opts) -- show diagnostics for line - keymap.set("n", "", "Lspsaga code_action", opts) - -- diagnostic - keymap.set("n", "d", "Telescope diagnostics", opts) -- jump to previous diagnostic in buffer - -- keymap.set("n", "d", "Lspsaga show_buf_diagnostics") - keymap.set("n", "dn", "Lspsaga diagnostic_jump_next") -- jump to next diagnostic in buffer - keymap.set("n", "dp", "Lspsaga diagnostic_jump_prev") -- jump to previous diagnostic in buffer + -- LSP Saga + keymap.set("n", "gsd", "Lspsaga peek_definition", opts) -- see definition and make edits in window + keymap.set("n", "gr", "Lspsaga finder", opts) -- see definition and make edits in window + keymap.set("n", "rn", "Lspsaga rename", opts) -- smart rename + keymap.set("n", "ca", "Lspsaga code_action", opts) -- see available code actions + keymap.set("n", "K", "Lspsaga hover_doc", opts) -- show documentation for what is under cursor + keymap.set("n", "ge", "Lspsaga show_line_diagnostics", opts) -- show diagnostics for line + keymap.set("n", "", "Lspsaga code_action", opts) + -- diagnostic + keymap.set("n", "d", "Telescope diagnostics", opts) -- jump to previous diagnostic in buffer + -- keymap.set("n", "d", "Lspsaga show_buf_diagnostics") + keymap.set("n", "dn", "Lspsaga diagnostic_jump_next") -- jump to next diagnostic in buffer + keymap.set("n", "dp", "Lspsaga diagnostic_jump_prev") -- jump to previous diagnostic in buffer - keymap.set("n", "gj", "lua require'nvim-treesitter.textobjects.move'.goto_next_start('@function.outer')", - opts) -- jump to next method - keymap.set("n", "gk", "lua require'nvim-treesitter.textobjects.move'.goto_previous_start('@function.outer')", - opts) -- jump to previous method + keymap.set("n", "gj", "lua require'nvim-treesitter.textobjects.move'.goto_next_start('@function.outer')", + opts) -- jump to next method + keymap.set("n", "gk", "lua require'nvim-treesitter.textobjects.move'.goto_previous_start('@function.outer')", + opts) -- jump to previous method end -- used to enable autocompletion (assign to every lsp server config) local capabilities = cmp_nvim_lsp.default_capabilities() --- Change the Diagnostic symbols in the sign column (gutter) --- (not in youtube nvim video) -local signs = { Error = " ", Warn = " ", Hint = "󰋽 ", Info = " " } -for type, icon in pairs(signs) do - local hl = "DiagnosticSign" .. type - vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) -end - -local lsp_flags = { - -- This is the default in Nvim 0.7+ - debounce_text_changes = 150, -} - lspconfig["bashls"].setup({ - capabilities = capabilities, - on_attach = on_attach, - filetypes = { "sh", "bin" }, + capabilities = capabilities, + on_attach = on_attach, + filetypes = { "sh", "bin" }, }) -- XML LSP lspconfig["lemminx"].setup({ - capabilities = capabilities, - on_attach = on_attach, - filetypes = { "xml" }, + capabilities = capabilities, + on_attach = on_attach, + filetypes = { "xml" }, }) -- yaml LSP lspconfig["yamlls"].setup({ - capabilities = capabilities, - on_attach = on_attach, - filetypes = { "yaml", "yml" }, + capabilities = capabilities, + on_attach = on_attach, + filetypes = { "yaml", "yml" }, }) -- json LSP lspconfig["jsonls"].setup({ - capabilities = capabilities, - on_attach = on_attach, - filetypes = { "json" }, + capabilities = capabilities, + on_attach = on_attach, + filetypes = { "json" }, }) lspconfig["pyright"].setup({ - on_attach = on_attach, - flags = lsp_flags, - filetypes = { "py" }, + on_attach = on_attach, + filetypes = { "py" }, }) -- configure html server lspconfig["html"].setup({ - capabilities = capabilities, - on_attach = on_attach, - filetypes = { "html" }, + capabilities = capabilities, + on_attach = on_attach, + filetypes = { "html" }, }) -- configure css server lspconfig["cssls"].setup({ - capabilities = capabilities, - on_attach = on_attach, - filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" }, + capabilities = capabilities, + on_attach = on_attach, + filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" }, }) -- configure tailwindcss server lspconfig["tailwindcss"].setup({ - capabilities = capabilities, - on_attach = on_attach, - filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" }, + capabilities = capabilities, + on_attach = on_attach, + filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" }, }) -- configure emmet language server lspconfig["emmet_ls"].setup({ - capabilities = capabilities, - on_attach = on_attach, - filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" }, + capabilities = capabilities, + on_attach = on_attach, + filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" }, }) lspconfig["eslint"].setup({ - capabilities = capabilities, - on_attach = on_attach, - filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" }, + capabilities = capabilities, + on_attach = on_attach, + filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" }, }) -- rust lspconfig["rust_analyzer"].setup({ - on_attach = on_attach, - capabilities = capabilities, - flags = lsp_flags, - -- Server-specific settings... - settings = { - ["rust-analyzer"] = { - -- enable clippy on save - checkOnSave = { - command = "clippy", - }, - }, - }, + on_attach = on_attach, + capabilities = capabilities, + -- Server-specific settings... + settings = { + ["rust-analyzer"] = { + -- enable clippy on save + checkOnSave = { + command = "clippy", + }, + }, + }, }) lspconfig["yamlls"].setup({ - capabilities = capabilities, - on_attach = on_attach, - filetypes = { "yml", "yaml" }, + capabilities = capabilities, + on_attach = on_attach, + filetypes = { "yml", "yaml" }, }) -- -- configure lua server (with special settings) lspconfig["lua_ls"].setup({ - capabilities = capabilities, - on_attach = on_attach, - settings = { -- custom settings for lua - Lua = { - -- make the language server recognize "vim" global - diagnostics = { - globals = { "vim" }, - }, - workspace = { - -- make language server aware of runtime files - library = { - [vim.fn.expand("$VIMRUNTIME/lua")] = true, - [vim.fn.stdpath("config") .. "/lua"] = true, - }, - }, - }, - }, - filetypes = { "lua" }, + capabilities = capabilities, + on_attach = on_attach, + filetypes = { "lua" }, }) -- lspconfig["phpactor"].setup({ @@ -217,17 +174,25 @@ lspconfig["lua_ls"].setup({ -- }) lspconfig["intelephense"].setup({ - capabilities = capabilities, - on_attach = on_attach, - filetypes = { "php" }, + capabilities = capabilities, + on_attach = on_attach, + filetypes = { "php" }, }) lspconfig["slint_lsp"].setup({ - on_attach = on_attach, - capabilities = capabilities, - filetypes = { "slint" }, + on_attach = on_attach, + capabilities = capabilities, + filetypes = { "slint" }, }) vim.g.nvim_phpcs_config_phpcs_path = 'phpcs' vim.g.nvim_phpcs_config_phpcbf_path = 'phpcbf' -vim.g.nvim_phpcs_config_phpcs_standard = "/home/mace/repos/configs/phpcs.xml" +local phpcs_config = "/home/mace/repos/configs/phpcs.xml" +local phpcs_config_new = "/home/mace/repos/dotfiles/phpcs.xml" + +if vim.loop.fs_stat(phpcs_config_new) then + vim.g.nvim_phpcs_config_phpcs_standard = phpcs_config_new +end +if vim.loop.fs_stat(phpcs_config) then + vim.g.nvim_phpcs_config_phpcs_standard = phpcs_config +end