Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

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
Closed

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

huguesv opened this issue Sep 4, 2019 · 2 comments · Fixed by #1519
Assignees
Labels
bug Something isn't working

Comments

@huguesv
Copy link
Contributor

huguesv 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 Something isn't working 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
Copy link
Member

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 has been minimized.

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

Successfully merging a pull request may close this issue.

3 participants