Skip to content
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

fix(modules): fix path dissection for windows #76

Merged
merged 1 commit into from
Mar 28, 2023

Conversation

kingavatar
Copy link
Contributor

@kingavatar kingavatar commented Mar 25, 2023

Hi guys, I have added a fix where for windows path the breakdown of paths to find similar path was not happening due to windows using "\" instead of "/" like unix path.

So before behavior
bug

After fix
fix

Ihave also encountered cases where the nvim api also sometimes gives path seperator of both types like "dev\neovim\nvchad-ui/lua/nvchad-ui" so I have converted all windows type path to unix path to handle those cases as well.

I have also changed the path display to display single "/" in tab instead of "/../" if the directory is parent itself. I hope this is okay as I thought it may be confusing.

Comment on lines 72 to 79
---@type string
local other_filename = api.nvim_buf_get_name(value)
---@type string
local current_filename = api.nvim_buf_get_name(bufnr)
if isWindows then
other_filename = other_filename:gsub("\\", "/")
current_filename = current_filename:gsub("\\", "/")
end
Copy link
Collaborator

@lucario387 lucario387 Mar 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do vim.fs.normalize(filename) instead of the gsub. It will change all \\ to / for you

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, will try this out and send a new commit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vim.fn.normalize is perfect. I have removed check for windows as it is not necessary as it deals with both windows and linux cases and also it handled edge cases like "dev\neovim\nvchad-ui/lua/nvchad-ui" well.

@siduck
Copy link
Member

siduck commented Mar 27, 2023

@kingavatar I dont think you need the types here
image

Hi guys, I have added a fix where for windows path the breakdown of paths to find similar path was not happening due to windows using "\\" instead of "/" like unix and I have also changed the path display to display single "/" in tab instead of "/../" if the directory is parent itself.
@kingavatar
Copy link
Contributor Author

kingavatar commented Mar 27, 2023

@kingavatar I dont think you need the types here image

@siduck Yes true, I was getting diagnostic error there before but after updating now I am not getting any errors. I have removed the redundant types defined and pushed again.

@@ -85,7 +85,13 @@ local function add_fileInfo(name, bufnr)
local other_current = other[i]

if value_current ~= other_current then
name = value_current .. "/../" .. name
if (#current - i) < 2 then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name = value_current .. ((#current - 1) < 2 and "/") or "/../") .. name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants