Skip to content

Fixed drive switching on windows #341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions lua/oil/adapters/files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -213,19 +213,36 @@ end
M.normalize_url = function(url, callback)
local scheme, path = util.parse_url(url)
assert(path)
if fs.is_windows and path == "/" then
return callback(url)

if fs.is_windows then
if path == "/" then
return callback(url)
else
local is_root_drive = path:match("^/%u$")
if is_root_drive then
return callback(url .. "/")
end
end
end

local os_path = vim.fn.fnamemodify(fs.posix_to_os_path(path), ":p")
uv.fs_realpath(os_path, function(err, new_os_path)
local realpath = new_os_path or os_path
local realpath
if fs.is_windows then
-- Ignore the fs_realpath on windows because it will resolve mapped network drives to the IP
-- address instead of using the drive letter
realpath = os_path
else
realpath = new_os_path or os_path
end

uv.fs_stat(
realpath,
vim.schedule_wrap(function(stat_err, stat)
local is_directory
if stat then
is_directory = stat.type == "directory"
elseif vim.endswith(realpath, "/") then
elseif vim.endswith(realpath, "/") or (fs.is_windows and vim.endswith(realpath, "\\")) then
is_directory = true
else
local filetype = vim.filetype.match({ filename = vim.fs.basename(realpath) })
Expand Down
7 changes: 4 additions & 3 deletions lua/oil/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ end
---@return boolean
local function maybe_hijack_directory_buffer(bufnr)
local config = require("oil.config")
local fs = require("oil.fs")
local util = require("oil.util")
if not config.default_file_explorer then
return false
Expand All @@ -684,10 +685,10 @@ local function maybe_hijack_directory_buffer(bufnr)
if util.parse_url(bufname) or vim.fn.isdirectory(bufname) == 0 then
return false
end
local replaced = util.rename_buffer(
bufnr,
util.addslash(config.adapter_to_scheme.files .. vim.fn.fnamemodify(bufname, ":p"))
local new_name = util.addslash(
config.adapter_to_scheme.files .. fs.os_to_posix_path(vim.fn.fnamemodify(bufname, ":p"))
)
local replaced = util.rename_buffer(bufnr, new_name)
return not replaced
end

Expand Down
Loading