Skip to content

Commit 9cddec4

Browse files
authored
fix: prefer released version over dev package when using auto_install (#36)
1 parent 48a6c86 commit 9cddec4

File tree

1 file changed

+27
-30
lines changed

1 file changed

+27
-30
lines changed

lua/rocks_treesitter/highlight.lua

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -62,44 +62,41 @@ end
6262
local _declined_installs = {}
6363

6464
---@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(
8969
nil,
90-
---@param latest_version vim.Version | nil
70+
---@param latest_version_ vim.Version | nil
9171
---@param rock Rock
92-
function(latest_version, rock)
72+
function(latest_version_, rock)
9373
---@type boolean, vim.Version?
9474
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_
9777
else
9878
return ok and version
9979
end
10080
end
10181
)
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
103100
end
104101
end
105102

@@ -118,7 +115,7 @@ local function do_highlight(lang)
118115
prompt_auto_install(rocks)
119116
end)
120117
elseif config.auto_install then
121-
api.install(rocks[1].name, nil, try_start_highlight)
118+
install_latest_version(rocks)
122119
end
123120
end)
124121
end

0 commit comments

Comments
 (0)