Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit58c25cd

Browse files
logrusxs1n7ax
andauthored
feat: adds Mason 2.0 support (#402)
* feat: Mason 2.0 migration* feat: Mason 2.0 migration Pt. 2: backward compatibility with Mason 1.x* feat: Mason 2.0 migration Pt. 3: fixed formatting and typos, added missing diagnostic disable's* feat: Mason 2.0 migration Pt. 4: fixed formatting* chore: release 3.0.0Release-As: 3.0.0---------Co-authored-by: s1n7ax <srineshnisala@gmail.com>
1 parent0831149 commit58c25cd

File tree

5 files changed

+106
-46
lines changed

5 files changed

+106
-46
lines changed

‎lazy.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ return {
1414
commit='218c0c26c14d99feca778e4d13f5ec3e8b1b60f0',
1515
},
1616
{
17-
'williamboman/mason.nvim',
17+
'mason-org/mason.nvim',
1818
-- opts = {
1919
-- registries = {
2020
-- 'github:nvim-java/mason-registry',

‎lua/java/startup/mason-dep.lua‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ local notify = require('java-core.utils.notify')
66
localasync=require('java-core.utils.async')
77
locallazy=require('java.ui.lazy')
88
localsync=async.sync
9+
localmason_v2=require('mason.version').MAJOR_VERSION==2
910

1011
localList=require('java-core.utils.list')
1112

1213
localM= {}
1314

14-
---Add custom registries tomason
15+
---Add custom registries toMason 1.x
1516
---@paramregistriesjava.Config
16-
functionM.add_custom_registries(registries)
17+
localfunctionadd_custom_registries_v1(registries)
1718
localmason_default_config=require('mason.settings').current
1819

1920
localnew_registries=
@@ -24,6 +25,21 @@ function M.add_custom_registries(registries)
2425
})
2526
end
2627

28+
---Add custom registries to Mason 2.x
29+
---@paramregistriesjava.Config
30+
localfunctionadd_custom_registries_v2(registries)
31+
for_,reginipairs(registries)do
32+
---@diagnosticdisable-next-line:undefined-field
33+
require('mason-registry').sources:prepend(reg)
34+
end
35+
end
36+
37+
ifmason_v2then
38+
M.add_custom_registries=add_custom_registries_v2
39+
else
40+
M.add_custom_registries=add_custom_registries_v1
41+
end
42+
2743
---Install mason package dependencies for nvim-java
2844
---@paramconfigjava.Config
2945
functionM.install(config)
@@ -51,7 +67,7 @@ function M.refresh_and_install(packages)
5167
lazy.close_lazy_if_opened()
5268

5369
mason_ui.open()
54-
notify.warn('Please close and re-open afterdependecies are installed')
70+
notify.warn('Please close and re-open afterdependencies are installed')
5571
end)
5672

5773
mason_util.refresh_registry()

‎lua/java/startup/mason-registry-check.lua‎

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,42 @@
1-
localmason_source=require('mason-registry.sources')
1+
localmason_v2=require('mason.version').MAJOR_VERSION==2
22

3-
localM= {
4-
JAVA_REG_ID='github:nvim-java/mason-registry',
5-
}
3+
localmason_sources
4+
5+
ifmason_v2then
6+
-- compiler will complain when Mason 1.x is used
7+
---@diagnosticdisable-next-line:undefined-field
8+
mason_sources=require('mason-registry').sources
9+
else
10+
mason_sources=require('mason-registry.sources')
11+
end
12+
13+
localM= {}
14+
ifmason_v2then
15+
M.JAVA_REG_ID='nvim-java/mason-registry'
16+
else
17+
M.JAVA_REG_ID='github:nvim-java/mason-registry'
18+
end
619

720
functionM.is_valid()
8-
localhas_reg=false
21+
localiterator
922

10-
forreginmason_source.iter()do
11-
ifreg.id==M.JAVA_REG_IDthen
12-
has_reg=true
13-
gotocontinue
14-
end
23+
ifmason_v2then
24+
-- the compiler will complain when Mason 1.x is in use
25+
---@diagnosticdisable-next-line:undefined-field
26+
iterator=mason_sources.iterate
27+
else
28+
-- the compiler will complain when Mason 2.x is in use
29+
---@diagnosticdisable-next-line:undefined-field
30+
iterator=mason_sources.iter
1531
end
1632

17-
::continue::
18-
19-
ifhas_regthen
20-
return {
21-
success=true,
22-
continue=true,
23-
}
33+
forreginiterator(mason_sources)do
34+
ifreg.id==M.JAVA_REG_IDthen
35+
return {
36+
success=true,
37+
continue=true,
38+
}
39+
end
2440
end
2541

2642
return {

‎lua/java/utils/mason.lua‎

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,60 @@ local log = require('java.utils.log')
22
localmason_reg=require('mason-registry')
33
localasync=require('java-core.utils.async')
44
localawait=async.wait_handle_ok
5+
localmason_v2=require('mason.version').MAJOR_VERSION==2
56

67
localM= {}
78

89
functionM.is_available(package_name,package_version)
9-
localhas_pkg=mason_reg.has_package(package_name)
10+
-- get_package errors if the package is not available in Mason 2.x
11+
-- it works fine in Mason 1.x this way too.
12+
localhas_pkg,pkg=pcall(mason_reg.get_package,package_name)
1013

1114
ifnothas_pkgthen
1215
returnfalse
1316
end
1417

15-
localhas_version=false
16-
17-
localpkg=mason_reg.get_package(package_name)
18-
pkg:get_installed_version(function(success,version)
19-
ifsuccessandversion==package_versionthen
20-
has_version=true
21-
end
22-
end)
18+
localinstalled_version
19+
ifmason_v2then
20+
-- the compiler will complain when Mason 1.x is in use
21+
---@diagnosticdisable-next-line:missing-parameter
22+
installed_version=pkg:get_installed_version()
23+
else
24+
-- the compiler will complain when mason 2.x is in use
25+
---@diagnosticdisable-next-line:param-type-mismatch
26+
pkg:get_installed_version(function(success,version)
27+
ifsuccessthen
28+
installed_version=version
29+
end
30+
end)
31+
end
2332

24-
returnhas_version
33+
returninstalled_version==package_version
2534
end
2635

2736
functionM.is_installed(package_name,package_version)
28-
localpkg=mason_reg.get_package(package_name)
29-
localis_installed=pkg:is_installed()
37+
-- get_package errors if the package is not available in Mason 2.x
38+
-- it works fine in Mason 1.x this way too.
39+
localfound,pkg=pcall(mason_reg.get_package,package_name)
3040

31-
ifnotis_installedthen
41+
ifnotfoundornotpkg:is_installed()then
3242
returnfalse
3343
end
3444

3545
localinstalled_version
36-
pkg:get_installed_version(function(ok,version)
37-
ifnotokthen
38-
return
39-
end
40-
41-
installed_version=version
42-
end)
46+
ifmason_v2then
47+
-- the compiler will complain when Mason 1.x is in use
48+
---@diagnosticdisable-next-line:missing-parameter
49+
installed_version=pkg:get_installed_version()
50+
else
51+
-- the compiler will complain when Mason 2.x is in use
52+
---@diagnosticdisable-next-line:param-type-mismatch
53+
pkg:get_installed_version(function(success,version)
54+
ifsuccessthen
55+
installed_version=version
56+
end
57+
end)
58+
end
4359

4460
returninstalled_version==package_version
4561
end
@@ -69,10 +85,22 @@ function M.install_pkgs(packages)
6985
ifnotM.is_installed(dep.name,dep.version)then
7086
localpkg=mason_reg.get_package(dep.name)
7187

72-
pkg:install({
73-
version=dep.version,
74-
force=true,
75-
})
88+
-- install errors if installation is already running in Mason 2.x
89+
localguard
90+
ifmason_v2then
91+
-- guard if the package is already installing in Mason 2.x
92+
-- the compiler will complain about the following line with Mason 1.x
93+
---@diagnosticdisable-next-line:undefined-field
94+
guard=pkg:is_installing()
95+
else
96+
guard=false
97+
end
98+
ifnotguardthen
99+
pkg:install({
100+
version=dep.version,
101+
force=true,
102+
})
103+
end
76104
end
77105
end
78106
end

‎tests/prepare-config.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ require('lazy').setup({
5050
lazy=false,
5151
},
5252
{
53-
'williamboman/mason.nvim',
53+
'mason-org/mason.nvim',
5454
lazy=false,
5555
},
5656
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp