@@ -10,25 +10,22 @@ local required_version = '2.0.0'
1010function M .install ()
1111 local version_info = M .get_version_info ()
1212 if not version_info .installed then
13- M .run (' install' )
14- return true
13+ return M .run (' install' )
1514 end
1615
1716 -- Parser found but in invalid location
1817 if not version_info .install_location then
19- M .run (' install' )
18+ local result = M .run (' install' )
2019 M .notify_conflicting_parsers (version_info .conflicting_parsers )
21- return true
20+ return result
2221 end
2322
2423 if version_info .outdated then
25- M .run (' update' )
26- return true
24+ return M .run (' update' )
2725 end
2826
2927 if version_info .version_mismatch then
30- M .reinstall ()
31- return true
28+ return M .reinstall ()
3229 end
3330
3431 M .notify_conflicting_parsers (version_info .conflicting_parsers )
@@ -93,7 +90,9 @@ function M.get_version_info()
9390end
9491
9592function M .get_parser_locations ()
96- local installed_org_parsers = vim .api .nvim_get_runtime_file (' parser/org.so' , true )
93+ local installed_org_parsers = vim .tbl_map (function (item )
94+ return vim .fn .fnamemodify (item , ' :p' )
95+ end , vim .api .nvim_get_runtime_file (' parser/org.so' , true ))
9796 local parser_path = M .get_parser_path ()
9897 local install_location = nil
9998 local conflicting_parsers = {}
@@ -229,6 +228,7 @@ function M.get_path(url, type)
229228end
230229
231230--- @param type ? ' install' | ' update' | ' reinstall' '
231+ --- @return OrgPromise<boolean>
232232function M .run (type )
233233 local url = ' https://github.com/nvim-orgmode/tree-sitter-org'
234234 local compiler = vim .tbl_filter (function (exe )
@@ -241,6 +241,7 @@ function M.run(type)
241241
242242 local compiler_args = M .select_compiler_args (compiler )
243243 local path = nil
244+ local lock_file = M .get_lock_file ()
244245
245246 return M .get_path (url , type )
246247 :next (function (directory )
@@ -250,17 +251,18 @@ function M.run(type)
250251 cwd = directory ,
251252 })
252253 end )
253- :next (vim . schedule_wrap ( function (code )
254+ :next (function (code )
254255 if code ~= 0 then
255256 error (' [orgmode] Failed to compile parser' , 0 )
256257 end
257258 local source = vim .fs .joinpath (path , ' parser.so' )
258- local destination = M .get_parser_path ()
259- local renamed = vim .fn .rename (source , destination )
260- if renamed ~= 0 then
261- error (' [orgmode] Failed to move generated tree-sitter parser to runtime folder' , 0 )
259+ local copied , err = vim .uv .fs_copyfile (source , M .get_parser_path ())
260+ if not copied then
261+ error (' [orgmode] Failed to copy generated tree-sitter parser to runtime folder: ' .. err , 0 )
262262 end
263- utils .writefile (M .get_lock_file (), vim .json .encode ({ version = required_version })):wait ()
263+ return utils .writefile (lock_file , vim .json .encode ({ version = required_version }))
264+ end )
265+ :next (vim .schedule_wrap (function ()
264266 local msg = { ' Tree-sitter grammar installed!' }
265267
266268 if type == ' update' then
0 commit comments