dotfiles/nvim/lua/my/lsp.lua
Nikos Papadakis 70167a557e
nvim
2024-05-21 08:59:23 +03:00

240 lines
6.5 KiB
Lua

local lspconfig = require "lspconfig"
require "neodev".setup()
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "single" })
local capabilities = {}
local has_cmp, cmp_lsp = pcall(require, "cmp_nvim_lsp")
if has_cmp then
capabilities = cmp_lsp.default_capabilities()
end
local has_lsp_format, lsp_format = pcall(require, "lsp-format")
if has_lsp_format then
lsp_format.setup {
typescript = { exclude = { "tsserver" } },
javascript = { exclude = { "tsserver" } },
typescriptreact = { exclude = { "tsserver" } },
javascriptreact = { exclude = { "tsserver" } },
}
end
local on_attach = function(client, bufnr)
require("my.keymaps").lsp_keymaps(client, bufnr)
if client.server_capabilities.completionProvider then
vim.api.nvim_set_option_value("omnifunc", "v:lua.vim.lsp.omnifunc", { buf = bufnr })
end
if client.server_capabilities.definitionProvider then
vim.api.nvim_set_option_value("tagfunc", "v:lua.vim.lsp.tagfunc", { buf = bufnr })
end
-- Highlight on cursor hold
if client.server_capabilities.documentHighlightProvider then
vim.api.nvim_create_autocmd({ "CursorHold" }, {
callback = vim.lsp.buf.document_highlight,
buffer = bufnr,
})
end
if client.server_capabilities.signatureHelp then
vim.api.nvim_create_autocmd({ "CursorHoldI" }, {
callback = vim.lsp.buf.signature_help,
buffer = bufnr,
})
end
vim.api.nvim_create_autocmd({ "CursorMoved" }, {
callback = vim.lsp.buf.clear_references,
buffer = bufnr,
})
if has_lsp_format then
lsp_format.on_attach(client)
end
end
local prettier = {
formatCommand = 'prettierd "${INPUT}"',
formatStdin = true,
-- env = {
-- string.format('PRETTIERD_DEFAULT_CONFIG=%s', vim.fn.expand('~/.config/nvim/utils/linter-config/.prettierrc.json')),
-- },
}
local eslint = {
lintCommand = [[eslint_d -f visualstudio --stdin --stdin-filename ${INPUT}]],
lintIgnoreExitCode = true,
lintStdin = true,
lintFormats = {
"%f(%l,%c): %tarning %m",
"%f(%l,%c): %rror %m",
},
lintSource = "eslint",
}
local shellcheck = {
lintCommand = "shellcheck -f gcc -x",
lintSource = "shellcheck",
lintFormats = {
"%f:%l:%c: %trror: %m",
"%f:%l:%c: %tarning: %m",
"%f:%l:%c: %tote: %m",
},
}
local servers = {
efm = {
filetypes = { "typescript", "typescriptreact", "sh", "php" },
init_options = { documentFormatting = true },
settings = {
rootMarkers = { ".git/" },
languages = {
typescript = { prettier, eslint },
typescriptreact = { prettier, eslint },
sh = { shellcheck },
php = { prettier },
},
},
},
gopls = {},
nil_ls = {
settings = {
['nil'] = {
formatting = {
command = { "nixpkgs-fmt" },
},
},
},
},
jedi_language_server = {}, -- python lsp
ruff_lsp = {}, -- python linter
rust_analyzer = {
assist = {
importGranularity = "module",
importPrefix = "self",
},
cargo = {
buildScripts = {
enable = true,
},
},
procMacro = {
enable = true,
},
},
lua_ls = {
settings = {
Lua = {
runtime = {
version = "LuaJIT",
},
diagnostics = {
globals = { "vim" },
},
workspace = {
checkThirdParty = false,
library = vim.api.nvim_get_runtime_file("", true),
},
telemetry = {
enable = false,
},
},
},
},
lexical = {
cmd = { "lexical" },
},
gleam = {},
tsserver = {},
intelephense = {
settings = {
intelephense = {
format = { braces = "k&r", },
stubs = {
"apache",
"bcmath",
"bz2",
"calendar",
"com_dotnet",
"Core",
"ctype",
"curl",
"date",
"dba",
"dom",
"enchant",
"exif",
"FFI",
"fileinfo",
"filter",
"fpm",
"ftp",
"gd",
"gettext",
"gmp",
"hash",
"iconv",
"imap",
"intl",
"json",
"ldap",
"libxml",
"mbstring",
"meta",
"mysqli",
"oci8",
"odbc",
"openssl",
"pcntl",
"pcre",
"PDO",
"pdo_ibm",
"pdo_mysql",
"pdo_pgsql",
"pdo_sqlite",
"pgsql",
"Phar",
"posix",
"pspell",
"readline",
"Reflection",
"session",
"shmop",
"SimpleXML",
"snmp",
"soap",
"sockets",
"sodium",
"SPL",
"sqlite3",
"standard",
"superglobals",
"sysvmsg",
"sysvsem",
"sysvshm",
"tidy",
"tokenizer",
"xml",
"xmlreader",
"xmlrpc",
"xmlwriter",
"xsl",
"wordpress",
"Zend OPcache",
"zip",
"zlib",
},
},
}
},
}
for lsp, settings in pairs(servers) do
lspconfig[lsp].setup(vim.tbl_extend("force", {
on_attach = on_attach,
capabilities = capabilities,
}, settings))
end