my demo first config lua
This commit is contained in:
29
lua/alpha/lsp/attach.lua
Normal file
29
lua/alpha/lsp/attach.lua
Normal file
@@ -0,0 +1,29 @@
|
||||
local telescope_mapper = require "alpha.telescope.mappings"
|
||||
|
||||
return function(client, bufnr)
|
||||
-- keymaps for lsp
|
||||
vim.keymap.set("n", "K", vim.lsp.buf.hover, { buffer = 0, desc = "LSP Help information of symbol under the cursor" })
|
||||
vim.keymap.set("n", "<leader>vrn", vim.lsp.buf.rename, { buffer = 0, desc = "LSP Rename symbol under cursor" })
|
||||
vim.keymap.set("i", "<c-h>", vim.lsp.buf.signature_help, { buffer = 0, desc = "LSP Signature help" })
|
||||
vim.keymap.set("n", "<leader>vo", ":LspRestart<cr>", { noremap = true, desc = "LSP Restart Server" })
|
||||
vim.keymap.set({ "n", "v" }, "<leader>vca", vim.lsp.buf.code_action, { buffer = 0, desc = "LSP Code actions" })
|
||||
vim.keymap.set("n", "<leader>vf", function()
|
||||
return vim.lsp.buf.format {
|
||||
async = true,
|
||||
filter = function(cli)
|
||||
return cli.name ~= "lua_ls"
|
||||
end,
|
||||
}
|
||||
end, { buffer = 0, desc = "LSP format file" })
|
||||
|
||||
telescope_mapper("gr", "lsp_references", { buffer = true, desc = "LSP References of symbol on cursor" })
|
||||
telescope_mapper("<leader>pv", "find_symbol", { buffer = true, desc = "LSP find symbol on the project" })
|
||||
telescope_mapper("<leader>pd", "lsp_document_symbols", { buffer = true, desc = "LSP document symbols" })
|
||||
telescope_mapper("gd", "lsp_definitions", { buffer = true, desc = "LSP go to definition" })
|
||||
|
||||
vim.bo.omnifunc = "v:lua.vim.lsp.omnifunc"
|
||||
|
||||
if client.server_capabilities.inlayHintProvider then
|
||||
vim.lsp.inlay_hint(bufnr, true)
|
||||
end
|
||||
end
|
||||
26
lua/alpha/lsp/default.lua
Normal file
26
lua/alpha/lsp/default.lua
Normal file
@@ -0,0 +1,26 @@
|
||||
return {
|
||||
mason = {
|
||||
enable = true,
|
||||
auto_install = false,
|
||||
},
|
||||
servers = {
|
||||
emmet_ls = { enable = true },
|
||||
gopls = { enable = true },
|
||||
html = { enable = true },
|
||||
jsonls = { enable = true },
|
||||
lua_ls = { enable = true, neodev = true },
|
||||
nil_ls = { enable = true },
|
||||
phpactor = {enable = true },
|
||||
rust_analyzer = { enable = true },
|
||||
svelte = { enable = true },
|
||||
tailwindcss = { enable = true, filetypes = {"blade", "html", "svelte"} },
|
||||
tsserver = { enable = true },
|
||||
volar = { enable = true },
|
||||
},
|
||||
default_options = function (options)
|
||||
return vim.tbl_deep_extend("force", {
|
||||
on_attach = require"alpha.lsp.attach",
|
||||
flags = require "alpha.lsp.flags",
|
||||
}, options)
|
||||
end,
|
||||
}
|
||||
3
lua/alpha/lsp/flags.lua
Normal file
3
lua/alpha/lsp/flags.lua
Normal file
@@ -0,0 +1,3 @@
|
||||
return {
|
||||
debounce_text_changes = 150,
|
||||
}
|
||||
65
lua/alpha/lsp/init.lua
Normal file
65
lua/alpha/lsp/init.lua
Normal file
@@ -0,0 +1,65 @@
|
||||
return {
|
||||
setup = function(ops)
|
||||
ops = vim.tbl_deep_extend("force", require "alpha.lsp.default", ops)
|
||||
|
||||
local lspconfig = require "lspconfig"
|
||||
|
||||
local mason_servers = {}
|
||||
for server, options in pairs(ops.servers) do
|
||||
if options.enable == true then
|
||||
local ok, definition = pcall(require, "alpha.lsp.servers." .. server)
|
||||
local server_options
|
||||
if not ok then
|
||||
server_options = ops.default_options(options)
|
||||
else
|
||||
server_options = definition(options)
|
||||
end
|
||||
lspconfig[server].setup(server_options)
|
||||
table.insert(mason_servers, server)
|
||||
end
|
||||
end
|
||||
|
||||
-- Mason
|
||||
if ops.mason.enable then
|
||||
local mason_ops = {}
|
||||
if ops.mason.auto_install == true then
|
||||
mason_ops.ensure_installed = mason_servers
|
||||
end
|
||||
local mason_lspconfig = require "mason-lspconfig"
|
||||
mason_lspconfig.setup(mason_ops)
|
||||
end
|
||||
|
||||
-- TODO: implement null ls with options
|
||||
require "alpha.lsp.null-ls"
|
||||
|
||||
local servers = {}
|
||||
for server, options in pairs(ops.servers) do
|
||||
table.insert(servers, string.format("%s <%s>", server, options.enable))
|
||||
end
|
||||
|
||||
-- TODO: create an auto command that on write of the configuration, calls again the setup and restart the server if it's up.
|
||||
-- can get the client by name of the file
|
||||
|
||||
vim.api.nvim_create_user_command("AlphaLSP", function()
|
||||
vim.ui.select(servers, { prompt = "LSP Servers" }, function(server)
|
||||
if server == nil then
|
||||
return
|
||||
end
|
||||
|
||||
server = string.match(server, "^(.+) <")
|
||||
local path = string.format("%s/lua/alpha/lsp/servers/%s.lua", vim.fn.stdpath "config", server)
|
||||
if vim.fn.filereadable(path) == 0 then
|
||||
local create = vim.fn.confirm("Server Does Not exist. Create new server?", "&Yes\n&No\n&Cancel")
|
||||
if create ~= 1 then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local uri = vim.uri_from_fname(path)
|
||||
local buffer = vim.uri_to_bufnr(uri)
|
||||
|
||||
vim.api.nvim_win_set_buf(0, buffer)
|
||||
end)
|
||||
end, {})
|
||||
end,
|
||||
}
|
||||
23
lua/alpha/lsp/mason.lua
Normal file
23
lua/alpha/lsp/mason.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
local mason_lspconfig = require "mason-lspconfig"
|
||||
local servers = require "alpha.lsp.servers"
|
||||
local lspconfig = require "lspconfig"
|
||||
|
||||
local mason_servers = {}
|
||||
|
||||
for server, _ in pairs(servers) do
|
||||
local cmd = lspconfig[server].cmd[1]
|
||||
if vim.fn.executable(cmd) == 0 then
|
||||
table.insert(mason_servers, server)
|
||||
end
|
||||
end
|
||||
|
||||
mason_lspconfig.setup {
|
||||
-- ensure_installed = mason_servers,
|
||||
}
|
||||
|
||||
-- filter the list for the ones not globally installed
|
||||
-- require("mason-tool-installer").setup {
|
||||
-- ensure_installed = vim.tbl_filter(function (tool)
|
||||
-- return vim.fn.executable(tool) == 0
|
||||
-- end, require "alpha.lsp.tools"),
|
||||
-- }
|
||||
53
lua/alpha/lsp/null-ls.lua
Normal file
53
lua/alpha/lsp/null-ls.lua
Normal file
@@ -0,0 +1,53 @@
|
||||
local null_ls = require "null-ls"
|
||||
-- local php_actions = require "php-code-actions"
|
||||
-- local laravel_actions = require("laravel.code-actions")
|
||||
|
||||
null_ls.setup {
|
||||
sources = {
|
||||
-- null_ls.builtins.code_actions.gitsigns,
|
||||
null_ls.builtins.formatting.jq,
|
||||
null_ls.builtins.code_actions.refactoring,
|
||||
null_ls.builtins.formatting.alejandra,
|
||||
null_ls.builtins.diagnostics.luacheck,
|
||||
null_ls.builtins.formatting.stylua,
|
||||
|
||||
null_ls.builtins.diagnostics.yamllint,
|
||||
|
||||
-- php_actions.getter_setter,
|
||||
-- php_actions.file_creator,
|
||||
|
||||
-- null_ls.builtins.diagnostics.phpstan.with {
|
||||
-- to_temp_file = false,
|
||||
-- method = null_ls.methods.DIAGNOSTICS_ON_SAVE,
|
||||
-- -- command = "./bin/phpstan",
|
||||
-- -- condition = function ()
|
||||
-- -- return vim.fn.findfile("bin/phpstan") ~= ""
|
||||
-- -- end
|
||||
-- },
|
||||
null_ls.builtins.diagnostics.phpcs.with {
|
||||
method = null_ls.methods.DIAGNOSTICS_ON_SAVE,
|
||||
condition = function(utils)
|
||||
return utils.root_has_file "phpcs.xml"
|
||||
end,
|
||||
},
|
||||
null_ls.builtins.formatting.pint,
|
||||
},
|
||||
}
|
||||
|
||||
vim.keymap.set({ "n", "v" }, "<leader>vca", vim.lsp.buf.code_action, {desc = "LSP (null ls) Code actions"})
|
||||
vim.keymap.set("n", "<leader>vf", function()
|
||||
return vim.lsp.buf.format { async = true }
|
||||
end, {desc = "LSP (null ls) Format file"})
|
||||
|
||||
-- function to toogle and possible restart it
|
||||
vim.api.nvim_create_user_command("NullLsToggle", function()
|
||||
local sources = vim.tbl_map(function(el)
|
||||
return el.name
|
||||
end, null_ls.get_sources())
|
||||
vim.ui.select(sources, {}, function(selected)
|
||||
if not selected then
|
||||
return
|
||||
end
|
||||
null_ls.toggle(selected)
|
||||
end)
|
||||
end, {})
|
||||
12
lua/alpha/lsp/servers/emmet_ls.lua
Normal file
12
lua/alpha/lsp/servers/emmet_ls.lua
Normal file
@@ -0,0 +1,12 @@
|
||||
local lsp_attach = require "alpha.lsp.attach"
|
||||
local lsp_flags = require "alpha.lsp.flags"
|
||||
|
||||
return function(ops)
|
||||
local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
|
||||
return vim.tbl_extend("force", {
|
||||
on_attach = lsp_attach,
|
||||
flags = lsp_flags,
|
||||
capabilities = capabilities,
|
||||
filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "blade", "vue" },
|
||||
}, ops)
|
||||
end
|
||||
14
lua/alpha/lsp/servers/html.lua
Normal file
14
lua/alpha/lsp/servers/html.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
local lsp_attach = require "alpha.lsp.attach"
|
||||
local lsp_flags = require "alpha.lsp.flags"
|
||||
|
||||
return function(ops)
|
||||
local config = {
|
||||
on_attach = lsp_attach,
|
||||
flags = lsp_flags,
|
||||
}
|
||||
if vim.fn.executable "html-languageserver" == 1 then
|
||||
config.cmd = { "html-languageserver", "--stdio" }
|
||||
end
|
||||
|
||||
return vim.tbl_extend("force", config, ops)
|
||||
end
|
||||
14
lua/alpha/lsp/servers/jsonls.lua
Normal file
14
lua/alpha/lsp/servers/jsonls.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
local lsp_attach = require "alpha.lsp.attach"
|
||||
local lsp_flags = require "alpha.lsp.flags"
|
||||
|
||||
return function(ops)
|
||||
local config = {
|
||||
on_attach = lsp_attach,
|
||||
flags = lsp_flags,
|
||||
}
|
||||
if vim.fn.executable "json-languageserver" == 1 then
|
||||
config.cmd = { "json-languageserver", "--stdio" }
|
||||
end
|
||||
|
||||
return vim.tbl_extend("force", config, ops)
|
||||
end
|
||||
36
lua/alpha/lsp/servers/lua_ls.lua
Normal file
36
lua/alpha/lsp/servers/lua_ls.lua
Normal file
@@ -0,0 +1,36 @@
|
||||
local lsp_attach = require "alpha.lsp.attach"
|
||||
local lsp_flags = require "alpha.lsp.flags"
|
||||
|
||||
return function(ops)
|
||||
if ops.neodev == true then
|
||||
require("neodev").setup()
|
||||
end
|
||||
|
||||
return vim.tbl_extend("force", {
|
||||
on_attach = lsp_attach,
|
||||
flags = lsp_flags,
|
||||
settings = {
|
||||
Lua = {
|
||||
runtime = {
|
||||
version = "LuaJIT",
|
||||
},
|
||||
diagnostics = {
|
||||
globals = { "vim" },
|
||||
},
|
||||
workspace = {
|
||||
library = vim.api.nvim_get_runtime_file("", true),
|
||||
checkThirdParty = false,
|
||||
},
|
||||
telemetry = {
|
||||
enable = false,
|
||||
},
|
||||
hint = {
|
||||
enable = true,
|
||||
},
|
||||
completion = {
|
||||
callSnippet = "Replace",
|
||||
},
|
||||
},
|
||||
},
|
||||
}, ops)
|
||||
end
|
||||
80
lua/alpha/lsp/servers/phpactor.lua
Normal file
80
lua/alpha/lsp/servers/phpactor.lua
Normal file
@@ -0,0 +1,80 @@
|
||||
local lsp_attach = require "alpha.lsp.attach"
|
||||
local lsp_flags = require "alpha.lsp.flags"
|
||||
|
||||
local function phpactor_attach(_, bufnr)
|
||||
vim.api.nvim_buf_create_user_command(bufnr, "LspPhpactorReindex", function()
|
||||
vim.lsp.buf_notify(bufnr, "phpactor/index/reindex", {})
|
||||
end, {})
|
||||
|
||||
vim.api.nvim_buf_create_user_command(bufnr, "LspPhpactorStatus", function()
|
||||
local results, _ = vim.lsp.buf_request_sync(bufnr, "phpactor/status", { ["return"] = true })
|
||||
|
||||
local content = ""
|
||||
|
||||
for _, res in pairs(results or {}) do
|
||||
if res ~= nil and res["result"] ~= nil then
|
||||
content = content .. res["result"]
|
||||
end
|
||||
end
|
||||
|
||||
local Popup = require "nui.popup"
|
||||
local event = require("nui.utils.autocmd").event
|
||||
|
||||
local popup = Popup {
|
||||
enter = true,
|
||||
focusable = true,
|
||||
border = {
|
||||
style = "rounded",
|
||||
},
|
||||
position = "50%",
|
||||
size = {
|
||||
width = "80%",
|
||||
height = "60%",
|
||||
},
|
||||
}
|
||||
|
||||
-- mount/open the component
|
||||
popup:mount()
|
||||
|
||||
-- unmount component when cursor leaves buffer
|
||||
popup:on(event.BufLeave, function()
|
||||
popup:unmount()
|
||||
end)
|
||||
local out = {}
|
||||
for match in string.gmatch(content, "[^\n]+") do
|
||||
table.insert(out, match)
|
||||
end
|
||||
|
||||
vim.api.nvim_buf_set_option(popup.bufnr, "filetype", "markdown")
|
||||
vim.api.nvim_buf_set_lines(popup.bufnr, 0, 1, false, out)
|
||||
end, {})
|
||||
end
|
||||
|
||||
return function(ops)
|
||||
return vim.tbl_extend("force", {
|
||||
on_attach = function(client, bufnr)
|
||||
lsp_attach(client, bufnr)
|
||||
phpactor_attach(client, bufnr)
|
||||
end,
|
||||
flags = lsp_flags,
|
||||
filetypes = { "php", "blade" },
|
||||
init_options = {
|
||||
["language_server_worse_reflection.inlay_hints.enable"] = true,
|
||||
["language_server_worse_reflection.inlay_hints.params"] = true,
|
||||
-- ["language_server_worse_reflection.inlay_hints.types"] = true,
|
||||
["language_server_configuration.auto_config"] = false,
|
||||
["code_transform.import_globals"] = true,
|
||||
["language_server_phpstan.enabled"] = true,
|
||||
["language_server_phpstan.level"] = 7,
|
||||
["language_server_phpstan.bin"] = "phpstan",
|
||||
},
|
||||
handlers = {
|
||||
["textDocument/inlayHint"] = function(err, result, ...)
|
||||
for _, res in ipairs(result) do
|
||||
res.label = res.label .. ": "
|
||||
end
|
||||
vim.lsp.handlers["textDocument/inlayHint"](err, result, ...)
|
||||
end,
|
||||
},
|
||||
}, ops)
|
||||
end
|
||||
24
lua/alpha/lsp/servers/rust_analyzer.lua
Normal file
24
lua/alpha/lsp/servers/rust_analyzer.lua
Normal file
@@ -0,0 +1,24 @@
|
||||
local lsp_attach = require "alpha.lsp.attach"
|
||||
local lsp_flags = require "alpha.lsp.flags"
|
||||
|
||||
return function(ops)
|
||||
return vim.tbl_extend("force", {
|
||||
on_attach = lsp_attach,
|
||||
flags = lsp_flags,
|
||||
settings = {
|
||||
["rust-analyzer"] = {
|
||||
checkOnSave = {
|
||||
allFeatures = true,
|
||||
overrideCommand = {
|
||||
"cargo",
|
||||
"clippy",
|
||||
"--workspace",
|
||||
"--message-format=json",
|
||||
"--all-targets",
|
||||
"--all-features",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, ops)
|
||||
end
|
||||
33
lua/alpha/lsp/servers/tsserver.lua
Normal file
33
lua/alpha/lsp/servers/tsserver.lua
Normal file
@@ -0,0 +1,33 @@
|
||||
local lsp_attach = require "alpha.lsp.attach"
|
||||
local lsp_flags = require "alpha.lsp.flags"
|
||||
|
||||
return function(ops)
|
||||
return vim.tbl_extend("force", {
|
||||
on_attach = lsp_attach,
|
||||
flags = lsp_flags,
|
||||
settings = {
|
||||
typescript = {
|
||||
inlayHints = {
|
||||
includeInlayParameterNameHints = "all",
|
||||
includeInlayParameterNameHintsWhenArgumentMatchesName = false,
|
||||
includeInlayFunctionParameterTypeHints = true,
|
||||
includeInlayVariableTypeHints = true,
|
||||
includeInlayPropertyDeclarationTypeHints = true,
|
||||
includeInlayFunctionLikeReturnTypeHints = true,
|
||||
includeInlayEnumMemberValueHints = true,
|
||||
},
|
||||
},
|
||||
javascript = {
|
||||
inlayHints = {
|
||||
includeInlayParameterNameHints = "all",
|
||||
includeInlayParameterNameHintsWhenArgumentMatchesName = false,
|
||||
includeInlayFunctionParameterTypeHints = true,
|
||||
includeInlayVariableTypeHints = true,
|
||||
includeInlayPropertyDeclarationTypeHints = true,
|
||||
includeInlayFunctionLikeReturnTypeHints = true,
|
||||
includeInlayEnumMemberValueHints = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}, ops)
|
||||
end
|
||||
8
lua/alpha/lsp/tools.lua
Normal file
8
lua/alpha/lsp/tools.lua
Normal file
@@ -0,0 +1,8 @@
|
||||
return {
|
||||
"codelldb",
|
||||
"go-debug-adapter",
|
||||
"js-debug-adapter",
|
||||
"php-debug-adapter",
|
||||
"phpcs",
|
||||
"phpstan",
|
||||
}
|
||||
Reference in New Issue
Block a user