Skip to content

case sensitivity causes false 'File not in cwd' in Windows #97

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

Closed
Rodrigodd opened this issue Jan 26, 2022 · 2 comments · Fixed by #98
Closed

case sensitivity causes false 'File not in cwd' in Windows #97

Rodrigodd opened this issue Jan 26, 2022 · 2 comments · Fixed by #98
Labels
bug Something isn't working

Comments

@Rodrigodd
Copy link
Contributor

This is similar neovim/nvim-lspconfig#1168. See also neovim/neovim#16331.

Windows paths are not case sensitive in most cases, but this is not a problem normally. But lsp servers report paths with the drive letter normalized to lower case, but windows paths usually have upper case drive letters. This means that when cwd is, for example, C:\my_project\, sometimes I have a file c:\my_project\a_file.rs, which trigger the 'File not in cwd' prompt when running :NeoTreeReveal.

I temporally solve this problem by replacing the condition in this line with not M.is_subpath(cwd, path), from code below. I can open a PR if you wish. I don't know if you may know a better solution or want to wait for neovim/neovim#16331.

M.normalize_path = function (path)
    local has_windows_drive_letter = path:match '^%a:'
    if has_windows_drive_letter then
        return path:sub(1,1):lower()..path:sub(2)
    end
    return path
end

M.is_subpath = function(cwd, path)
    cwd = M.normalize_path(cwd)
    path = M.normalize_path(path)
    return string.sub(path, 1, string.len(cwd)) == cwd
end
@cseickel
Copy link
Contributor

If you could open a PR that would be great. I don't use nvim natively on windows myself so I can't properly test it.

One question though: would it be better to just lowercase the whole path if it is on Windows since the whole path is actually case insensitive? The neo-tree.utils module does have a is_windows property to determine if it is running on windows.

@cseickel cseickel added the bug Something isn't working label Jan 26, 2022
@Rodrigodd
Copy link
Contributor Author

Ok, so I will try to organize the code a little better, and open a PR.

would it be better to just lowercase the whole path if it is on Windows since the whole path is actually case insensitive?

There is a way to enable case sensitivity in windows, so I avoided lowercasing the entire path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants