-
Notifications
You must be signed in to change notification settings - Fork 225
Fix: Windows path conversion fails for forward-slash paths #686
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
Open
crwebb85
wants to merge
6
commits into
stevearc:master
Choose a base branch
from
crwebb85:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2501246
Add support for UNC paths on Windows
jeremyhaugen b483d65
Added tests for Windows UNC path support.
jeremyhaugen b13616c
Renamed SMB to UNC in test names
jeremyhaugen 3341d24
Fixed line endings on fs_spec.lua
jeremyhaugen 6963df1
feat(test): Added Windows support for running tests
crwebb85 30478b4
fix: Windows path conversion fails for forward-slash paths
crwebb85 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ __pycache__ | |
|
|
||
| .direnv/ | ||
| .testenv/ | ||
| oil_test_*/ | ||
| venv/ | ||
| doc/tags | ||
| scripts/nvim_doc_tools | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/usr/bin/env pwsh | ||
| $ErrorActionPreference = "Stop" | ||
|
|
||
| # Create required directories | ||
| $dirs = @( | ||
| ".testenv/config/nvim", | ||
| ".testenv/data/nvim", | ||
| ".testenv/state/nvim", | ||
| ".testenv/run/nvim", | ||
| ".testenv/cache/nvim" | ||
| ) | ||
| foreach ($dir in $dirs) { | ||
| New-Item -ItemType Directory -Force -Path $dir | Out-Null | ||
| } | ||
|
|
||
| # Plugin directory | ||
| $PLUGINS = ".testenv/data/nvim-data/site/pack/plugins/start" | ||
|
|
||
| # Ensure plenary.nvim is present | ||
| $plenaryPath = Join-Path $PLUGINS "plenary.nvim" | ||
| if (-Not (Test-Path $plenaryPath)) { | ||
| git clone --depth=1 https://github.com/nvim-lua/plenary.nvim.git $plenaryPath | ||
| } else { | ||
| Push-Location $plenaryPath | ||
| git pull | ||
| Pop-Location | ||
| } | ||
|
|
||
| # Set environment variables | ||
| $env:XDG_CONFIG_HOME = ".testenv/config" | ||
| $env:XDG_DATA_HOME = ".testenv/data" | ||
| $env:XDG_STATE_HOME = ".testenv/state" | ||
| $env:XDG_RUNTIME_DIR = ".testenv/run" | ||
| $env:XDG_CACHE_HOME = ".testenv/cache" | ||
|
|
||
| # Run Neovim tests | ||
| $nvimArgs = @( | ||
| "--headless", | ||
| "-u", "./tests/minimal_init.lua", | ||
| "-c", "PlenaryBustedDirectory $($args[0] ?? 'tests') { minimal_init = './tests/minimal_init.lua' }" | ||
| ) | ||
|
|
||
| nvim @nvimArgs | ||
|
|
||
| Write-Host "Success" | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| require("plenary.async").tests.add_to_env() | ||
| local fs = require("oil.fs") | ||
|
|
||
| local function set_env_windows() | ||
| fs.is_windows = true | ||
| fs.is_mac = false | ||
| fs.is_linux = false | ||
| fs.sep = "\\" | ||
| end | ||
|
|
||
| local function set_env_linux() | ||
| fs.is_windows = false | ||
| fs.is_mac = false | ||
| fs.is_linux = true | ||
| fs.sep = "/" | ||
| end | ||
|
|
||
| a.describe("File system", function() | ||
| after_each(function() | ||
| fs._initialize_environment() | ||
| end) | ||
|
|
||
| a.it("converts linux path to posix", function() | ||
| set_env_linux() | ||
| assert.equals("/a/b/c", fs.os_to_posix_path("/a/b/c")) | ||
| end) | ||
|
|
||
| a.it("converts Windows local path to posix", function() | ||
| set_env_windows() | ||
| assert.equals("/C/a/b/c", fs.os_to_posix_path("C:\\a\\b\\c")) | ||
| end) | ||
|
|
||
| a.it("converts Windows local path with extra backslash path seperators to posix", function() | ||
| set_env_windows() | ||
| assert.equals("/C/a/b/c", fs.os_to_posix_path("C:\\\\a\\b\\c")) | ||
| end) | ||
|
|
||
| a.it("converts Windows local path with forward slashes to posix", function() | ||
| set_env_windows() | ||
| assert.equals("/C/a/b/c", fs.os_to_posix_path("C:/a/b/c")) | ||
| end) | ||
|
|
||
| a.it("converts Windows UNC path to posix", function() | ||
| set_env_windows() | ||
| assert.equals("//a/b/c", fs.os_to_posix_path("\\\\a\\b\\c")) | ||
| end) | ||
|
|
||
| a.it("converts posix to linux path", function() | ||
| set_env_linux() | ||
| assert.equals("/a/b/c", fs.posix_to_os_path("/a/b/c")) | ||
| end) | ||
|
|
||
| a.it("converts posix to Windows local path", function() | ||
| set_env_windows() | ||
| assert.equals("C:\\a\\b\\c", fs.posix_to_os_path("/C/a/b/c")) | ||
| end) | ||
|
|
||
| a.it("converts posix to Windows UNC path", function() | ||
| set_env_windows() | ||
| assert.equals("\\\\a\\b\\c", fs.posix_to_os_path("//a/b/c")) | ||
| end) | ||
| end) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,35 @@ | ||
| local oil = require("oil") | ||
| local util = require("oil.util") | ||
|
|
||
| local uv = vim.uv or vim.loop | ||
|
|
||
| describe("url", function() | ||
| it("get_url_for_path", function() | ||
| local cases = { | ||
| { "", "oil://" .. util.addslash(vim.fn.getcwd()) }, | ||
| { "term://~/oil.nvim//52953:/bin/sh", "oil://" .. vim.loop.os_homedir() .. "/oil.nvim/" }, | ||
| { "/foo/bar.txt", "oil:///foo/", "bar.txt" }, | ||
| { "", "oil://" .. util.addslash(vim.fn.getcwd()), skip_on_windows = true }, | ||
| { | ||
| "term://~/oil.nvim//52953:/bin/sh", | ||
| "oil://" .. vim.loop.os_homedir() .. "/oil.nvim/", | ||
| skip_on_windows = true, | ||
| }, | ||
| { "/foo/bar.txt", "oil:///foo/", "bar.txt", skip_on_windows = true }, | ||
| { "oil:///foo/bar.txt", "oil:///foo/", "bar.txt" }, | ||
| { "oil:///", "oil:///" }, | ||
| { "oil-ssh://user@hostname:8888//bar.txt", "oil-ssh://user@hostname:8888//", "bar.txt" }, | ||
| { "oil-ssh://user@hostname:8888//", "oil-ssh://user@hostname:8888//" }, | ||
| } | ||
| for _, case in ipairs(cases) do | ||
| local input, expected, expected_basename = unpack(case) | ||
| local output, basename = oil.get_buffer_parent_url(input, true) | ||
| assert.equals(expected, output, string.format('Parent url for path "%s" failed', input)) | ||
| assert.equals( | ||
| expected_basename, | ||
| basename, | ||
| string.format('Basename for path "%s" failed', input) | ||
| ) | ||
| local is_skip = case.skip_on_windows and uv.os_uname().version:match("Windows") | ||
| if not is_skip then | ||
| local input, expected, expected_basename = unpack(case) | ||
| local output, basename = oil.get_buffer_parent_url(input, true) | ||
| assert.equals(expected, output, string.format('Parent url for path "%s" failed', input)) | ||
| assert.equals( | ||
| expected_basename, | ||
| basename, | ||
| string.format('Basename for path "%s" failed', input) | ||
| ) | ||
| end | ||
| end | ||
| end) | ||
| end) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make use of
vim.fs.normalizefor any of this functionality? It seems to do some similar things (preserving leading double slashes) and I'd like to rely on the Neovim libs whenever possible.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In nightly it looks like it would work. I still need to try it out in the oil code but from some quick testing I think it would work, However, I don't think it would work if you want to continue supporting Neovim 0.8+. There were a lot of improvements to vim.fs.normalize in 2024 and one improvement in 2025 that we may need for it to function correctly.
https://github.com/neovim/neovim/blob/b1ae775de618e3e87954a88d533ec17bbef41cdf/runtime/lua/vim/fs.lua#L209-L231
https://github.com/neovim/neovim/blob/0ef27180e31671a043b28547da327cd52f1a87c4/runtime/lua/vim/fs.lua#L306-L352
https://github.com/neovim/neovim/blob/0c995c0efba092f149fc314a43327db7d105e1ad/runtime/lua/vim/fs.lua#L504-L612
https://github.com/neovim/neovim/blob/c1c007813884075a970198fbba918d568428d739/runtime/lua/vim/fs.lua#L587-L688
https://github.com/neovim/neovim/blob/5370b7a2e0a0484c9005cb5a727dffa5ef13b1ed/runtime/lua/vim/fs.lua#L596-L697
I could also do the normal
if has version use vim.fs.normalize else use a copy of nightly's versionif that sounds better.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neovim 0.9 came out almost 3 years ago, so I'm fine to drop support for 0.8 now. I only kept it this long because there was no strong motivation to remove it, but now there is!