Skip to content

Commit dd7d4eb

Browse files
authored
Fix crash when untitled files are opened as PowerShell (#815)
1 parent 3e0ee90 commit dd7d4eb

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/PowerShellEditorServices/Workspace/ScriptFile.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,16 @@ private void ParseFileContents()
648648
.Select(ScriptFileMarker.FromParseError)
649649
.ToArray();
650650

651-
//Get all dot sourced referenced files and store them
651+
// Untitled files have no directory
652+
// Discussed in https://github.com/PowerShell/PowerShellEditorServices/pull/815.
653+
// Rather than working hard to enable things for untitled files like a phantom directory,
654+
// users should save the file.
655+
if (IsUntitledPath(this.FilePath))
656+
{
657+
return;
658+
}
659+
660+
// Get all dot sourced referenced files and store them
652661
this.ReferencedFiles = AstOperations.FindDotSourcedIncludes(this.ScriptAst, Path.GetDirectoryName(this.FilePath));
653662
}
654663

0 commit comments

Comments
 (0)