fix new lsp vim
parent
5f80a31736
commit
dff46591c7
|
@ -1,9 +1,4 @@
|
|||
-- import lspconfig plugin safely
|
||||
local lspconfig_status, lspconfig = pcall(require, "lspconfig")
|
||||
if not lspconfig_status then
|
||||
return
|
||||
end
|
||||
|
||||
-- lsp.lua (replace your current file with this)
|
||||
-- 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
|
||||
|
@ -12,7 +7,7 @@ end
|
|||
|
||||
local keymap = vim.keymap -- for conciseness
|
||||
|
||||
-- smart format with null-ls if aviable
|
||||
-- smart format with null-ls if available
|
||||
local function smart_format()
|
||||
vim.lsp.buf.format({
|
||||
filter = function(client)
|
||||
|
@ -29,228 +24,154 @@ local function smart_format()
|
|||
timeout_ms = 3000,
|
||||
})
|
||||
end
|
||||
|
||||
---------- 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, ...)
|
||||
do
|
||||
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"
|
||||
return orig_floating_preview(contents, syntax, opts, ...)
|
||||
end
|
||||
end
|
||||
---------- </border ------------------------------
|
||||
|
||||
vim.diagnostic.config({ virtual_lines = { current_line = true } })
|
||||
|
||||
-- enable keybinds only for when lsp server available
|
||||
local on_attach = function(_, bufnr)
|
||||
-- keybind options
|
||||
local opts = { noremap = true, silent = true, buffer = bufnr }
|
||||
|
||||
keymap.set("n", "g0", "<cmd>lua vim.lsp.buf.document_symbol()<CR>", opts)
|
||||
-- keymap.set("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts) keymap.set("n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts) -- got to declaration
|
||||
-- keymap.set("n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts) -- see definition and make edits in window
|
||||
keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts) -- see definition and make edits in window
|
||||
keymap.set("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts) -- go to implementation
|
||||
-- keymap.set("n", "<leader>l", "<cmd>lua vim.lsp.buf.format()<CR>", opts) -- format code
|
||||
keymap.set("n", "<leader>l", smart_format, opts) -- format code
|
||||
keymap.set("n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts) -- format code
|
||||
-- keymap.set("n", "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts) -- see available code actions
|
||||
-- keymap.set("n", "<leader>ed", "<cmd>Telescope diagnostics<CR>", opts) -- jump to previous diagnostic in buffer
|
||||
-- keymap.set("n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts) -- show documentation for what is under cursor
|
||||
keymap.set("n", "gd", "<cmd>Telescope lsp_definitions<CR>", opts)
|
||||
keymap.set("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
|
||||
keymap.set("n", "<leader>l", smart_format, opts)
|
||||
keymap.set("n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
|
||||
keymap.set(
|
||||
"n",
|
||||
"<leader>cbf",
|
||||
":!phpcbf -w --standard=PSR12 %<CR>",
|
||||
{ noremap = true, silent = false, buffer = bufnr }
|
||||
)
|
||||
|
||||
keymap.set("n", "<leader>o", "<cmd>Lspsaga outline<CR>", opts) -- see outline on right hand side
|
||||
keymap.set("n", "<leader>ss", "<cmd>Telescope lsp_dynamic_workspace_symbols<CR>", opts) -- workspace symbols
|
||||
|
||||
keymap.set("n", "<leader>o", "<cmd>Lspsaga outline<CR>", opts)
|
||||
keymap.set("n", "<leader>ss", "<cmd>Telescope lsp_dynamic_workspace_symbols<CR>", opts)
|
||||
|
||||
-- LSP Saga
|
||||
keymap.set("n", "gsd", "<cmd>Lspsaga peek_definition<CR>", opts) -- see definition and make edits in window
|
||||
keymap.set("n", "gr", "<cmd>Lspsaga finder<CR>", opts) -- see definition and make edits in window
|
||||
keymap.set("n", "<leader>rn", "<cmd>Lspsaga rename<CR>", opts) -- smart rename
|
||||
keymap.set("n", "<leader>ca", "<cmd>Lspsaga code_action<CR>", opts) -- see available code actions
|
||||
-- keymap.set("n", "K", "<cmd>Lspsaga hover_doc<CR>", opts) -- show documentation for what is under cursor
|
||||
keymap.set("n", "ge", "<cmd>Lspsaga show_line_diagnostics<CR>", opts) -- show diagnostics for line
|
||||
keymap.set("n", "gsd", "<cmd>Lspsaga peek_definition<CR>", opts)
|
||||
keymap.set("n", "gr", "<cmd>Lspsaga finder<CR>", opts)
|
||||
keymap.set("n", "<leader>rn", "<cmd>Lspsaga rename<CR>", opts)
|
||||
keymap.set("n", "<leader>ca", "<cmd>Lspsaga code_action<CR>", opts)
|
||||
keymap.set("n", "ge", "<cmd>Lspsaga show_line_diagnostics<CR>", opts)
|
||||
keymap.set("n", "<a-cr>", "<cmd>Lspsaga code_action<CR>", opts)
|
||||
-- diagnostic
|
||||
keymap.set("n", "<leader>d", "<cmd>Telescope diagnostics<CR>", opts) -- jump to previous diagnostic in buffer
|
||||
-- keymap.set("n", "<leader>d", "<cmd>Lspsaga show_buf_diagnostics<CR>")
|
||||
keymap.set("n", "<leader>dn", "<cmd>Lspsaga diagnostic_jump_next<CR>") -- jump to next diagnostic in buffer
|
||||
keymap.set("n", "<leader>dp", "<cmd>Lspsaga diagnostic_jump_prev<CR>") -- jump to previous diagnostic in buffer
|
||||
keymap.set("n", "<leader>d", "<cmd>Telescope diagnostics<CR>", opts)
|
||||
keymap.set("n", "<leader>dn", "<cmd>Lspsaga diagnostic_jump_next<CR>")
|
||||
keymap.set("n", "<leader>dp", "<cmd>Lspsaga diagnostic_jump_prev<CR>")
|
||||
|
||||
keymap.set("n", "gj", "<cmd>lua require'nvim-treesitter.textobjects.move'.goto_next_start('@function.outer')<CR>",
|
||||
opts) -- jump to next method
|
||||
opts)
|
||||
keymap.set("n", "gk", "<cmd>lua require'nvim-treesitter.textobjects.move'.goto_previous_start('@function.outer')<CR>",
|
||||
opts) -- jump to previous method
|
||||
opts)
|
||||
end
|
||||
|
||||
-- used to enable autocompletion (assign to every lsp server config)
|
||||
-- capabilities
|
||||
local capabilities = cmp_nvim_lsp.default_capabilities()
|
||||
|
||||
lspconfig["bashls"].setup({
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
filetypes = { "sh", "bin" },
|
||||
})
|
||||
|
||||
-- XML LSP
|
||||
lspconfig["lemminx"].setup({
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
filetypes = { "xml" },
|
||||
})
|
||||
|
||||
-- yaml LSP
|
||||
lspconfig["yamlls"].setup({
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
filetypes = { "yaml", "yml" },
|
||||
})
|
||||
-- json LSP
|
||||
lspconfig["jsonls"].setup({
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
filetypes = { "json" },
|
||||
})
|
||||
|
||||
lspconfig["pyright"].setup({
|
||||
on_attach = on_attach,
|
||||
filetypes = { "py" },
|
||||
})
|
||||
|
||||
-- configure html server
|
||||
lspconfig["html"].setup({
|
||||
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" },
|
||||
})
|
||||
|
||||
-- configure tailwindcss server
|
||||
lspconfig["tailwindcss"].setup({
|
||||
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" },
|
||||
})
|
||||
|
||||
lspconfig["eslint"].setup({
|
||||
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,
|
||||
-- Server-specific settings...
|
||||
settings = {
|
||||
["rust-analyzer"] = {
|
||||
-- enable clippy on save
|
||||
checkOnSave = true,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
lspconfig["yamlls"].setup({
|
||||
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,
|
||||
filetypes = { "lua" },
|
||||
})
|
||||
|
||||
local util = require("lspconfig.util")
|
||||
|
||||
local fallback_root_dir = function(fname)
|
||||
return util.root_pattern("composer.json", ".git")(fname) or util.path.dirname(fname)
|
||||
-- helper for registering server configs (lazy attach)
|
||||
local function setup_server(name, config)
|
||||
local cfg = vim.tbl_deep_extend("force", {
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
}, config or {})
|
||||
-- register the config
|
||||
-- use the function form so it works in latest nvim
|
||||
vim.lsp.config(name, cfg)
|
||||
end
|
||||
|
||||
lspconfig["phpactor"].setup({
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
-- servers
|
||||
setup_server("bashls", { filetypes = { "sh", "bin" } })
|
||||
setup_server("lemminx", { filetypes = { "xml" } })
|
||||
setup_server("yamlls", { filetypes = { "yaml", "yml" } })
|
||||
setup_server("jsonls", { filetypes = { "json" } })
|
||||
setup_server("pyright", { filetypes = { "py" } })
|
||||
setup_server("html", { filetypes = { "html" } })
|
||||
setup_server("cssls",
|
||||
{ filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" } })
|
||||
setup_server("tailwindcss", {
|
||||
filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" },
|
||||
})
|
||||
setup_server("emmet_ls", {
|
||||
filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" },
|
||||
})
|
||||
setup_server("eslint", {
|
||||
filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" },
|
||||
})
|
||||
setup_server("rust_analyzer", {
|
||||
settings = {
|
||||
["rust-analyzer"] = { checkOnSave = true },
|
||||
},
|
||||
})
|
||||
setup_server("lua_ls", { filetypes = { "lua" } })
|
||||
-- setup_server("slint_lsp", { filetypes = { "slint" } })
|
||||
|
||||
-- PHP LSPs
|
||||
local util = require("lspconfig.util")
|
||||
root_dir = function(fname)
|
||||
return util.root_pattern("composer.json", ".git")(fname)
|
||||
or util.path.dirname(fname)
|
||||
end
|
||||
|
||||
setup_server("phpactor", {
|
||||
filetypes = { "php" },
|
||||
root_dir = fallback_root_dir,
|
||||
init_options = {
|
||||
["language_server_phpstan.enabled"] = true,
|
||||
["language_server_psalm.enabled"] = false,
|
||||
},
|
||||
filetypes = { "php" },
|
||||
root_dir = fallback_root_dir,
|
||||
})
|
||||
|
||||
lspconfig["intelephense"].setup({
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
setup_server("intelephense", {
|
||||
filetypes = { "php" },
|
||||
root_dir = fallback_root_dir,
|
||||
init_options = {
|
||||
licenceKey = vim.fn.readfile(vim.fn.expand("$HOME/.config/intelephense/license.txt"))[1],
|
||||
},
|
||||
root_dir = fallback_root_dir,
|
||||
settings = {
|
||||
intelephense = {
|
||||
-- ✅ Enable property inference (Pro)
|
||||
telemetry = { enabled = false }, -- optional, privacy
|
||||
telemetry = { enabled = false },
|
||||
files = {
|
||||
maxSize = 5000000, -- increase if needed
|
||||
maxSize = 5000000,
|
||||
associations = { "**/*.php" },
|
||||
},
|
||||
-- environment = {
|
||||
-- includePaths = {
|
||||
-- "/path/to/your/stubs", -- ⬅️ Your custom stub folder
|
||||
-- },
|
||||
-- },
|
||||
completion = {
|
||||
fullyQualifyGlobalConstantsAndFunctions = false,
|
||||
triggerParameterHints = true,
|
||||
maxItems = 100,
|
||||
},
|
||||
-- enables smarter inference
|
||||
phpdoc = {
|
||||
enabled = true,
|
||||
},
|
||||
diagnostics = {
|
||||
enable = true,
|
||||
},
|
||||
format = {
|
||||
enable = false, -- you’re using `phpcbf` anyway
|
||||
},
|
||||
phpdoc = { enabled = true },
|
||||
diagnostics = { enable = true },
|
||||
format = { enable = false },
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
lspconfig["slint_lsp"].setup({
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
filetypes = { "slint" },
|
||||
})
|
||||
|
||||
-- phpcs / phpstan configs
|
||||
vim.g.nvim_phpcs_config_phpcs_path = 'phpcs'
|
||||
vim.g.nvim_phpcs_config_phpcbf_path = 'phpcbf'
|
||||
vim.g.ale_php_phpstan_executable = '/home/mace/.config/composer/vendor/bin/phpstan'
|
||||
|
||||
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
|
||||
elseif vim.loop.fs_stat(phpcs_config) then
|
||||
vim.g.nvim_phpcs_config_phpcs_standard = phpcs_config
|
||||
end
|
||||
|
||||
-- === ENABLE: tell Neovim to autostart these configs lazily (filetype + root_dir)
|
||||
-- call this early in your init (so FileType autocommands are installed before opening files)
|
||||
local enabled_servers = {
|
||||
"bashls", "lemminx", "yamlls", "jsonls", "pyright", "html", "cssls",
|
||||
"tailwindcss", "emmet_ls", "eslint", "rust_analyzer", "lua_ls",
|
||||
"phpactor", "intelephense"
|
||||
}
|
||||
vim.lsp.enable(enabled_servers)
|
||||
|
|
Loading…
Reference in New Issue