@@ -114,14 +114,22 @@ function M.not_installed()
114
114
return not ok or (not result and err ~= nil )
115
115
end
116
116
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
+
117
124
function M .get_installed_version ()
118
125
local lock_file = M .get_lock_file ()
119
- -- No lock file, assume that version is 1.3.4 (when lock file was introduced)
120
126
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' })
122
128
return ' 1.3.4'
123
129
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 ()
125
133
return file_content .version
126
134
end
127
135
@@ -275,7 +283,6 @@ function M.run(type)
275
283
276
284
local compiler_args = M .select_compiler_args (compiler )
277
285
local ts_grammar_dir = nil
278
- local lock_file = M .get_lock_file ()
279
286
local is_win = vim .fn .has (' win32' ) == 1
280
287
local shellslash = is_win and vim .opt .shellslash :get () or false
281
288
@@ -298,7 +305,7 @@ function M.run(type)
298
305
if code ~= 0 then
299
306
error (' [orgmode] Failed to move generated tree-sitter parser to runtime folder' , 0 )
300
307
end
301
- return utils . writefile ( lock_file , vim . json . encode ( { version = required_version }) )
308
+ return M . _write_lock_file ( { version = required_version })
302
309
end )
303
310
:next (vim .schedule_wrap (function ()
304
311
local msg = { ' Tree-sitter grammar installed!' }
0 commit comments