Skip to content

Commit 19a9552

Browse files
committed
Merge remote-tracking branch 'origin/main' into vuxuanhungg/main
* origin/main: fix(fs): fall back to `fs_stat` if entry type is not returned by `fs_readdir` (mason-org#1783) fix: avoid calling vim.fn in fast event (mason-org#1878) fix(ui): reposition window if border is different than "none" (mason-org#1859) fix: replace deprecated calls to vim.validate (mason-org#1876) tests: add new nvim versions to test matrix (mason-org#1877)
2 parents bb1fdfa + 1114b23 commit 19a9552

File tree

6 files changed

+120
-78
lines changed

6 files changed

+120
-78
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
nvim_version:
15-
- v0.7.0
16-
- v0.7.2
1715
- v0.8.0
1816
- v0.8.1
1917
- v0.8.2
@@ -24,6 +22,10 @@ jobs:
2422
- v0.9.4
2523
- v0.9.5
2624
- v0.10.0
25+
- v0.10.1
26+
- v0.10.2
27+
- v0.10.3
28+
- v0.10.4
2729
runs-on: ubuntu-latest
2830
steps:
2931
- uses: actions/checkout@v4

lua/mason-core/fs.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ local function make_module(uv)
134134
log.trace("fs: fs_readdir", path, entries)
135135
if entries and #entries > 0 then
136136
for i = 1, #entries do
137+
if entries[i].name and not entries[i].type then
138+
-- See https://github.com/luvit/luv/issues/660
139+
local full_path = Path.concat { path, entries[i].name }
140+
log.trace("fs: fs_readdir falling back to fs_stat to find type", full_path)
141+
local stat = uv.fs_stat(full_path)
142+
entries[i].type = stat.type
143+
end
137144
all_entries[#all_entries + 1] = entries[i]
138145
end
139146
else

lua/mason-core/package/init.lua

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ local a = require "mason-core.async"
77
local fs = require "mason-core.fs"
88
local log = require "mason-core.log"
99
local path = require "mason-core.path"
10+
local platform = require "mason-core.platform"
1011
local registry = require "mason-registry"
1112

1213
local is_not_nil = _.complement(_.is_nil)
@@ -86,30 +87,33 @@ local PackageMt = { __index = Package }
8687
---@field opt table<string, string>?
8788

8889
---@param spec PackageSpec | RegistryPackageSpec
89-
function Package.new(spec)
90+
local function validate_spec(spec)
91+
if platform.cached_features["nvim-0.11"] ~= 1 then
92+
return
93+
end
9094
if is_registry_spec(spec) then
91-
vim.validate {
92-
name = { spec.name, "s" },
93-
description = { spec.description, "s" },
94-
homepage = { spec.homepage, "s" },
95-
licenses = { spec.licenses, "t" },
96-
categories = { spec.categories, "t" },
97-
languages = { spec.languages, "t" },
98-
source = { spec.source, "t" },
99-
bin = { spec.bin, { "t", "nil" } },
100-
share = { spec.share, { "t", "nil" } },
101-
}
95+
vim.validate("name", spec.name, "string")
96+
vim.validate("description", spec.description, "string")
97+
vim.validate("homepage", spec.homepage, "string")
98+
vim.validate("licenses", spec.licenses, "table")
99+
vim.validate("categories", spec.categories, "table")
100+
vim.validate("languages", spec.languages, "table")
101+
vim.validate("source", spec.source, "table")
102+
vim.validate("bin", spec.bin, { "table", "nil" })
103+
vim.validate("share", spec.share, { "table", "nil" })
102104
else
103-
vim.validate {
104-
name = { spec.name, "s" },
105-
desc = { spec.desc, "s" },
106-
homepage = { spec.homepage, "s" },
107-
categories = { spec.categories, "t" },
108-
languages = { spec.languages, "t" },
109-
install = { spec.install, "f" },
110-
}
105+
vim.validate("name", spec.name, "string")
106+
vim.validate("desc", spec.desc, "string")
107+
vim.validate("homepage", spec.homepage, "string")
108+
vim.validate("categories", spec.categories, "table")
109+
vim.validate("languages", spec.languages, "table")
110+
vim.validate("install", spec.install, "function")
111111
end
112+
end
112113

114+
---@param spec PackageSpec | RegistryPackageSpec
115+
function Package.new(spec)
116+
validate_spec(spec)
113117
return EventEmitter.init(setmetatable({
114118
name = spec.name, -- for convenient access
115119
spec = spec,

lua/mason-core/platform.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,15 @@ end)
6666

6767
-- Most of the code that calls into these functions executes outside of the main event loop, where API/fn functions are
6868
-- disabled. We evaluate these immediately here to avoid issues with main loop synchronization.
69-
local cached_features = {
69+
M.cached_features = {
7070
["win"] = vim.fn.has "win32",
7171
["win32"] = vim.fn.has "win32",
7272
["win64"] = vim.fn.has "win64",
7373
["mac"] = vim.fn.has "mac",
7474
["darwin"] = vim.fn.has "mac",
7575
["unix"] = vim.fn.has "unix",
7676
["linux"] = vim.fn.has "linux",
77+
["nvim-0.11"] = vim.fn.has "nvim-0.11",
7778
}
7879

7980
---@type fun(env: string): boolean
@@ -104,7 +105,7 @@ local check_env = _.memoize(_.cond {
104105
M.is = setmetatable({}, {
105106
__index = function(__, key)
106107
local os, arch, env = unpack(vim.split(key, "_", { plain = true }))
107-
if not cached_features[os] or cached_features[os] ~= 1 then
108+
if not M.cached_features[os] or M.cached_features[os] ~= 1 then
108109
return false
109110
end
110111
if arch and arch ~= M.arch then

lua/mason-core/ui/display.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,10 @@ M._render_node = render_node
170170

171171
---@alias WindowOpts { effects?: table<string, fun()>, winhighlight?: string[], border?: string|table }
172172

173-
---@param size integer | float
173+
---@param size number
174174
---@param viewport integer
175175
local function calc_size(size, viewport)
176-
if size <= 1 then
177-
return math.ceil(size * viewport)
178-
end
179-
return math.min(size, viewport)
176+
return size > 1 and math.min(size, viewport) or math.floor(size * viewport)
180177
end
181178

182179
---@param opts WindowOpts
@@ -188,6 +185,11 @@ local function create_popup_window_opts(opts, sizes_only)
188185
local width = calc_size(settings.current.ui.width, columns)
189186
local row = math.floor((lines - height) / 2)
190187
local col = math.floor((columns - width) / 2)
188+
if opts.border ~= "none" then
189+
row = math.max(row - 1, 0)
190+
col = math.max(col - 1, 0)
191+
end
192+
191193
local popup_layout = {
192194
height = height,
193195
width = width,

tests/mason-core/package/package_spec.lua

Lines changed: 75 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -23,60 +23,62 @@ describe("package", function()
2323
assert.same({ "rust-analyzer", "nightly" }, parse "rust-analyzer@nightly")
2424
end)
2525

26-
it("should validate spec", function()
27-
local valid_spec = {
28-
name = "Package name",
29-
desc = "Package description",
30-
homepage = "https://example.com",
31-
categories = { Pkg.Cat.LSP },
32-
languages = { Pkg.Lang.Rust },
33-
install = function() end,
34-
}
35-
local function spec(fields)
36-
return setmetatable(fields, { __index = valid_spec })
37-
end
38-
assert.equals(
39-
"name: expected string, got number",
40-
assert.has_error(function()
41-
Pkg.new(spec { name = 23 })
42-
end)
43-
)
26+
if vim.fn.has "nvim-0.11" == 1 then
27+
it("should validate spec", function()
28+
local valid_spec = {
29+
name = "Package name",
30+
desc = "Package description",
31+
homepage = "https://example.com",
32+
categories = { Pkg.Cat.LSP },
33+
languages = { Pkg.Lang.Rust },
34+
install = function() end,
35+
}
36+
local function spec(fields)
37+
return setmetatable(fields, { __index = valid_spec })
38+
end
39+
assert.equals(
40+
"name: expected string, got number",
41+
assert.has_error(function()
42+
Pkg.new(spec { name = 23 })
43+
end)
44+
)
4445

45-
assert.equals(
46-
"desc: expected string, got number",
47-
assert.has_error(function()
48-
Pkg.new(spec { desc = 23 })
49-
end)
50-
)
46+
assert.equals(
47+
"desc: expected string, got number",
48+
assert.has_error(function()
49+
Pkg.new(spec { desc = 23 })
50+
end)
51+
)
5152

52-
assert.equals(
53-
"homepage: expected string, got number",
54-
assert.has_error(function()
55-
Pkg.new(spec { homepage = 23 })
56-
end)
57-
)
53+
assert.equals(
54+
"homepage: expected string, got number",
55+
assert.has_error(function()
56+
Pkg.new(spec { homepage = 23 })
57+
end)
58+
)
5859

59-
assert.equals(
60-
"categories: expected table, got number",
61-
assert.has_error(function()
62-
Pkg.new(spec { categories = 23 })
63-
end)
64-
)
60+
assert.equals(
61+
"categories: expected table, got number",
62+
assert.has_error(function()
63+
Pkg.new(spec { categories = 23 })
64+
end)
65+
)
6566

66-
assert.equals(
67-
"languages: expected table, got number",
68-
assert.has_error(function()
69-
Pkg.new(spec { languages = 23 })
70-
end)
71-
)
67+
assert.equals(
68+
"languages: expected table, got number",
69+
assert.has_error(function()
70+
Pkg.new(spec { languages = 23 })
71+
end)
72+
)
7273

73-
assert.equals(
74-
"install: expected function, got number",
75-
assert.has_error(function()
76-
Pkg.new(spec { install = 23 })
77-
end)
78-
)
79-
end)
74+
assert.equals(
75+
"install: expected function, got number",
76+
assert.has_error(function()
77+
Pkg.new(spec { install = 23 })
78+
end)
79+
)
80+
end)
81+
end
8082

8183
it("should create new handle", function()
8284
local dummy = registry.get_package "dummy"
@@ -191,4 +193,28 @@ describe("package", function()
191193
end)
192194
end)
193195
)
196+
197+
it(
198+
"should be able to instantiate package outside of main loop",
199+
async_test(function()
200+
local dummy = registry.get_package "registry"
201+
202+
-- Move outside the main loop
203+
a.wait(function(resolve)
204+
local timer = vim.loop.new_timer()
205+
timer:start(0, 0, function()
206+
timer:close()
207+
resolve()
208+
end)
209+
end)
210+
211+
assert.is_true(vim.in_fast_event())
212+
213+
local pkg = assert.is_not.has_error(function()
214+
return Pkg.new(dummy.spec)
215+
end)
216+
217+
assert.same(dummy.spec, pkg.spec)
218+
end)
219+
)
194220
end)

0 commit comments

Comments
 (0)