more settings
This commit is contained in:
@@ -0,0 +1,179 @@
|
||||
-- import lspconfig plugin safely
|
||||
local lspconfig_status, lspconfig = pcall(require, "lspconfig")
|
||||
if not lspconfig_status then
|
||||
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
|
||||
end
|
||||
|
||||
local keymap = vim.keymap -- for conciseness
|
||||
|
||||
-- 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", "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>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",
|
||||
"<leader>cbf",
|
||||
":!phpcbf -w --standard=PSR12 %<CR>",
|
||||
{ noremap = true, silent = false, buffer = bufnr }
|
||||
)
|
||||
|
||||
keymap.set("n", "<leader>o", "<cmd>LSoutlineToggle<CR>", opts) -- see outline on right hand side
|
||||
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" },
|
||||
})
|
||||
|
||||
-- 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,
|
||||
flags = lsp_flags,
|
||||
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,
|
||||
flags = lsp_flags,
|
||||
-- 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" },
|
||||
})
|
||||
|
||||
-- -- 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" },
|
||||
})
|
||||
|
||||
lspconfig["phpactor"].setup({
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
init_options = {
|
||||
["language_server_phpstan.enabled"] = true,
|
||||
["language_server_psalm.enabled"] = false,
|
||||
},
|
||||
filetypes = { "php" },
|
||||
})
|
||||
|
||||
lspconfig["intelephense"].setup({
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
filetypes = { "php" },
|
||||
})
|
||||
Reference in New Issue
Block a user