@@ -8,26 +8,48 @@ local M = {
88local required_version = ' 2.0.0'
99
1010function M .install ()
11- if M .not_installed () then
11+ local version_info = M .get_version_info ()
12+ if not version_info .installed then
1213 M .run (' install' )
1314 return true
1415 end
1516
16- if M .outdated () then
17+ if version_info .outdated then
1718 M .run (' update' )
1819 return true
1920 end
2021
22+ if version_info .version_mismatch then
23+ M .reinstall ()
24+ return true
25+ end
26+
2127 return false
2228end
2329
2430function M .reinstall ()
2531 return M .run (' reinstall' )
2632end
2733
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
2945 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+ }
3153end
3254
3355function M .not_installed ()
@@ -119,11 +141,11 @@ function M.get_path(url, type)
119141 local is_local_path = vim .fn .isdirectory (local_path ) == 1
120142
121143 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 ' } )
123145 return Promise .resolve (local_path )
124146 end
125147
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 ' )
127149 vim .fn .delete (path , ' rf' )
128150
129151 local msg = {
@@ -132,7 +154,7 @@ function M.get_path(url, type)
132154 reinstall = ' Reinstalling' ,
133155 }
134156
135- utils .notify ((' %s tree-sitter grammar...' ):format (msg [type ]))
157+ utils .notify ((' %s tree-sitter grammar...' ):format (msg [type ]), { id = ' orgmode-treesitter-install ' } )
136158 return M .exe (' git' , {
137159 args = { ' clone' , ' --filter=blob:none' , ' --depth=1' , ' --branch=' .. required_version , url , path },
138160 }):next (function (code )
@@ -177,12 +199,16 @@ function M.run(type)
177199 error (' [orgmode] Failed to move generated tree-sitter parser to runtime folder' , 0 )
178200 end
179201 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+ }
181206 if type == ' update' then
182207 table.insert (msg , ' Please restart Neovim to apply the changes.' )
183208 end
184- utils .notify (msg )
185- vim .treesitter .language .add (' org' )
209+ utils .notify (msg , {
210+ id = ' orgmode-treesitter-install' ,
211+ })
186212 return true
187213 end ))
188214 :wait (60000 )
0 commit comments