aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAriel D'Alessandro <ariel.dalessandro@auto1.com>2022-09-28 14:48:52 +0200
committerAriel D'Alessandro <ariel.dalessandro@auto1.com>2022-09-28 14:48:52 +0200
commit750dc94452c827e432116297e0cbd76b610ef65d (patch)
tree0546b928841581f37dc39a0e535da20d72648b83
parent3bd92df3733d21b8431e29b86c97d1715e57ffba (diff)
downloadnvim-conf-750dc94452c827e432116297e0cbd76b610ef65d.tar.gz
nvim-conf-750dc94452c827e432116297e0cbd76b610ef65d.zip
small changes, checking the changes of using phpactor
-rw-r--r--after/plugin/lsp.lua74
-rw-r--r--lua/alpha/php/lsp.lua54
-rw-r--r--lua/alpha/telescope/mappings.lua24
3 files changed, 83 insertions, 69 deletions
diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua
index 6ea0147..802f8b6 100644
--- a/after/plugin/lsp.lua
+++ b/after/plugin/lsp.lua
@@ -1,42 +1,41 @@
local telescope_mapper = require("alpha.telescope.mappings")
-
local lsp_formatting = function(bufnr, allowed_clientes)
- vim.lsp.buf.format({
- filter = function(client)
- for _, value in pairs(allowed_clientes) do
- if client.name == value then
- return true
- end
- end
-
- return false
- end,
- bufnr = bufnr,
- })
+ vim.lsp.buf.format({
+ filter = function(client)
+ for _, value in pairs(allowed_clientes) do
+ if client.name == value then
+ return true
+ end
+ end
+
+ return false
+ end,
+ bufnr = bufnr,
+ })
end
-- if you want to set up formatting on save, you can use this as a callback
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
-local format_on_save = function (allowed_clients)
- return function(client, bufnr)
- if client.supports_method("textDocument/formatting") then
- vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
- vim.api.nvim_create_autocmd("BufWritePre", {
- group = augroup,
- buffer = bufnr,
- callback = function()
- lsp_formatting(bufnr, allowed_clients)
- end,
- })
- end
- end
+local format_on_save = function(allowed_clients)
+ return function(client, bufnr)
+ if client.supports_method("textDocument/formatting") then
+ vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
+ vim.api.nvim_create_autocmd("BufWritePre", {
+ group = augroup,
+ buffer = bufnr,
+ callback = function()
+ lsp_formatting(bufnr, allowed_clients)
+ end,
+ })
+ end
+ end
end
local filetype_attach = setmetatable({
- go = format_on_save({"gopls"}),
- -- php = format_on_save,
+ go = format_on_save({ "gopls" }),
+ -- php = format_on_save,
-- lua = format_on_save,
gdscript = function(_) end,
@@ -46,13 +45,12 @@ local filetype_attach = setmetatable({
end,
})
-
-- Since I use null os this allows to have the format and actions
-- in all buffers not just configured servers
-vim.keymap.set("n", "<leader>vca", vim.lsp.buf.code_action, {})
+vim.keymap.set({ "n", "v" }, "<leader>vca", vim.lsp.buf.code_action, {})
vim.keymap.set("n", "<leader>vf", function()
- return vim.lsp.buf.format({ async = true })
+ return vim.lsp.buf.format({ async = true })
end, {})
vim.keymap.set("n", "<leader>vn", vim.diagnostic.goto_next, {})
@@ -63,9 +61,9 @@ local function on_attach(client, bufnr)
-- keymaps for lsp
vim.keymap.set("n", "K", vim.lsp.buf.hover, { buffer = 0 })
vim.keymap.set("n", "<c-]>", vim.lsp.buf.definition, { buffer = 0 })
- vim.keymap.set("n", "<leader><c-]>", function ()
- vim.cmd("vsp")
- vim.lsp.buf.definition()
+ vim.keymap.set("n", "<leader><c-]>", function()
+ vim.cmd("vsp")
+ vim.lsp.buf.definition()
end, { buffer = 0 })
vim.keymap.set("n", "<leader>vrn", vim.lsp.buf.rename, { buffer = 0 })
vim.keymap.set("i", "<c-h>", vim.lsp.buf.signature_help, { buffer = 0 })
@@ -78,11 +76,11 @@ local function on_attach(client, bufnr)
vim.bo.omnifunc = "v:lua.vim.lsp.omnifunc"
-- Attach any filetype specific options to the client
- filetype_attach[filetype](client,bufnr)
+ filetype_attach[filetype](client, bufnr)
end
vim.diagnostic.config({
- virtual_text = false,
+ virtual_text = false,
})
local signs = { Error = "⛔", Warn = "⚠️", Hint = "💡", Info = "ℹ️" }
@@ -141,8 +139,8 @@ capabilities.textDocument.completion.completionItem.snippetSupport = true
require("lspconfig").emmet_ls.setup({
on_attach = on_attach,
flags = lsp_flags,
- capabilities = capabilities,
- filetypes = { 'html', 'typescriptreact', 'javascriptreact', 'css', 'sass', 'scss', 'less', 'blade' },
+ capabilities = capabilities,
+ filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "blade" },
})
require("lspconfig").gopls.setup({
diff --git a/lua/alpha/php/lsp.lua b/lua/alpha/php/lsp.lua
index dc6fa1c..be18c79 100644
--- a/lua/alpha/php/lsp.lua
+++ b/lua/alpha/php/lsp.lua
@@ -2,15 +2,17 @@ local Path = require("plenary.path")
local lsp = {}
-lsp.get_intelephense_buffer = function ()
- local clients = vim.lsp.get_active_clients({ name = "intelephense" })
+local lsp_server_name = "phpactor"
+
+lsp.get_lsp_buffer = function ()
+ local clients = vim.lsp.get_active_clients({ name = lsp_server_name})
if #clients == 0 then
return
end
- local intelephense = clients[1]
+ local lsp_client = clients[1]
- local attached_buffers = intelephense.attached_buffers
+ local attached_buffers = lsp_client.attached_buffers
for key, val in pairs(attached_buffers) do
if val then
@@ -22,22 +24,13 @@ lsp.get_intelephense_buffer = function ()
end
-local get_index_buffer = function ()
- local uri = vim.uri_from_fname(vim.fn.getcwd() .. "/public/index.php")
- local buff = vim.uri_to_bufnr(uri)
- vim.fn.bufload(buff)
-
- return buff
-end
-
-
--- @param search string: fully name to search Class::method
lsp.find = function (search)
search = vim.split(search, "::")
- local class = search[1]
+ local fqn_class = search[1]
local method = search[2]
- local buffer = lsp.get_intelephense_buffer()
+ local buffer = lsp.get_lsp_buffer()
if buffer == nil then
-- TODO I want to not require this.
@@ -46,6 +39,21 @@ lsp.find = function (search)
return
end
+ local class_parts = vim.split(fqn_class, "\\")
+ local class = class_parts[#class_parts]
+
+ -- TODO phpactor does not support FQN search need to de sepparated
+ -- can query get the optiosn, match the full name and type class
+ -- I don't think gives the namespace
+ -- So I will get the full name, not the
+ -- the option is to get the class
+ -- open the buffer, change in the window
+ -- call the vim.lsp.buf_document_symbol({on_list = function (list) end})
+ -- grab the information and move the cursor
+ -- if method does not exist show error but stay in the class
+ -- Can have the code extracted to work with both implementations ?
+ -- Potentially could have a way to create the classes if they don't exist
+ -- With the file creater action
vim.lsp.buf_request(buffer, "workspace/symbol", { query = class }, function(err, server_result, _, _)
if err then
vim.api.nvim_err_writeln("Error when finding workspace symbols: " .. err.message)
@@ -54,11 +62,21 @@ lsp.find = function (search)
local locations = vim.lsp.util.symbols_to_items(server_result or {}, buffer) or {}
if vim.tbl_isempty(locations) then
- vim.api.nvim_err_writeln("Empty response looking for class: " .. class)
+ vim.api.nvim_err_writeln("Empty response looking for class: " .. fqn_class)
return
end
+ local class_location = nil
+ for idx, location in pairs(locations) do
+ if location.text == string.format("[Class] %s", fqn_class) then
+ class_location = locations[idx]
+ break
+ end
+ end
- local class_location = locations[1]
+ if class_location == nil then
+ P("Did not found any class")
+ return
+ end
vim.lsp.buf_request(
buffer,
@@ -72,7 +90,7 @@ lsp.find = function (search)
local method_locations = vim.lsp.util.symbols_to_items(method_server_result or {}, buffer) or {}
if vim.tbl_isempty(method_locations) then
- P("empty response looking for method")
+ P(string.format("empty response looking for method %s", method))
return
end
diff --git a/lua/alpha/telescope/mappings.lua b/lua/alpha/telescope/mappings.lua
index e389a5e..b9166ac 100644
--- a/lua/alpha/telescope/mappings.lua
+++ b/lua/alpha/telescope/mappings.lua
@@ -1,23 +1,21 @@
TelescopeMapArgs = TelescopeMapArgs or {}
-local map_tele = function(key, f, options, buffer)
- local map_key = vim.api.nvim_replace_termcodes(key .. f, true, true, true)
+local map_tele = function(key, f, options, buffer, mode)
+ mode = mode or "n"
- TelescopeMapArgs[map_key] = options or {}
-
- local mode = "n"
- local rhs = string.format("<cmd>lua R('alpha.telescope')['%s'](TelescopeMapArgs['%s'])<CR>", f, map_key)
+ local rhs = function ()
+ R('alpha.telescope')[f](options or {})
+ end
local map_options = {
- noremap = true,
+ remap = false,
silent = true,
}
+ if buffer then
+ map_options.buffer = buffer
+ end
- if not buffer then
- vim.api.nvim_set_keymap(mode, key, rhs, map_options)
- else
- vim.api.nvim_buf_set_keymap(0, mode, key, rhs, map_options)
- end
+ vim.keymap.set(mode, key, rhs, map_options)
end
-- not shure what this line does
@@ -39,7 +37,7 @@ map_tele("<leader>bp", "file_browser")
map_tele("<leader>gs", "git_status")
map_tele("<leader>ve", "diagnostics")
map_tele("<leader>fp", "my_plugins")
-map_tele("<leader>rr", "refactor")
+map_tele("<leader>rr", "refactor", {}, nil, {"n", "v"})
map_tele("<leader>pa", "laravel")
map_tele("<leader>pm", "gateway")