diff --git a/runtime/lua/vim/_watch.lua b/runtime/lua/vim/_watch.lua index 8bfa61cf1e..3f7438dcac 100644 --- a/runtime/lua/vim/_watch.lua +++ b/runtime/lua/vim/_watch.lua @@ -69,10 +69,12 @@ function M.watch(path, opts, callback) local uvflags = opts and opts.uvflags or {} local handle = assert(uv.new_fs_event()) + local watching_dir = (uv.fs_stat(path) or {}).type == 'directory' + local _, start_err, start_errname = handle:start(path, uvflags, function(err, filename, events) assert(not err, err) local fullpath = path - if filename then + if filename and watching_dir then fullpath = vim.fs.normalize(vim.fs.joinpath(fullpath, filename)) end