aboutsummaryrefslogtreecommitdiffstats
path: root/lua/alpha
diff options
context:
space:
mode:
authorAriel D'Alessandro <dalessandro.ariel@gmail.com>2023-09-22 09:29:03 +0200
committerAriel D'Alessandro <dalessandro.ariel@gmail.com>2023-09-22 09:29:03 +0200
commit213e644fd7f152ade9cd5efd7e23c6d6e8cde40d (patch)
tree397a08edaecdca16c037af059710cd6b7213c162 /lua/alpha
parentaf18201866ea29d179fd61bacd36b849a7d86a7d (diff)
downloadnvim-conf-213e644fd7f152ade9cd5efd7e23c6d6e8cde40d.tar.gz
nvim-conf-213e644fd7f152ade9cd5efd7e23c6d6e8cde40d.zip
Move php function of attach to the server file
Diffstat (limited to 'lua/alpha')
-rw-r--r--lua/alpha/lsp/attach.lua61
-rw-r--r--lua/alpha/lsp/servers/phpactor.lua54
2 files changed, 53 insertions, 62 deletions
diff --git a/lua/alpha/lsp/attach.lua b/lua/alpha/lsp/attach.lua
index a6d5257..e71cb75 100644
--- a/lua/alpha/lsp/attach.lua
+++ b/lua/alpha/lsp/attach.lua
@@ -1,64 +1,6 @@
local telescope_mapper = require "alpha.telescope.mappings"
-local filetype_attach = setmetatable({
- php = function(_, 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,
-}, {
- __index = function()
- return function() end
- end,
-})
-
return function(client, bufnr)
- local filetype = vim.api.nvim_buf_get_option(0, "filetype")
-- 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" })
@@ -84,7 +26,4 @@ return function(client, bufnr)
if client.server_capabilities.inlayHintProvider then
vim.lsp.inlay_hint(bufnr, true)
end
-
- -- Attach any filetype specific options to the client
- filetype_attach[filetype](client, bufnr)
end
diff --git a/lua/alpha/lsp/servers/phpactor.lua b/lua/alpha/lsp/servers/phpactor.lua
index fd25568..e6bebcd 100644
--- a/lua/alpha/lsp/servers/phpactor.lua
+++ b/lua/alpha/lsp/servers/phpactor.lua
@@ -1,9 +1,61 @@
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 = lsp_attach,
+ on_attach = function(client, bufnr)
+ lsp_attach(client, bufnr)
+ phpactor_attach(client, bufnr)
+ end,
flags = lsp_flags,
filetypes = { "php", "blade" },
init_options = {