2024-02-23 09:38:57 +00:00
|
|
|
local lspconfig = require "lspconfig"
|
|
|
|
require "neodev".setup()
|
2023-01-01 14:16:21 +00:00
|
|
|
|
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-10-06 20:46:37 +00:00
|
|
|
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "single" })
|
2023-01-01 14:16:21 +00:00
|
|
|
|
|
|
|
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
|
2024-02-23 09:38:57 +00:00
|
|
|
vim.api.nvim_set_option_value("omnifunc", "v:lua.vim.lsp.omnifunc", { buf = bufnr })
|
2023-01-16 09:22:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if client.server_capabilities.definitionProvider then
|
2024-02-23 09:38:57 +00:00
|
|
|
vim.api.nvim_set_option_value("tagfunc", "v:lua.vim.lsp.tagfunc", { buf = bufnr })
|
2023-01-16 09:22:41 +00:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-03-02 21:09:33 +00:00
|
|
|
lexical = {
|
|
|
|
cmd = { "lexical" },
|
2023-07-12 09:22:46 +00:00
|
|
|
},
|
2024-04-18 18:37:45 +00:00
|
|
|
gleam = {},
|
2023-07-12 09:22:46 +00:00
|
|
|
tsserver = {
|
|
|
|
settings = {
|
|
|
|
documentFormatting = false,
|
|
|
|
},
|
2023-05-06 21:02:42 +00:00
|
|
|
},
|
2024-04-27 06:47:30 +00:00
|
|
|
-- psalm = {},
|
|
|
|
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",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
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,
|
|
|
|
}, settings))
|
|
|
|
end
|