@@ -114,14 +114,22 @@ function M.not_installed()
114114 return not ok or (not result and err ~= nil )
115115end
116116
117+ function M ._write_lock_file (content )
118+ local lock_file = M .get_lock_file ()
119+ local file = assert (io.open (lock_file , ' w' ))
120+ file :write (vim .json .encode (content ))
121+ file :close ()
122+ end
123+
117124function M .get_installed_version ()
118125 local lock_file = M .get_lock_file ()
119- -- No lock file, assume that version is 1.3.4 (when lock file was introduced)
120126 if not vim .uv .fs_stat (lock_file ) then
121- utils . writefile ( lock_file , vim . json . encode ( { version = ' 1.3.4' })): wait ( )
127+ M . _write_lock_file ( { version = ' 1.3.4' })
122128 return ' 1.3.4'
123129 end
124- local file_content = vim .json .decode (utils .readfile (lock_file , { raw = true }):wait ())
130+ local lock_file_handle = assert (io.open (lock_file , ' r' ))
131+ local file_content = vim .json .decode (lock_file_handle :read (' *a' ))
132+ lock_file_handle :close ()
125133 return file_content .version
126134end
127135
@@ -275,7 +283,6 @@ function M.run(type)
275283
276284 local compiler_args = M .select_compiler_args (compiler )
277285 local ts_grammar_dir = nil
278- local lock_file = M .get_lock_file ()
279286 local is_win = vim .fn .has (' win32' ) == 1
280287 local shellslash = is_win and vim .opt .shellslash :get () or false
281288
@@ -298,7 +305,7 @@ function M.run(type)
298305 if code ~= 0 then
299306 error (' [orgmode] Failed to move generated tree-sitter parser to runtime folder' , 0 )
300307 end
301- return utils . writefile ( lock_file , vim . json . encode ( { version = required_version }) )
308+ return M . _write_lock_file ( { version = required_version })
302309 end )
303310 :next (vim .schedule_wrap (function ()
304311 local msg = { ' Tree-sitter grammar installed!' }
0 commit comments