public void CanDetermineIsPathInMemory()
        {
            string tempDir       = Path.GetTempPath();
            string shortDirPath  = Path.Combine(tempDir, "GitHub", "PowerShellEditorServices");
            string shortFilePath = Path.Combine(shortDirPath, "foo.ps1");
            string shortUriForm  = "git:/c%3A/Users/Keith/GitHub/dahlbyk/posh-git/src/PoshGitTypes.ps1?%7B%22path%22%3A%22c%3A%5C%5CUsers%5C%5CKeith%5C%5CGitHub%5C%5Cdahlbyk%5C%5Cposh-git%5C%5Csrc%5C%5CPoshGitTypes.ps1%22%2C%22ref%22%3A%22~%22%7D";
            string longUriForm   = "gitlens-git:c%3A%5CUsers%5CKeith%5CGitHub%5Cdahlbyk%5Cposh-git%5Csrc%5CPoshGitTypes%3Ae0022701.ps1?%7B%22fileName%22%3A%22src%2FPoshGitTypes.ps1%22%2C%22repoPath%22%3A%22c%3A%2FUsers%2FKeith%2FGitHub%2Fdahlbyk%2Fposh-git%22%2C%22sha%22%3A%22e0022701fa12e0bc22d0458673d6443c942b974a%22%7D";

            var testCases = new[] {
                // Test short file absolute paths
                new { IsInMemory = false, Path = shortDirPath },
                new { IsInMemory = false, Path = shortFilePath },
                new { IsInMemory = false, Path = new Uri(shortDirPath).ToString() },
                new { IsInMemory = false, Path = new Uri(shortFilePath).ToString() },

                // Test short file relative paths - not sure we'll ever get these but just in case
                new { IsInMemory = false, Path = "foo.ps1" },
                new { IsInMemory = false, Path = Path.Combine(new [] { "..", "foo.ps1" }) },

                // Test short non-file paths
                new { IsInMemory = true, Path = "untitled:untitled-1" },
                new { IsInMemory = true, Path = shortUriForm },
                new { IsInMemory = true, Path = "inmemory://foo.ps1" },

                // Test long non-file path - known to have crashed PSES
                new { IsInMemory = true, Path = longUriForm },
            };

            foreach (var testCase in testCases)
            {
                Assert.True(
                    WorkspaceService.IsPathInMemory(testCase.Path) == testCase.IsInMemory,
                    $"Testing path {testCase.Path}");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new ScriptFile instance by reading file contents from
        /// the given TextReader.
        /// </summary>
        /// <param name="filePath">The path at which the script file resides.</param>
        /// <param name="clientFilePath">The path which the client uses to identify the file.</param>
        /// <param name="textReader">The TextReader to use for reading the file's contents.</param>
        /// <param name="powerShellVersion">The version of PowerShell for which the script is being parsed.</param>
        public ScriptFile(
            string filePath,
            string clientFilePath,
            TextReader textReader,
            Version powerShellVersion)
        {
            this.FilePath          = filePath;
            this.ClientFilePath    = clientFilePath;
            this.IsAnalysisEnabled = true;
            this.IsInMemory        = WorkspaceService.IsPathInMemory(filePath);
            this.powerShellVersion = powerShellVersion;

            // SetFileContents() calls ParseFileContents() which initializes the rest of the properties.
            this.SetFileContents(textReader.ReadToEnd());
        }