62
62
local _declined_installs = {}
63
63
64
64
--- @param rocks Rock[]
65
- local function prompt_auto_install (rocks )
66
- local rock_name = rocks [1 ].name
67
- if _declined_installs [rock_name ] then
68
- return
69
- end
70
- --- @param version string ?
71
- local function install_rock_or_mark_declined (version )
72
- if version then
73
- api .install (rock_name , version , function (installed_rock )
74
- --- @cast installed_rock Rock
75
- try_start_highlight (installed_rock )
76
- end )
77
- else
78
- _declined_installs [rock_name ] = true
79
- end
80
- end
81
- if vim .tbl_isempty (rocks ) then
82
- return
83
- end
84
- local choice = vim .fn .confirm (" Install " .. rocks [1 ].name .. " ?" , " &Yes\n &No" , 2 , " Question" )
85
- if # rocks == 1 then
86
- install_rock_or_mark_declined (choice == 1 and rocks [1 ].version or nil )
87
- elseif # rocks > 1 then
88
- local latest_version = vim .iter (rocks ):fold (
65
+ local function install_latest_version (rocks )
66
+ local latest_version = rocks [1 ].version
67
+ if # rocks > 1 then
68
+ latest_version = vim .iter (rocks ):fold (
89
69
nil ,
90
- --- @param latest_version vim.Version | nil
70
+ --- @param latest_version_ vim.Version | nil
91
71
--- @param rock Rock
92
- function (latest_version , rock )
72
+ function (latest_version_ , rock )
93
73
--- @type boolean , vim.Version ?
94
74
local ok , version = pcall (vim .version .parse , rock .version )
95
- if latest_version then
96
- return (ok and version and version > latest_version and version ) or latest_version
75
+ if latest_version_ then
76
+ return (ok and version and version > latest_version_ and version ) or latest_version_
97
77
else
98
78
return ok and version
99
79
end
100
80
end
101
81
)
102
- install_rock_or_mark_declined (choice == 1 and tostring (latest_version or " dev" ) or nil )
82
+ end
83
+ api .install (rocks [1 ].name , tostring (latest_version or " dev" ), try_start_highlight )
84
+ end
85
+
86
+ --- @param rocks Rock[]
87
+ local function prompt_auto_install (rocks )
88
+ local rock_name = rocks [1 ].name
89
+ if _declined_installs [rock_name ] then
90
+ return
91
+ end
92
+ if vim .tbl_isempty (rocks ) then
93
+ return
94
+ end
95
+ local choice = vim .fn .confirm (" Install " .. rocks [1 ].name .. " ?" , " &Yes\n &No" , 2 , " Question" )
96
+ if choice == 1 then
97
+ install_latest_version (rocks )
98
+ else
99
+ _declined_installs [rock_name ] = true
103
100
end
104
101
end
105
102
@@ -118,7 +115,7 @@ local function do_highlight(lang)
118
115
prompt_auto_install (rocks )
119
116
end )
120
117
elseif config .auto_install then
121
- api . install (rocks [ 1 ]. name , nil , try_start_highlight )
118
+ install_latest_version (rocks )
122
119
end
123
120
end )
124
121
end
0 commit comments