Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced WorkspaceFileSystemWrapper with Get-Content and Get-ChildItem #2136

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/PowerShellEditorServices.Hosting/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@
"version": 1,
"dependencies": {
".NETFramework,Version=v4.6.2": {
"Microsoft.NETFramework.ReferenceAssemblies": {
"type": "Direct",
"requested": "[1.0.3, )",
"resolved": "1.0.3",
"contentHash": "vUc9Npcs14QsyOD01tnv/m8sQUnGTGOw1BCmKcv77LBJY7OxhJ+zJF7UD/sCL3lYNFuqmQEVlkfS4Quif6FyYg==",
"dependencies": {
"Microsoft.NETFramework.ReferenceAssemblies.net462": "1.0.3"
}
},
"NETStandard.Library": {
"type": "Direct",
"requested": "[2.0.3, )",
Expand Down Expand Up @@ -175,11 +166,6 @@
"resolved": "1.1.0",
"contentHash": "kz0PEW2lhqygehI/d6XsPCQzD7ff7gUJaVGPVETX611eadGsA3A877GdSlU0LRVMCTH/+P3o2iDTak+S08V2+A=="
},
"Microsoft.NETFramework.ReferenceAssemblies.net462": {
"type": "Transitive",
"resolved": "1.0.3",
"contentHash": "IzAV30z22ESCeQfxP29oVf4qEo8fBGXLXSU6oacv/9Iqe6PzgHDKCaWfwMBak7bSJQM0F5boXWoZS+kChztRIQ=="
},
"Microsoft.VisualStudio.Threading": {
"type": "Transitive",
"resolved": "17.6.40",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,58 +78,66 @@ static AstOperations()
IScriptPosition cursorPosition = s_clonePositionWithNewOffset(scriptAst.Extent.StartScriptPosition, fileOffset);
Stopwatch stopwatch = new();
logger.LogTrace($"Getting completions at offset {fileOffset} (line: {cursorPosition.LineNumber}, column: {cursorPosition.ColumnNumber})");

CommandCompletion commandCompletion = await executionService.ExecuteDelegateAsync(
representation: "CompleteInput",
new ExecutionOptions { Priority = ExecutionPriority.Next },
(pwsh, _) =>
{
stopwatch.Start();

// If the current runspace is not out of process, then we call TabExpansion2 so
// that we have the ability to issue pipeline stop requests on cancellation.
if (executionService is PsesInternalHost psesInternalHost
&& !psesInternalHost.Runspace.RunspaceIsRemote)
{
IReadOnlyList<CommandCompletion> completionResults = new SynchronousPowerShellTask<CommandCompletion>(
logger,
psesInternalHost,
new PSCommand()
.AddCommand("TabExpansion2")
.AddParameter("ast", scriptAst)
.AddParameter("tokens", currentTokens)
.AddParameter("positionOfCursor", cursorPosition),
executionOptions: null,
cancellationToken)
.ExecuteAndGetResult(cancellationToken);

if (completionResults is { Count: > 0 })
CommandCompletion commandCompletion = null;
try
{
commandCompletion = await executionService.ExecuteDelegateAsync(
representation: "CompleteInput",
new ExecutionOptions { Priority = ExecutionPriority.Next },
(pwsh, _) =>
{
return completionResults[0];
}

return null;
}

// If the current runspace is out of process, we can't call TabExpansion2
// because the output will be serialized.
return CommandCompletion.CompleteInput(
scriptAst,
currentTokens,
cursorPosition,
options: null,
powershell: pwsh);
},
cancellationToken).ConfigureAwait(false);

stopwatch.Stop();

if (commandCompletion is null)
stopwatch.Start();

// If the current runspace is not out of process, then we call TabExpansion2 so
// that we have the ability to issue pipeline stop requests on cancellation.
if (executionService is PsesInternalHost psesInternalHost
&& !psesInternalHost.Runspace.RunspaceIsRemote)
{
IReadOnlyList<CommandCompletion> completionResults = new SynchronousPowerShellTask<CommandCompletion>(
logger,
psesInternalHost,
new PSCommand()
.AddCommand("TabExpansion2")
.AddParameter("ast", scriptAst)
.AddParameter("tokens", currentTokens)
.AddParameter("positionOfCursor", cursorPosition),
executionOptions: new PowerShellExecutionOptions()
{
ThrowOnError = true
},
cancellationToken)
.ExecuteAndGetResult(cancellationToken);

if (completionResults is { Count: > 0 })
{
return completionResults[0];
}
}
return null;

// If the current runspace is out of process, we can't call TabExpansion2
// because the output will be serialized.
return CommandCompletion.CompleteInput(
scriptAst,
currentTokens,
cursorPosition,
options: null,
powershell: pwsh);
},
cancellationToken).ConfigureAwait(false);

}
catch (WildcardPatternException)
{
// This hits when you press Ctrl+Space inside empty square brackets []
}
catch (RuntimeException ex)
{
logger.LogError("Error Occurred in TabExpansion2");
logger.LogError($"Error Occurred in TabExpansion2: {ex.ErrorRecord}", ex.ErrorRecord.Exception);
}
else
finally
{
stopwatch.Stop();
logger.LogTrace(
"IntelliSense completed in {elapsed}ms - WordToComplete: \"{word}\" MatchCount: {count}",
stopwatch.ElapsedMilliseconds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public override async Task<CompletionItem> Handle(CompletionItem request, Cancel
_logger,
cancellationToken).ConfigureAwait(false);

if (result.CompletionMatches.Count == 0)
if (result is not { CompletionMatches.Count: > 0 })
{
return new CompletionResults(IsIncomplete: true, Array.Empty<CompletionItem>());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public Task<Unit> Handle(DidChangeWatchedFilesParams request, CancellationToken
string fileContents;
try
{
fileContents = WorkspaceService.ReadFileContents(change.Uri);
fileContents = _workspaceService.ReadFileContents(change.Uri);
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,32 @@ 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);
if (!IsSupportedScheme(documentUri.Scheme))
{
return false;
}
return documentUri.Scheme switch
{
// List supported schemes here
"inmemory" or "untitled" or "vscode-notebook-cell" => true,
_ => false,
};
}

internal static bool IsSupportedScheme(string? scheme)
{
return scheme switch
{
// List supported schemes here
"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