aboutsummaryrefslogtreecommitdiffstats
path: root/lua/alpha/php
diff options
context:
space:
mode:
Diffstat (limited to 'lua/alpha/php')
-rw-r--r--lua/alpha/php/lsp.lua30
-rw-r--r--lua/alpha/php/servers.lua28
2 files changed, 41 insertions, 17 deletions
diff --git a/lua/alpha/php/lsp.lua b/lua/alpha/php/lsp.lua
index be18c79..8a92b0e 100644
--- a/lua/alpha/php/lsp.lua
+++ b/lua/alpha/php/lsp.lua
@@ -2,40 +2,36 @@ local Path = require("plenary.path")
local lsp = {}
-local lsp_server_name = "phpactor"
-
-lsp.get_lsp_buffer = function ()
- local clients = vim.lsp.get_active_clients({ name = lsp_server_name})
+---Return a buffer id for the given client
+---@param server_name string
+---@return integer|nil
+lsp.get_lsp_buffer = function(server_name)
+ local clients = vim.lsp.get_active_clients({ name = server_name })
if #clients == 0 then
- return
+ return nil
end
- local lsp_client = clients[1]
-
- local attached_buffers = lsp_client.attached_buffers
+ local buffers = vim.lsp.get_buffers_by_client_id(clients[1].id)
- for key, val in pairs(attached_buffers) do
- if val then
- return key
- end
+ if #buffers == 0 then
+ return nil
end
- return nil
+ return buffers[1]
end
-
--- @param search string: fully name to search Class::method
-lsp.find = function (search)
+lsp.find = function(search, client)
search = vim.split(search, "::")
local fqn_class = search[1]
local method = search[2]
- local buffer = lsp.get_lsp_buffer()
+ local buffer = lsp.get_lsp_buffer(client)
if buffer == nil then
-- TODO I want to not require this.
-- I can load a buffer but does not start the lsp
- P("load a php buffer to load the lsp server")
+ vim.api.nvim_err_writeln(string.format("No buffer available for client %s", client))
return
end
diff --git a/lua/alpha/php/servers.lua b/lua/alpha/php/servers.lua
new file mode 100644
index 0000000..78c99a8
--- /dev/null
+++ b/lua/alpha/php/servers.lua
@@ -0,0 +1,28 @@
+local phpactor = {}
+
+function phpactor.findclass(buffer, fqn, callback)
+ local class_parts = vim.split(fqn, "\\")
+ local class = class_parts[#class_parts]
+
+ vim.lsp.buf_request(buffer, "workspace/symbol", { query = class }, function(err, server_result, _, _)
+ if err then
+ callback(
+ nil,
+ "Error when finding workspace symbols: " .. err.message
+ )
+
+ return
+ end
+
+ 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: " .. fqn)
+ return
+ end
+
+ end)
+end
+
+return {
+ phpactor = phpactor,
+}