From 5c8227d324a19c4c54d38c262241ce5687f38414 Mon Sep 17 00:00:00 2001 From: Mike Funk <639tiopl@duck.com> Date: Sun, 19 Nov 2023 14:16:41 -0800 Subject: [PATCH 1/9] Use latest neovim lsp API (#23) `vim.lsp.get_clients()` is no longer defined. Replaced by `vim.lsp.get_active_clients()`. --- lua/phpactor/utils.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/phpactor/utils.lua b/lua/phpactor/utils.lua index e90fa47..611e134 100644 --- a/lua/phpactor/utils.lua +++ b/lua/phpactor/utils.lua @@ -21,7 +21,7 @@ function utils.path(bufnr) end function utils.get_root_dir() - local buf_clients = vim.lsp.get_clients({ name = "phpactor", bufnr = 0 }) + local buf_clients = vim.lsp.get_active_clients({ name = "phpactor", bufnr = 0 }) if #buf_clients > 0 then return buf_clients[1].config.root_dir From 8c735746d1ecdda42c1034b87e314a6af6e2e9a7 Mon Sep 17 00:00:00 2001 From: gbprod Date: Thu, 4 Jan 2024 13:48:32 +0100 Subject: [PATCH 2/9] allow running commands from neo-tree (#26) Ref: #25 --- README.md | 12 ++++++++++++ lua/phpactor/command.lua | 15 ++++++++++++--- lua/phpactor/handler/new_class.lua | 5 +++-- lua/phpactor/rpc.lua | 2 +- lua/phpactor/utils.lua | 30 ++++++++++++++++++++++++++++-- 5 files changed, 56 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d3d96ee..a6eafb6 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,18 @@ Default: `{}` This is here where you can define options to pass to [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig/). Basicly, you should pass a `on_attach` function to set your mappings ;) +## 🤝 Integration + +
+nvim-neo-tree/neo-tree.nvim + +This plugin works out-of-the-box with [nvim-neo-tree/neo-tree.nvim](https://github.com/nvim-neo-tree/neo-tree.nvim). +If you execute a `PhpActor navigate` command on a file/folder in neo-tree, it will use this file as source. + +Eg. If you run `PhpActor new_class` in a neo-tree buffer, this will create a new class inside the folder you are in. + +
+ ## 🎉 Credits - [phpactor](https://github.com/phpactor/phpactor) for this awesome lsp serveur diff --git a/lua/phpactor/command.lua b/lua/phpactor/command.lua index f0fc8a2..bc211ec 100644 --- a/lua/phpactor/command.lua +++ b/lua/phpactor/command.lua @@ -13,11 +13,20 @@ function command.run(args) local options = {} - if "transform" == args.fargs[1] and nil ~= args.fargs[2] then - options.transform = args.fargs[2] + local do_run = function(cmd, ...) + for _, argument in ipairs({ ... }) do + if argument:find("=", 1) ~= nil then + local param = vim.split(argument, "=") + local key = table.remove(param, 1) + param = table.concat(param, "=") + options[key] = param + end + end + + phpactor.rpc(cmd, options) end - phpactor.rpc(args.fargs[1], options) + do_run(table.unpack(args.fargs)) end return command diff --git a/lua/phpactor/handler/new_class.lua b/lua/phpactor/handler/new_class.lua index 193fcd7..dcb45e3 100644 --- a/lua/phpactor/handler/new_class.lua +++ b/lua/phpactor/handler/new_class.lua @@ -1,8 +1,9 @@ local rpc = require("phpactor.rpc") local utils = require("phpactor.utils") -return function() +return function(options) rpc.call("class_new", { - current_path = utils.path(), + current_path = utils.folder(), + new_path = options["new_path"] or nil, }) end diff --git a/lua/phpactor/rpc.lua b/lua/phpactor/rpc.lua index e2888c0..ee13a60 100644 --- a/lua/phpactor/rpc.lua +++ b/lua/phpactor/rpc.lua @@ -119,7 +119,7 @@ function rpc.handle_input_callback(parameters) local opts = { prompt = input.parameters.label, default = input.parameters.default } if "file" == input.parameters.type then opts.completion = "file" - opts.default = utils.path() + opts.default = input.parameters.default end vim.ui.input(opts, function(item) diff --git a/lua/phpactor/utils.lua b/lua/phpactor/utils.lua index 611e134..f854cbc 100644 --- a/lua/phpactor/utils.lua +++ b/lua/phpactor/utils.lua @@ -17,11 +17,37 @@ end function utils.path(bufnr) bufnr = bufnr or 0 - return vim.api.nvim_buf_get_name(bufnr) + -- regular file + if vim.api.nvim_get_option_value("buftype", { buf = bufnr }) == "" then + return vim.api.nvim_buf_get_name(bufnr) or vim.loop.cwd() + end + + -- neo-tree + if vim.api.nvim_get_option_value("filetype", { buf = bufnr }) == "neo-tree" then + return utils.neotree_get_current_filepath() + end + + return vim.loop.cwd() +end + +function utils.neotree_get_current_filepath() + local state = require("neo-tree.sources.manager").get_state("filesystem") + + if state.tree == nil then + state = require("neo-tree.sources.manager").get_state("filesystem", nil, vim.api.nvim_get_current_win()) + end + + return state.tree:get_node().path +end + +function utils.folder(bufnr) + bufnr = bufnr or 0 + + return utils.path(bufnr):match("(.*[/\\])") end function utils.get_root_dir() - local buf_clients = vim.lsp.get_active_clients({ name = "phpactor", bufnr = 0 }) + local buf_clients = vim.lsp.get_clients({ name = "phpactor", bufnr = 0 }) if #buf_clients > 0 then return buf_clients[1].config.root_dir From 0fb2d1cf50c5b533a3fb96d076ad52487a02ef3f Mon Sep 17 00:00:00 2001 From: gbprod Date: Tue, 9 Jan 2024 15:41:59 +0100 Subject: [PATCH 3/9] fix: use get_clients only from nvim 0.10 (#29) --- lua/phpactor/utils.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/phpactor/utils.lua b/lua/phpactor/utils.lua index f854cbc..0835f20 100644 --- a/lua/phpactor/utils.lua +++ b/lua/phpactor/utils.lua @@ -47,7 +47,8 @@ function utils.folder(bufnr) end function utils.get_root_dir() - local buf_clients = vim.lsp.get_clients({ name = "phpactor", bufnr = 0 }) + local buf_clients = vim.fn.has("nvim-0.10") == 1 and vim.lsp.get_clients({ name = "phpactor", bufnr = 0 }) + or vim.lsp.get_active_clients({ name = "phpactor", bufnr = 0 }) if #buf_clients > 0 then return buf_clients[1].config.root_dir From 927ed2ff96786dcfa5809d92bd30ab8fc8f928aa Mon Sep 17 00:00:00 2001 From: gbprod Date: Thu, 18 Jan 2024 20:06:51 +0100 Subject: [PATCH 4/9] feat: introduce copy_fcqn command (#31) Fixes: #4 --- README.md | 1 + lua/phpactor.lua | 1 + lua/phpactor/handler/copy_fcqn.lua | 17 +++++++++++++++++ lua/phpactor/utils.lua | 19 +++++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 lua/phpactor/handler/copy_fcqn.lua diff --git a/README.md b/README.md index a6eafb6..92fc024 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ PhpActor [ config status cache_clear + copy_fcqn lsp/status lsp/reindex lsp/debug/config diff --git a/lua/phpactor.lua b/lua/phpactor.lua index e105655..45a875b 100644 --- a/lua/phpactor.lua +++ b/lua/phpactor.lua @@ -19,6 +19,7 @@ phpactor.AVAILABLE_RPC = { "status", "transform", "update", + "copy_fcqn", "lsp/status", "lsp/reindex", "lsp/debug/config", diff --git a/lua/phpactor/handler/copy_fcqn.lua b/lua/phpactor/handler/copy_fcqn.lua new file mode 100644 index 0000000..8fda846 --- /dev/null +++ b/lua/phpactor/handler/copy_fcqn.lua @@ -0,0 +1,17 @@ +local rpc = require("phpactor.rpc") +local utils = require("phpactor.utils") + +return function() + rpc.call("file_info", { + path = utils.path(), + }, { + callback = function(file_info) + if vim.NIL == file_info.class then + vim.notify("No php class found", vim.log.levels.ERROR, { title = "PhpActor" }) + + return + end + vim.fn.setreg(utils.get_default_register(), file_info.class) + end, + }) +end diff --git a/lua/phpactor/utils.lua b/lua/phpactor/utils.lua index 0835f20..dfe6537 100644 --- a/lua/phpactor/utils.lua +++ b/lua/phpactor/utils.lua @@ -88,4 +88,23 @@ function utils.get_open_cmd_form_target(target) return target end +function utils.get_default_register() + local clipboard_tool = vim.fn["provider#clipboard#Executable"]() + if not clipboard_tool or "" == clipboard_tool then + return '"' + end + + local clipboard_flags = vim.split(vim.api.nvim_get_option("clipboard"), ",") + + if vim.tbl_contains(clipboard_flags, "unnamedplus") then + return "+" + end + + if vim.tbl_contains(clipboard_flags, "unnamed") then + return "*" + end + + return '"' +end + return utils From 8bb5f0e290b7da7d778e5f7841e1d56e58c4a49e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frederik=20Buchl=C3=A1k?= <30214087+fbuchlak@users.noreply.github.com> Date: Wed, 31 Jan 2024 08:42:19 +0000 Subject: [PATCH 5/9] fix: table unpack compatibility (#33) --- lua/phpactor/command.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/phpactor/command.lua b/lua/phpactor/command.lua index bc211ec..15ab912 100644 --- a/lua/phpactor/command.lua +++ b/lua/phpactor/command.lua @@ -26,7 +26,8 @@ function command.run(args) phpactor.rpc(cmd, options) end - do_run(table.unpack(args.fargs)) + local table_unpack = table.unpack or unpack + do_run(table_unpack(args.fargs)) end return command From 42bdb2ea48abadc910d9f500455b811a9039e620 Mon Sep 17 00:00:00 2001 From: gbprod Date: Tue, 2 Apr 2024 10:29:57 +0200 Subject: [PATCH 6/9] fix: use pairs instead of ipairs (#35) Fixes: #34 --- lua/phpactor/handler/lsp/debug/config.lua | 2 +- lua/phpactor/handler/lsp/debug/workspace.lua | 2 +- lua/phpactor/handler/lsp/status.lua | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/phpactor/handler/lsp/debug/config.lua b/lua/phpactor/handler/lsp/debug/config.lua index 0058596..9b50a76 100644 --- a/lua/phpactor/handler/lsp/debug/config.lua +++ b/lua/phpactor/handler/lsp/debug/config.lua @@ -4,7 +4,7 @@ return function() local results, _ = vim.lsp.buf_request_sync(0, "phpactor/debug/config", { ["return"] = true }) local message = {} - for _, result in ipairs(results or {}) do + for _, result in pairs(results or {}) do message = vim.tbl_extend("force", message, vim.split(result["result"] or {}, "\n", {})) end diff --git a/lua/phpactor/handler/lsp/debug/workspace.lua b/lua/phpactor/handler/lsp/debug/workspace.lua index 29e05d0..7413006 100644 --- a/lua/phpactor/handler/lsp/debug/workspace.lua +++ b/lua/phpactor/handler/lsp/debug/workspace.lua @@ -4,7 +4,7 @@ return function() local results, _ = vim.lsp.buf_request_sync(0, "phpactor/debug/workspace", { ["return"] = true }) print(vim.inspect(results)) local message = {} - for _, result in ipairs(results or {}) do + for _, result in pairs(results or {}) do message = vim.tbl_extend("force", message, vim.split(result["result"] or "", "\n", {})) end utils.open_message_win(message) diff --git a/lua/phpactor/handler/lsp/status.lua b/lua/phpactor/handler/lsp/status.lua index a0eed21..61fce5c 100644 --- a/lua/phpactor/handler/lsp/status.lua +++ b/lua/phpactor/handler/lsp/status.lua @@ -4,7 +4,7 @@ return function() local results, _ = vim.lsp.buf_request_sync(0, "phpactor/status", { ["return"] = true }) local message = {} - for _, result in ipairs(results or {}) do + for _, result in pairs(results or {}) do message = vim.tbl_extend("force", message, vim.split(result["result"] or {}, "\n", {})) end From 4a47b60c1469df1ab5cdc75b477a83eda4d88a9b Mon Sep 17 00:00:00 2001 From: gbprod Date: Thu, 25 Apr 2024 09:22:49 +0200 Subject: [PATCH 7/9] docs: lazy install --- README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 92fc024..750a7a6 100644 --- a/README.md +++ b/README.md @@ -54,25 +54,25 @@ Eg: `:lua require('phpactor').rpc('context_menu', {})` Install the plugin with your preferred package manager: -### [packer](https://github.com/wbthomason/packer.nvim) +### [lazy.nvim](https://github.com/folke/lazy.nvim) ```lua -- Lua -use({ - "gbprod/phpactor.nvim", - run = require("phpactor.handler.update"), -- To install/update phpactor when installing this plugin - requires = { - "nvim-lua/plenary.nvim", -- required to update phpactor - "neovim/nvim-lspconfig" -- required to automaticly register lsp serveur +{ + { + "gbprod/phpactor.nvim", + build = function() + require("phpactor.handler.update")() + end, + dependencies = { + "nvim-lua/plenary.nvim", + "neovim/nvim-lspconfig" + }, + opts = { + -- you're options coes here + }, }, - config = function() - require("phpactor").setup({ - -- your configuration comes here - -- or leave it empty to use the default settings - -- refer to the configuration section below - }) - end -}) +} ``` ## ⚙️ Configuration From db250633e7b9f0e08cc7cce364de8b7adad4f6d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dr=C3=A5f=C3=B8lin?= Date: Wed, 1 May 2024 11:13:39 +0200 Subject: [PATCH 8/9] Allow for spaces in CWD (#37) * Allow for spaces in CWD * Fixed code styling --- lua/phpactor/rpc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/phpactor/rpc.lua b/lua/phpactor/rpc.lua index ee13a60..da9974b 100644 --- a/lua/phpactor/rpc.lua +++ b/lua/phpactor/rpc.lua @@ -10,7 +10,7 @@ function rpc.call(action, parameters, options) local workspace_dir = utils.get_root_dir() local cmd = string.format( - "%s %s rpc --working-dir=%s", + '%s %s rpc --working-dir "%s"', config.options.install.php_bin, config.options.install.bin, workspace_dir From f4aba0b309f74b015f4a19a07e2befd6f1a0e6ca Mon Sep 17 00:00:00 2001 From: gbprod Date: Tue, 18 Feb 2025 13:31:59 +0100 Subject: [PATCH 9/9] fix: install phpactor on first launch (#42) --- README.md | 20 ++++++++----- lua/phpactor.lua | 29 +++++++++++++++---- lua/phpactor/check_installed.lua | 8 +++++ .../{check_install.lua => check_uptodate.lua} | 4 +++ lua/phpactor/config.lua | 1 + lua/phpactor/handler/update.lua | 2 +- spec/init.lua | 6 +++- 7 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 lua/phpactor/check_installed.lua rename lua/phpactor/{check_install.lua => check_uptodate.lua} (90%) diff --git a/README.md b/README.md index 750a7a6..748bc61 100644 --- a/README.md +++ b/README.md @@ -61,15 +61,15 @@ Install the plugin with your preferred package manager: { { "gbprod/phpactor.nvim", - build = function() - require("phpactor.handler.update")() - end, + ft = "php", dependencies = { "nvim-lua/plenary.nvim", - "neovim/nvim-lspconfig" + "neovim/nvim-lspconfig", + -- If the update/install notification doesn't show properly, + -- you should also add here UI plugins like "folke/noice.nvim" or "stevearc/dressing.nvim" }, opts = { - -- you're options coes here + -- you're options goes here }, }, } @@ -139,8 +139,14 @@ Git binary. Default: `none` Accepted values: `none|daily|always` -This will check if phpactor install is up-to-date on nvim startup. This could be -slow, use wisely. +This will check if phpactor install is up-to-date when the plugin is loaded. +This could be slow, use wisely. + +### install.confirm + +Default: `true` + +If true, will ask for confirmation before installing/updating phpactor. ### `lspconfig.enabled` diff --git a/lua/phpactor.lua b/lua/phpactor.lua index 45a875b..b130f42 100644 --- a/lua/phpactor.lua +++ b/lua/phpactor.lua @@ -31,10 +31,7 @@ phpactor.AVAILABLE_RPC = { function phpactor.setup(options) config.setup(options) - vim.api.nvim_create_autocmd("VimEnter", { - pattern = "*", - callback = phpactor.check_install, - }) + vim.schedule(phpactor.check_install) if config.options.lspconfig.enabled then require("lspconfig").phpactor.setup(vim.tbl_deep_extend("force", { @@ -47,6 +44,26 @@ function phpactor.setup(options) end function phpactor.check_install() + local do_update = function(confirm_message) + if config.options.install.confirm then + vim.ui.select({ "Yes", "No" }, { + prompt = confirm_message, + }, function(item) + if item == "Yes" then + require("phpactor.handler.update")() + end + end) + else + require("phpactor.handler.update")() + end + end + + if not require("phpactor.check_installed")() then + do_update("Phpactor is not installed, would you like to install it?") + + return + end + if config.options.install.check_on_startup == "none" then return end @@ -59,8 +76,8 @@ function phpactor.check_install() vim.g.PHPACTOR_LAST_CHECK = os.date("%x") end - if not require("phpactor.check_install")() then - vim.notify("PhpActor is outdated\nrun `:PhpActor update`", vim.log.levels.INFO, { title = "PhpActor" }) + if not require("phpactor.check_uptodate")() then + do_update("Phpactor is not up-to-date, would you like to update it?") end end diff --git a/lua/phpactor/check_installed.lua b/lua/phpactor/check_installed.lua new file mode 100644 index 0000000..46ee480 --- /dev/null +++ b/lua/phpactor/check_installed.lua @@ -0,0 +1,8 @@ +local config = require("phpactor.config") +local Path = require("plenary.path") + +return function() + local phpactor_bin_path = Path:new(config.options.install.bin) + + return phpactor_bin_path:exists() +end diff --git a/lua/phpactor/check_install.lua b/lua/phpactor/check_uptodate.lua similarity index 90% rename from lua/phpactor/check_install.lua rename to lua/phpactor/check_uptodate.lua index 052b522..88432a3 100644 --- a/lua/phpactor/check_install.lua +++ b/lua/phpactor/check_uptodate.lua @@ -4,6 +4,10 @@ local Path = require("plenary.path") return function() local phpactor_path = Path:new(config.options.install.path .. "phpactor/") + if not phpactor_path:exists() then + return false + end + vim.fn.system({ config.options.install.git_bin, "-C", diff --git a/lua/phpactor/config.lua b/lua/phpactor/config.lua index 1557e03..696e354 100644 --- a/lua/phpactor/config.lua +++ b/lua/phpactor/config.lua @@ -11,6 +11,7 @@ local default_values = { composer_bin = "composer", git_bin = "git", check_on_startup = "none", + confirm = true, }, lspconfig = { enabled = true, diff --git a/lua/phpactor/handler/update.lua b/lua/phpactor/handler/update.lua index 995571f..2961997 100644 --- a/lua/phpactor/handler/update.lua +++ b/lua/phpactor/handler/update.lua @@ -32,7 +32,7 @@ return function() return end else - if require("phpactor.check_install")() then + if require("phpactor.check_uptodate")() then vim.notify("PhpActor is already up-to-date", vim.log.levels.INFO, { title = "PhpActor" }) return diff --git a/spec/init.lua b/spec/init.lua index 918398a..94bde8a 100644 --- a/spec/init.lua +++ b/spec/init.lua @@ -30,7 +30,11 @@ function M.setup() M.load("nvim-lua/plenary.nvim") M.load("neovim/nvim-lspconfig") - require("phpactor").setup() + require("phpactor").setup({ + install = { + confirm = false, + }, + }) end M.setup()