Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
{
new OmniSharpFileSystemWatcher()
{
GlobPattern = "**/*.{ps1,psm1}",

Check warning on line 50 in src/PowerShellEditorServices/Services/TextDocument/Handlers/DidChangeWatchedFilesHandler.cs

View workflow job for this annotation

GitHub Actions / pack-and-publish

Possible null reference assignment.
Kind = WatchKind.Create | WatchKind.Delete | WatchKind.Change,
},
},
Expand All @@ -66,7 +66,11 @@
matcher.AddExcludePatterns(_workspaceService.ExcludeFilesGlob);
foreach (FileEvent change in request.Changes)
{
if (matcher.Match(change.Uri.GetFileSystemPath()).HasMatches)
string changePath = change.Uri.ToUri().IsFile
? change.Uri.GetFileSystemPath()
: change.Uri.ToUri().AbsolutePath;

if (matcher.Match(changePath).HasMatches)
{
continue;
}
Expand Down Expand Up @@ -100,7 +104,7 @@
string fileContents;
try
{
fileContents = WorkspaceService.ReadFileContents(change.Uri);
fileContents = _workspaceService.ReadFileContents(change.Uri);
}
catch
{
Expand Down
27 changes: 23 additions & 4 deletions src/PowerShellEditorServices/Services/TextDocument/ScriptFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,31 @@ internal static List<string> GetLines(string text)
/// <returns>True if the path is an untitled file, false otherwise.</returns>
internal static bool IsUntitledPath(string path)
{
Validate.IsNotNull(nameof(path), path);
// This may not have been given a URI, so return false instead of throwing.
return Uri.IsWellFormedUriString(path, UriKind.RelativeOrAbsolute) &&
!string.Equals(DocumentUri.From(path).Scheme, Uri.UriSchemeFile, StringComparison.OrdinalIgnoreCase);
if (!Uri.IsWellFormedUriString(path, UriKind.RelativeOrAbsolute))
{
return false;
}

DocumentUri documentUri = DocumentUri.From(path);
string scheme = documentUri.Scheme?.ToLowerInvariant();
if (!IsSupportedScheme(scheme))
{
return false;
}

return scheme switch
{
"inmemory" or "untitled" or "vscode-notebook-cell" => true,
_ => false,
};
}

internal static bool IsSupportedScheme(string scheme) => scheme?.ToLowerInvariant() switch
{
"file" or "inmemory" or "untitled" or "vscode-notebook-cell" or "pspath" => true,
_ => false,
};

/// <summary>
/// Gets a line from the file's contents.
/// </summary>
Expand Down
Loading
Loading