diff options
Diffstat (limited to 'lua/alpha/php')
| -rw-r--r-- | lua/alpha/php/lsp.lua | 26 | ||||
| -rw-r--r-- | lua/alpha/php/servers.lua | 17 |
2 files changed, 31 insertions, 12 deletions
diff --git a/lua/alpha/php/lsp.lua b/lua/alpha/php/lsp.lua index 8a92b0e..6845d1c 100644 --- a/lua/alpha/php/lsp.lua +++ b/lua/alpha/php/lsp.lua @@ -70,14 +70,23 @@ lsp.find = function(search, client) end if class_location == nil then - P("Did not found any class") + P("Did not found any class: " .. class) return end + local command = "edit" + local filename = class_location.filename + + if vim.api.nvim_buf_get_name(0) ~= filename or command ~= "edit" then + filename = Path:new(vim.fn.fnameescape(filename)):normalize(vim.loop.cwd()) + pcall(vim.cmd, string.format("%s %s", command, filename)) + end + + local params = vim.lsp.util.make_position_params(0) vim.lsp.buf_request( - buffer, - "workspace/symbol", - { query = method }, + 0, + "textDocument/documentSymbol", + params, function(method_err, method_server_result, _, _) if err then vim.api.nvim_err_writeln("Error when finding workspace symbols: " .. method_err.message) @@ -92,7 +101,7 @@ lsp.find = function(search, client) local method_location = nil for _, value in ipairs(method_locations) do - if value.filename == class_location.filename then + if value.text == string.format("[Method] %s", method) then method_location = value break end @@ -102,16 +111,9 @@ lsp.find = function(search, client) return end - local command = "edit" - local filename = method_location.filename local row = method_location.lnum local col = method_location.col - 1 - if vim.api.nvim_buf_get_name(0) ~= filename or command ~= "edit" then - filename = Path:new(vim.fn.fnameescape(filename)):normalize(vim.loop.cwd()) - pcall(vim.cmd, string.format("%s %s", command, filename)) - end - if row and col then local ok, err_msg = pcall(vim.api.nvim_win_set_cursor, 0, { row, col }) if not ok then diff --git a/lua/alpha/php/servers.lua b/lua/alpha/php/servers.lua index 78c99a8..caab4a8 100644 --- a/lua/alpha/php/servers.lua +++ b/lua/alpha/php/servers.lua @@ -1,5 +1,10 @@ local phpactor = {} +-- TODO possible improvement look how it works underline +-- use the client directly to call, no need for the buffer +-- to find a class. +-- vim.lsp.start() should return the client + function phpactor.findclass(buffer, fqn, callback) local class_parts = vim.split(fqn, "\\") local class = class_parts[#class_parts] @@ -23,6 +28,18 @@ function phpactor.findclass(buffer, fqn, callback) end) end +-- getting the config I can re use the client +-- the next thing is to make the request with the client +local config = require("lspconfig").phpactor +config.root_dir = vim.fn.getcwd() +local client_id = vim.lsp.start( + config +); + +local client = vim.lsp.get_client_by_id(client_id) +P(client) +-- use client.request or request_sync +-- look for the direct of the symbol return { phpactor = phpactor, } |