@@ -8,26 +8,48 @@ local M = {
8
8
local required_version = ' 2.0.0'
9
9
10
10
function M .install ()
11
- if M .not_installed () then
11
+ local version_info = M .get_version_info ()
12
+ if not version_info .installed then
12
13
M .run (' install' )
13
14
return true
14
15
end
15
16
16
- if M .outdated () then
17
+ if version_info .outdated then
17
18
M .run (' update' )
18
19
return true
19
20
end
20
21
22
+ if version_info .version_mismatch then
23
+ M .reinstall ()
24
+ return true
25
+ end
26
+
21
27
return false
22
28
end
23
29
24
30
function M .reinstall ()
25
31
return M .run (' reinstall' )
26
32
end
27
33
28
- function M .outdated ()
34
+ function M .get_version_info ()
35
+ local not_installed = M .not_installed ()
36
+ if not_installed then
37
+ return {
38
+ installed = false ,
39
+ installed_version = nil ,
40
+ outdated = false ,
41
+ required_version = required_version ,
42
+ version_mismatch = false ,
43
+ }
44
+ end
29
45
local installed_version = M .get_installed_version ()
30
- return vim .version .lt (installed_version , required_version )
46
+ return {
47
+ installed = true ,
48
+ installed_version = installed_version ,
49
+ outdated = vim .version .lt (installed_version , required_version ),
50
+ required_version = required_version ,
51
+ version_mismatch = installed_version ~= required_version ,
52
+ }
31
53
end
32
54
33
55
function M .not_installed ()
@@ -119,11 +141,11 @@ function M.get_path(url, type)
119
141
local is_local_path = vim .fn .isdirectory (local_path ) == 1
120
142
121
143
if is_local_path then
122
- utils .notify (' Using local version of tree-sitter grammar...' )
144
+ utils .notify (' Using local version of tree-sitter grammar...' , { id = ' orgmode-treesitter-install ' } )
123
145
return Promise .resolve (local_path )
124
146
end
125
147
126
- local path = ( ' %s/tree-sitter-org ' ): format ( vim .fn .stdpath (' cache' ))
148
+ local path = vim . fs . joinpath ( vim .fn .stdpath (' cache' ), ' tree-sitter-org ' )
127
149
vim .fn .delete (path , ' rf' )
128
150
129
151
local msg = {
@@ -132,7 +154,7 @@ function M.get_path(url, type)
132
154
reinstall = ' Reinstalling' ,
133
155
}
134
156
135
- utils .notify ((' %s tree-sitter grammar...' ):format (msg [type ]))
157
+ utils .notify ((' %s tree-sitter grammar...' ):format (msg [type ]), { id = ' orgmode-treesitter-install ' } )
136
158
return M .exe (' git' , {
137
159
args = { ' clone' , ' --filter=blob:none' , ' --depth=1' , ' --branch=' .. required_version , url , path },
138
160
}):next (function (code )
@@ -177,12 +199,16 @@ function M.run(type)
177
199
error (' [orgmode] Failed to move generated tree-sitter parser to runtime folder' , 0 )
178
200
end
179
201
utils .writefile (M .get_lock_file (), vim .json .encode ({ version = required_version })):wait ()
180
- local msg = { ' Done!' }
202
+ local msg = {
203
+ ' Tree-sitter grammar installed!' ,
204
+ (' Version: %s' ):format (required_version ),
205
+ }
181
206
if type == ' update' then
182
207
table.insert (msg , ' Please restart Neovim to apply the changes.' )
183
208
end
184
- utils .notify (msg )
185
- vim .treesitter .language .add (' org' )
209
+ utils .notify (msg , {
210
+ id = ' orgmode-treesitter-install' ,
211
+ })
186
212
return true
187
213
end ))
188
214
:wait (60000 )
0 commit comments