From 550d0e32f3fe8ff5b0b2807be72f25a4e8170b90 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 12 Dec 2018 02:35:53 -0800 Subject: [PATCH 1/2] Fix crash when untitled files are opened as PowerShell --- src/PowerShellEditorServices/Workspace/ScriptFile.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/PowerShellEditorServices/Workspace/ScriptFile.cs b/src/PowerShellEditorServices/Workspace/ScriptFile.cs index a81200887..9716a272d 100644 --- a/src/PowerShellEditorServices/Workspace/ScriptFile.cs +++ b/src/PowerShellEditorServices/Workspace/ScriptFile.cs @@ -648,7 +648,14 @@ private void ParseFileContents() .Select(ScriptFileMarker.FromParseError) .ToArray(); - //Get all dot sourced referenced files and store them + // Untitled files have no directory + // TODO: Make untitled files support dot-sourced references + if (IsUntitledPath(this.FilePath)) + { + return; + } + + // Get all dot sourced referenced files and store them this.ReferencedFiles = AstOperations.FindDotSourcedIncludes(this.ScriptAst, Path.GetDirectoryName(this.FilePath)); } From 72eed8de9f51c086b9bf37dc643badd7847951f6 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 17 Dec 2018 11:47:53 -0800 Subject: [PATCH 2/2] Change TODO to discussion note --- src/PowerShellEditorServices/Workspace/ScriptFile.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PowerShellEditorServices/Workspace/ScriptFile.cs b/src/PowerShellEditorServices/Workspace/ScriptFile.cs index 9716a272d..dab2918cc 100644 --- a/src/PowerShellEditorServices/Workspace/ScriptFile.cs +++ b/src/PowerShellEditorServices/Workspace/ScriptFile.cs @@ -649,7 +649,9 @@ private void ParseFileContents() .ToArray(); // Untitled files have no directory - // TODO: Make untitled files support dot-sourced references + // Discussed in https://github.com/PowerShell/PowerShellEditorServices/pull/815. + // Rather than working hard to enable things for untitled files like a phantom directory, + // users should save the file. if (IsUntitledPath(this.FilePath)) { return;