2023-01-01 14:16:21 +00:00
|
|
|
local ok, lspconfig = pcall(require, "lspconfig")
|
|
|
|
|
|
|
|
if not ok then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2023-08-18 21:12:43 +00:00
|
|
|
local root_dir
|
|
|
|
for dir in vim.fs.parents(vim.api.nvim_buf_get_name(0)) do
|
|
|
|
if vim.fn.isdirectory(dir .. "/.git") == 1 then
|
|
|
|
root_dir = dir
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-01 14:16:21 +00:00
|
|
|
local border = {
|
|
|
|
{ "┌", "FloatBorder" },
|
|
|
|
{ "─", "FloatBorder" },
|
|
|
|
{ "┐", "FloatBorder" },
|
|
|
|
{ "│", "FloatBorder" },
|
|
|
|
{ "┘", "FloatBorder" },
|
|
|
|
{ "─", "FloatBorder" },
|
|
|
|
{ "└", "FloatBorder" },
|
|
|
|
{ "│", "FloatBorder" },
|
|
|
|
}
|
|
|
|
|
|
|
|
local handlers = {
|
|
|
|
["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = border }),
|
|
|
|
["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = border }),
|
|
|
|
}
|
|
|
|
|
|
|
|
local capabilities = {}
|
|
|
|
|
|
|
|
local has_cmp, cmp_lsp = pcall(require, "cmp_nvim_lsp")
|
|
|
|
if has_cmp then
|
|
|
|
capabilities = cmp_lsp.default_capabilities()
|
|
|
|
end
|
|
|
|
|
2023-07-12 09:22:46 +00:00
|
|
|
local has_lsp_format, lsp_format = pcall(require, "lsp-format")
|
|
|
|
if has_lsp_format then
|
|
|
|
lsp_format.setup()
|
2023-04-25 17:23:42 +00:00
|
|
|
end
|
|
|
|
|
2023-01-01 14:16:21 +00:00
|
|
|
local on_attach = function(client, bufnr)
|
2023-06-14 09:30:11 +00:00
|
|
|
require("my.keymaps").lsp_keymaps(client, bufnr)
|
2023-01-01 14:16:21 +00:00
|
|
|
|
2023-01-16 09:22:41 +00:00
|
|
|
if client.server_capabilities.completionProvider then
|
|
|
|
vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
|
|
|
|
end
|
|
|
|
|
|
|
|
if client.server_capabilities.definitionProvider then
|
|
|
|
vim.api.nvim_buf_set_option(bufnr, "tagfunc", "v:lua.vim.lsp.tagfunc")
|
|
|
|
end
|
|
|
|
|
2023-01-01 14:16:21 +00:00
|
|
|
-- Highlight on cursor hold
|
|
|
|
if client.server_capabilities.documentHighlightProvider then
|
|
|
|
vim.api.nvim_create_autocmd({ "CursorHold" }, {
|
|
|
|
callback = vim.lsp.buf.document_highlight,
|
|
|
|
buffer = bufnr,
|
|
|
|
})
|
2023-09-30 13:40:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if client.server_capabilities.signatureHelp then
|
2023-01-01 14:16:21 +00:00
|
|
|
vim.api.nvim_create_autocmd({ "CursorHoldI" }, {
|
|
|
|
callback = vim.lsp.buf.signature_help,
|
|
|
|
buffer = bufnr,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2023-09-30 13:40:43 +00:00
|
|
|
vim.api.nvim_create_autocmd({ "CursorMoved" }, {
|
|
|
|
callback = vim.lsp.buf.clear_references,
|
|
|
|
buffer = bufnr,
|
|
|
|
})
|
|
|
|
|
2023-07-12 09:22:46 +00:00
|
|
|
if has_lsp_format then
|
|
|
|
lsp_format.on_attach(client)
|
|
|
|
end
|
2023-01-01 14:16:21 +00:00
|
|
|
end
|
|
|
|
|
2023-08-18 21:12:43 +00:00
|
|
|
local function prettier_command()
|
2023-08-20 09:22:56 +00:00
|
|
|
if not root_dir then
|
|
|
|
return "prettier"
|
|
|
|
end
|
|
|
|
|
2023-08-18 21:12:43 +00:00
|
|
|
if vim.fs.basename(root_dir .. "node_modules/prettier") then
|
|
|
|
return "npx prettier"
|
|
|
|
else
|
|
|
|
return "prettier"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-07-12 09:22:46 +00:00
|
|
|
local prettier = {
|
2023-08-18 21:12:43 +00:00
|
|
|
formatCommand = prettier_command() .. [[ --stdin-filepath ${INPUT} ${--tab-width:tab_width}]],
|
2023-07-12 09:22:46 +00:00
|
|
|
formatStdin = true,
|
|
|
|
}
|
|
|
|
|
|
|
|
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",
|
|
|
|
}
|
|
|
|
|
2023-07-21 13:57:29 +00:00
|
|
|
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",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-01-01 14:16:21 +00:00
|
|
|
local servers = {
|
2023-07-12 09:22:46 +00:00
|
|
|
efm = {
|
2023-08-18 21:12:43 +00:00
|
|
|
filetypes = { "typescript", "typescriptreact", "sh", "php" },
|
2023-07-12 09:22:46 +00:00
|
|
|
init_options = { documentFormatting = true },
|
|
|
|
settings = {
|
|
|
|
rootMarkers = { ".git/" },
|
|
|
|
languages = {
|
|
|
|
typescript = { prettier, eslint },
|
|
|
|
typescriptreact = { prettier, eslint },
|
2023-07-21 13:57:29 +00:00
|
|
|
sh = { shellcheck },
|
2023-08-18 21:12:43 +00:00
|
|
|
php = { prettier },
|
2023-07-12 09:22:46 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-01-01 14:16:21 +00:00
|
|
|
gopls = {},
|
2023-09-26 17:40:23 +00:00
|
|
|
nil_ls = {
|
|
|
|
settings = {
|
|
|
|
['nil'] = {
|
|
|
|
formatting = {
|
|
|
|
command = { "nixpkgs-fmt" },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-09-21 08:18:48 +00:00
|
|
|
jedi_language_server = {}, -- python lsp
|
|
|
|
ruff_lsp = {}, -- python linter
|
2023-01-01 14:16:21 +00:00
|
|
|
rust_analyzer = {
|
|
|
|
assist = {
|
|
|
|
importGranularity = "module",
|
|
|
|
importPrefix = "self",
|
|
|
|
},
|
|
|
|
cargo = {
|
2023-04-22 17:31:30 +00:00
|
|
|
buildScripts = {
|
|
|
|
enable = true,
|
|
|
|
},
|
2023-01-01 14:16:21 +00:00
|
|
|
},
|
|
|
|
procMacro = {
|
|
|
|
enable = true,
|
|
|
|
},
|
|
|
|
},
|
2023-02-14 09:43:58 +00:00
|
|
|
lua_ls = {
|
2023-01-01 14:16:21 +00:00
|
|
|
settings = {
|
|
|
|
Lua = {
|
|
|
|
runtime = {
|
|
|
|
version = "LuaJIT",
|
|
|
|
},
|
|
|
|
diagnostics = {
|
|
|
|
globals = { "vim" },
|
|
|
|
},
|
|
|
|
workspace = {
|
2023-07-12 09:59:53 +00:00
|
|
|
checkThirdParty = false,
|
2023-01-01 14:16:21 +00:00
|
|
|
library = vim.api.nvim_get_runtime_file("", true),
|
|
|
|
},
|
|
|
|
telemetry = {
|
|
|
|
enable = false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-05-06 21:02:42 +00:00
|
|
|
elixirls = {
|
2023-07-12 09:22:46 +00:00
|
|
|
cmd = { "/home/nikos/Projects/elixir-ls/release/language_server.sh" },
|
|
|
|
settings = {
|
|
|
|
elixirLS = {
|
|
|
|
dialyzerEnabled = true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
tsserver = {
|
|
|
|
settings = {
|
|
|
|
documentFormatting = false,
|
|
|
|
},
|
2023-05-06 21:02:42 +00:00
|
|
|
},
|
2023-07-09 20:39:36 +00:00
|
|
|
psalm = {
|
|
|
|
cmd = { "vendor/bin/psalm-language-server" },
|
|
|
|
},
|
2023-01-01 14:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for lsp, settings in pairs(servers) do
|
|
|
|
lspconfig[lsp].setup(vim.tbl_extend("force", {
|
|
|
|
on_attach = on_attach,
|
|
|
|
capabilities = capabilities,
|
|
|
|
handlers = handlers,
|
|
|
|
}, settings))
|
|
|
|
end
|