Skip to content

Commit 82d2336

Browse files
authored
fix: error when opening standalone rust file without .rs extension (#789)
1 parent 2fdf224 commit 82d2336

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lua/rustaceanvim/cargo.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ end
6060
---@param callback? fun(root_dir: string | nil) If `nil`, this function runs synchronously
6161
---@return string | nil root_dir (if `callback ~= nil` and successful)
6262
local function default_get_root_dir(file_name, callback)
63-
local path = file_name:find('%.rs$') and vim.fs.dirname(file_name) or file_name
64-
if not path then
63+
local stat = vim.uv.fs_stat(file_name)
64+
if not stat then
65+
return nil
66+
end
67+
local path = stat.type == 'file' and vim.fs.dirname(file_name) or file_name
68+
if not path or not vim.uv.fs_stat(path) then
6569
return nil
6670
end
6771

0 commit comments

Comments
 (0)