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

IndexManager.WorkspaceFiles returns paths rooted by cwd instead of workspace root #1512

Closed
huguesv opened this issue Sep 4, 2019 · 2 comments · Fixed by #1519

Comments

@huguesv
Copy link
Contributor

commented Sep 4, 2019

Causes errors like this, notice the file path:

System.IO.FileNotFoundException
  HResult=0x80070002
  Message=Could not find file 'C:\Projects\GitHub\Microsoft\python-language-server\output\bin\Debug\PythonApplication7.py'.
  Source=System.Private.CoreLib
  StackTrace:
   at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
   at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at System.IO.File.Open(String path, FileMode mode, FileAccess access, FileShare share)
   at Microsoft.Python.Core.IO.FileSystem.FileOpen(String path, FileMode mode, FileAccess access, FileShare share) in C:\Projects\GitHub\Microsoft\python-language-server\src\Core\Impl\IO\FileSystem.cs:line 35

See how my _workspaceRootPath is properly set, and also the cwd which I've added FYI.

image

And now the result, which is incorrectly rooted:

image

Problem seems to be in DirectoryInfoProxy class:

        public IEnumerable<IFileSystemInfo> EnumerateFileSystemInfos(string[] includePatterns, string[] excludePatterns) {
            var matcher = GetMatcher(includePatterns, excludePatterns);
            PatternMatchingResult matchResult = SafeExecuteMatcher(matcher);
            return matchResult.Files.Select((filePatternMatch) => {
                var path = PathUtils.NormalizePath(filePatternMatch.Path);
                return CreateFileSystemInfoProxy(new FileInfo(path));
            });
        }

The FileInfo is created with just the file name.

If I change that line to this, it works fine:

return CreateFileSystemInfoProxy(new FileInfo(Path.Combine(_directoryInfo.FullName, path)));

@jakebailey jakebailey added the bug label Sep 4, 2019

@jakebailey jakebailey self-assigned this Sep 4, 2019

@jakebailey jakebailey added this to the September 2019.1 milestone Sep 4, 2019

@jakebailey

This comment has been minimized.

Copy link
Member

commented Sep 4, 2019

My wild guess is that VS Code starts the LS with the working directory set to the workspace, so we wouldn't have hit this until now.

@CTrando

This comment was marked as outdated.

Copy link
Contributor

commented Sep 4, 2019

It might be slightly hard to test because we mock enumerating the file results, but we’re open to PRs if you want to contribute!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.