Skip to content

Commit f4aba0b

Browse files
authored
fix: install phpactor on first launch (#42)
1 parent db25063 commit f4aba0b

File tree

7 files changed

+55
-15
lines changed

7 files changed

+55
-15
lines changed

README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ Install the plugin with your preferred package manager:
6161
{
6262
{
6363
"gbprod/phpactor.nvim",
64-
build = function()
65-
require("phpactor.handler.update")()
66-
end,
64+
ft = "php",
6765
dependencies = {
6866
"nvim-lua/plenary.nvim",
69-
"neovim/nvim-lspconfig"
67+
"neovim/nvim-lspconfig",
68+
-- If the update/install notification doesn't show properly,
69+
-- you should also add here UI plugins like "folke/noice.nvim" or "stevearc/dressing.nvim"
7070
},
7171
opts = {
72-
-- you're options coes here
72+
-- you're options goes here
7373
},
7474
},
7575
}
@@ -139,8 +139,14 @@ Git binary.
139139
Default: `none`
140140
Accepted values: `none|daily|always`
141141

142-
This will check if phpactor install is up-to-date on nvim startup. This could be
143-
slow, use wisely.
142+
This will check if phpactor install is up-to-date when the plugin is loaded.
143+
This could be slow, use wisely.
144+
145+
### install.confirm
146+
147+
Default: `true`
148+
149+
If true, will ask for confirmation before installing/updating phpactor.
144150

145151
### `lspconfig.enabled`
146152

lua/phpactor.lua

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ phpactor.AVAILABLE_RPC = {
3131
function phpactor.setup(options)
3232
config.setup(options)
3333

34-
vim.api.nvim_create_autocmd("VimEnter", {
35-
pattern = "*",
36-
callback = phpactor.check_install,
37-
})
34+
vim.schedule(phpactor.check_install)
3835

3936
if config.options.lspconfig.enabled then
4037
require("lspconfig").phpactor.setup(vim.tbl_deep_extend("force", {
@@ -47,6 +44,26 @@ function phpactor.setup(options)
4744
end
4845

4946
function phpactor.check_install()
47+
local do_update = function(confirm_message)
48+
if config.options.install.confirm then
49+
vim.ui.select({ "Yes", "No" }, {
50+
prompt = confirm_message,
51+
}, function(item)
52+
if item == "Yes" then
53+
require("phpactor.handler.update")()
54+
end
55+
end)
56+
else
57+
require("phpactor.handler.update")()
58+
end
59+
end
60+
61+
if not require("phpactor.check_installed")() then
62+
do_update("Phpactor is not installed, would you like to install it?")
63+
64+
return
65+
end
66+
5067
if config.options.install.check_on_startup == "none" then
5168
return
5269
end
@@ -59,8 +76,8 @@ function phpactor.check_install()
5976
vim.g.PHPACTOR_LAST_CHECK = os.date("%x")
6077
end
6178

62-
if not require("phpactor.check_install")() then
63-
vim.notify("PhpActor is outdated\nrun `:PhpActor update`", vim.log.levels.INFO, { title = "PhpActor" })
79+
if not require("phpactor.check_uptodate")() then
80+
do_update("Phpactor is not up-to-date, would you like to update it?")
6481
end
6582
end
6683

lua/phpactor/check_installed.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
local config = require("phpactor.config")
2+
local Path = require("plenary.path")
3+
4+
return function()
5+
local phpactor_bin_path = Path:new(config.options.install.bin)
6+
7+
return phpactor_bin_path:exists()
8+
end

lua/phpactor/check_install.lua renamed to lua/phpactor/check_uptodate.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ local Path = require("plenary.path")
44
return function()
55
local phpactor_path = Path:new(config.options.install.path .. "phpactor/")
66

7+
if not phpactor_path:exists() then
8+
return false
9+
end
10+
711
vim.fn.system({
812
config.options.install.git_bin,
913
"-C",

lua/phpactor/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ local default_values = {
1111
composer_bin = "composer",
1212
git_bin = "git",
1313
check_on_startup = "none",
14+
confirm = true,
1415
},
1516
lspconfig = {
1617
enabled = true,

lua/phpactor/handler/update.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ return function()
3232
return
3333
end
3434
else
35-
if require("phpactor.check_install")() then
35+
if require("phpactor.check_uptodate")() then
3636
vim.notify("PhpActor is already up-to-date", vim.log.levels.INFO, { title = "PhpActor" })
3737

3838
return

spec/init.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ function M.setup()
3030
M.load("nvim-lua/plenary.nvim")
3131
M.load("neovim/nvim-lspconfig")
3232

33-
require("phpactor").setup()
33+
require("phpactor").setup({
34+
install = {
35+
confirm = false,
36+
},
37+
})
3438
end
3539

3640
M.setup()

0 commit comments

Comments
 (0)