dotfiles/nvim/lua/my/lsp.lua

249 lines
6.8 KiB
Lua
Raw Normal View History

2024-02-23 09:38:57 +00:00
local lspconfig = require "lspconfig"
require "neodev".setup()
2023-01-01 14:16:21 +00:00
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
2024-05-21 05:59:23 +00:00
lsp_format.setup {
typescript = { exclude = { "tsserver" } },
javascript = { exclude = { "tsserver" } },
typescriptreact = { exclude = { "tsserver" } },
javascriptreact = { exclude = { "tsserver" } },
}
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-07-12 09:22:46 +00:00
local prettier = {
2024-05-21 05:59:23 +00:00
formatCommand = 'prettierd "${INPUT}"',
2023-07-12 09:22:46 +00:00
formatStdin = true,
2024-05-21 05:59:23 +00:00
-- env = {
-- string.format('PRETTIERD_DEFAULT_CONFIG=%s', vim.fn.expand('~/.config/nvim/utils/linter-config/.prettierrc.json')),
-- },
2023-07-12 09:22:46 +00:00
}
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 = {
2024-06-01 16:26:52 +00:00
filetypes = { "javascript", "javascriptreact", "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 },
2024-06-01 16:26:52 +00:00
javascript = { prettier, eslint },
javascriptreact = { 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 = {},
2024-06-03 08:42:28 +00:00
tsserver = {
root_dir = lspconfig.util.root_pattern("package.json"),
single_file_support = false,
},
deno = {
root_dir = lspconfig.util.root_pattern("deno.json", "deno.jsonc"),
},
2024-04-27 06:47:30 +00:00
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