Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
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

@huguesv

Description

@huguesv

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)));

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions