From e72a21968a5eb724b9c86b9f61b85afeec45a2f6 Mon Sep 17 00:00:00 2001 From: Darren Kattan Date: Thu, 15 Feb 2024 11:41:37 -0600 Subject: [PATCH] Replaced WorkspaceFileSystemWrapper with Get-Content and Get-ChildItem --- .../Handlers/DidChangeWatchedFilesHandler.cs | 2 +- .../Workspace/WorkspaceFileSystemWrapper.cs | 363 ------------------ .../Services/Workspace/WorkspaceService.cs | 137 ++++--- .../Debugging/DebugServiceTests.cs | 2 +- .../Language/CompletionHandlerTests.cs | 10 +- .../Language/SymbolsServiceTests.cs | 2 +- .../Services/Symbols/AstOperationsTests.cs | 3 +- .../Services/Symbols/PSScriptAnalyzerTests.cs | 2 +- .../Session/WorkspaceTests.cs | 5 +- .../packages.lock.json | 22 +- 10 files changed, 105 insertions(+), 443 deletions(-) delete mode 100644 src/PowerShellEditorServices/Services/Workspace/WorkspaceFileSystemWrapper.cs diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DidChangeWatchedFilesHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DidChangeWatchedFilesHandler.cs index edbe9b0ad..8c19796d9 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DidChangeWatchedFilesHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DidChangeWatchedFilesHandler.cs @@ -100,7 +100,7 @@ public Task Handle(DidChangeWatchedFilesParams request, CancellationToken string fileContents; try { - fileContents = WorkspaceService.ReadFileContents(change.Uri); + fileContents = _workspaceService.ReadFileContents(change.Uri); } catch { diff --git a/src/PowerShellEditorServices/Services/Workspace/WorkspaceFileSystemWrapper.cs b/src/PowerShellEditorServices/Services/Workspace/WorkspaceFileSystemWrapper.cs deleted file mode 100644 index a8861cee2..000000000 --- a/src/PowerShellEditorServices/Services/Workspace/WorkspaceFileSystemWrapper.cs +++ /dev/null @@ -1,363 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Security; -using Microsoft.Extensions.FileSystemGlobbing.Abstractions; -using Microsoft.Extensions.Logging; -using Microsoft.PowerShell.EditorServices.Logging; - -namespace Microsoft.PowerShell.EditorServices.Services.Workspace -{ - /// - /// A FileSystem wrapper class which only returns files and directories that the consumer is interested in, - /// with a maximum recursion depth and silently ignores most file system errors. Typically this is used by the - /// Microsoft.Extensions.FileSystemGlobbing library. - /// - internal class WorkspaceFileSystemWrapperFactory - { - private readonly string[] _allowedExtensions; - private readonly bool _ignoreReparsePoints; - - /// - /// Gets the maximum depth of the directories that will be searched - /// - internal int MaxRecursionDepth { get; } - - /// - /// Gets the logging facility - /// - internal ILogger Logger { get; } - - /// - /// Gets the directory where the factory is rooted. Only files and directories at this level, or deeper, will be visible - /// by the wrapper - /// - public DirectoryInfoBase RootDirectory { get; } - - /// - /// Creates a new FileWrapper Factory - /// - /// The path to the root directory for the factory. - /// The maximum directory depth. - /// An array of file extensions that will be visible from the factory. For example [".ps1", ".psm1"] - /// Whether objects which are Reparse Points should be ignored. https://docs.microsoft.com/en-us/windows/desktop/fileio/reparse-points - /// An ILogger implementation used for writing log messages. - public WorkspaceFileSystemWrapperFactory(string rootPath, int recursionDepthLimit, string[] allowedExtensions, bool ignoreReparsePoints, ILogger logger) - { - MaxRecursionDepth = recursionDepthLimit; - RootDirectory = new WorkspaceFileSystemDirectoryWrapper(this, new DirectoryInfo(rootPath), 0); - _allowedExtensions = allowedExtensions; - _ignoreReparsePoints = ignoreReparsePoints; - Logger = logger; - } - - /// - /// Creates a wrapped object from . - /// - internal DirectoryInfoBase CreateDirectoryInfoWrapper(DirectoryInfo dirInfo, int depth) => - new WorkspaceFileSystemDirectoryWrapper(this, dirInfo, depth >= 0 ? depth : 0); - - /// - /// Creates a wrapped object from . - /// - internal FileInfoBase CreateFileInfoWrapper(FileInfo fileInfo, int depth) => - new WorkspaceFileSystemFileInfoWrapper(this, fileInfo, depth >= 0 ? depth : 0); - - /// - /// Enumerates all objects in the specified directory and ignores most errors - /// - internal IEnumerable SafeEnumerateFileSystemInfos(DirectoryInfo dirInfo) - { - // Find the subdirectories - string[] subDirs; - try - { - subDirs = Directory.GetDirectories(dirInfo.FullName, "*", SearchOption.TopDirectoryOnly); - } - catch (DirectoryNotFoundException e) - { - Logger.LogHandledException( - $"Could not enumerate directories in the path '{dirInfo.FullName}' due to it being an invalid path", - e); - - yield break; - } - catch (PathTooLongException e) - { - Logger.LogHandledException( - $"Could not enumerate directories in the path '{dirInfo.FullName}' due to the path being too long", - e); - - yield break; - } - catch (Exception e) when (e is SecurityException or UnauthorizedAccessException) - { - Logger.LogHandledException( - $"Could not enumerate directories in the path '{dirInfo.FullName}' due to the path not being accessible", - e); - - yield break; - } - catch (Exception e) - { - Logger.LogHandledException( - $"Could not enumerate directories in the path '{dirInfo.FullName}' due to an exception", - e); - - yield break; - } - foreach (string dirPath in subDirs) - { - DirectoryInfo subDirInfo = new(dirPath); - if (_ignoreReparsePoints && (subDirInfo.Attributes & FileAttributes.ReparsePoint) != 0) { continue; } - yield return subDirInfo; - } - - // Find the files - string[] filePaths; - try - { - filePaths = Directory.GetFiles(dirInfo.FullName, "*", SearchOption.TopDirectoryOnly); - } - catch (DirectoryNotFoundException e) - { - Logger.LogHandledException( - $"Could not enumerate files in the path '{dirInfo.FullName}' due to it being an invalid path", - e); - - yield break; - } - catch (PathTooLongException e) - { - Logger.LogHandledException( - $"Could not enumerate files in the path '{dirInfo.FullName}' due to the path being too long", - e); - - yield break; - } - catch (Exception e) when (e is SecurityException or UnauthorizedAccessException) - { - Logger.LogHandledException( - $"Could not enumerate files in the path '{dirInfo.FullName}' due to the path not being accessible", - e); - - yield break; - } - catch (Exception e) - { - Logger.LogHandledException( - $"Could not enumerate files in the path '{dirInfo.FullName}' due to an exception", - e); - - yield break; - } - foreach (string filePath in filePaths) - { - FileInfo fileInfo = new(filePath); - if (_allowedExtensions == null || _allowedExtensions.Length == 0) { yield return fileInfo; continue; } - if (_ignoreReparsePoints && (fileInfo.Attributes & FileAttributes.ReparsePoint) != 0) { continue; } - foreach (string extension in _allowedExtensions) - { - if (fileInfo.Extension == extension) { yield return fileInfo; break; } - } - } - } - } - - /// - /// Wraps an instance of and provides implementation of - /// . - /// Based on https://github.com/aspnet/Extensions/blob/c087cadf1dfdbd2b8785ef764e5ef58a1a7e5ed0/src/FileSystemGlobbing/src/Abstractions/DirectoryInfoWrapper.cs - /// - internal class WorkspaceFileSystemDirectoryWrapper : DirectoryInfoBase - { - private readonly DirectoryInfo _concreteDirectoryInfo; - private readonly bool _isParentPath; - private readonly WorkspaceFileSystemWrapperFactory _fsWrapperFactory; - private readonly int _depth; - - /// - /// Initializes an instance of . - /// - public WorkspaceFileSystemDirectoryWrapper(WorkspaceFileSystemWrapperFactory factory, DirectoryInfo directoryInfo, int depth) - { - _concreteDirectoryInfo = directoryInfo; - _isParentPath = depth == 0; - _fsWrapperFactory = factory; - _depth = depth; - } - - /// - public override IEnumerable EnumerateFileSystemInfos() - { - if (!_concreteDirectoryInfo.Exists || _depth >= _fsWrapperFactory.MaxRecursionDepth) { yield break; } - foreach (FileSystemInfo fileSystemInfo in _fsWrapperFactory.SafeEnumerateFileSystemInfos(_concreteDirectoryInfo)) - { - switch (fileSystemInfo) - { - case DirectoryInfo dirInfo: - yield return _fsWrapperFactory.CreateDirectoryInfoWrapper(dirInfo, _depth + 1); - break; - case FileInfo fileInfo: - yield return _fsWrapperFactory.CreateFileInfoWrapper(fileInfo, _depth); - break; - default: - // We should NEVER get here, but if we do just continue on - break; - } - } - } - - /// - /// Returns an instance of that represents a subdirectory. - /// - /// - /// If equals '..', this returns the parent directory. - /// - /// The directory name. - /// The directory - public override DirectoryInfoBase GetDirectory(string name) - { - bool isParentPath = string.Equals(name, "..", StringComparison.Ordinal); - - if (isParentPath) { return ParentDirectory; } - - DirectoryInfo[] dirs = _concreteDirectoryInfo.GetDirectories(name); - - if (dirs.Length == 1) { return _fsWrapperFactory.CreateDirectoryInfoWrapper(dirs[0], _depth + 1); } - if (dirs.Length == 0) { return null; } - // This shouldn't happen. The parameter name isn't supposed to contain wild card. - throw new InvalidOperationException( - string.Format( - System.Globalization.CultureInfo.CurrentCulture, - "More than one sub directories are found under {0} with name {1}.", - _concreteDirectoryInfo.FullName, name)); - } - - /// - public override FileInfoBase GetFile(string name) => _fsWrapperFactory.CreateFileInfoWrapper(new FileInfo(Path.Combine(_concreteDirectoryInfo.FullName, name)), _depth); - - /// - public override string Name => _isParentPath ? ".." : _concreteDirectoryInfo.Name; - - /// - /// Returns the full path to the directory. - /// - public override string FullName => _concreteDirectoryInfo.FullName; - - /// - /// Safely calculates the parent of this directory, swallowing most errors. - /// - private DirectoryInfoBase SafeParentDirectory() - { - try - { - return _fsWrapperFactory.CreateDirectoryInfoWrapper(_concreteDirectoryInfo.Parent, _depth - 1); - } - catch (DirectoryNotFoundException e) - { - _fsWrapperFactory.Logger.LogHandledException( - $"Could not get parent of '{_concreteDirectoryInfo.FullName}' due to it being an invalid path", - e); - } - catch (PathTooLongException e) - { - _fsWrapperFactory.Logger.LogHandledException( - $"Could not get parent of '{_concreteDirectoryInfo.FullName}' due to the path being too long", - e); - } - catch (Exception e) when (e is SecurityException or UnauthorizedAccessException) - { - _fsWrapperFactory.Logger.LogHandledException( - $"Could not get parent of '{_concreteDirectoryInfo.FullName}' due to the path not being accessible", - e); - } - catch (Exception e) - { - _fsWrapperFactory.Logger.LogHandledException( - $"Could not get parent of '{_concreteDirectoryInfo.FullName}' due to an exception", - e); - } - return null; - } - - /// - /// Returns the parent directory. (Overrides ). - /// - public override DirectoryInfoBase ParentDirectory => SafeParentDirectory(); - } - - /// - /// Wraps an instance of to provide implementation of . - /// - internal class WorkspaceFileSystemFileInfoWrapper : FileInfoBase - { - private readonly FileInfo _concreteFileInfo; - private readonly WorkspaceFileSystemWrapperFactory _fsWrapperFactory; - private readonly int _depth; - - /// - /// Initializes instance of to wrap the specified object . - /// - public WorkspaceFileSystemFileInfoWrapper(WorkspaceFileSystemWrapperFactory factory, FileInfo fileInfo, int depth) - { - _fsWrapperFactory = factory; - _concreteFileInfo = fileInfo; - _depth = depth; - } - - /// - /// The file name. (Overrides ). - /// - public override string Name => _concreteFileInfo.Name; - - /// - /// The full path of the file. (Overrides ). - /// - public override string FullName => _concreteFileInfo.FullName; - - /// - /// Safely calculates the parent of this file, swallowing most errors. - /// - private DirectoryInfoBase SafeParentDirectory() - { - try - { - return _fsWrapperFactory.CreateDirectoryInfoWrapper(_concreteFileInfo.Directory, _depth); - } - catch (DirectoryNotFoundException e) - { - _fsWrapperFactory.Logger.LogHandledException( - $"Could not get parent of '{_concreteFileInfo.FullName}' due to it being an invalid path", - e); - } - catch (PathTooLongException e) - { - _fsWrapperFactory.Logger.LogHandledException( - $"Could not get parent of '{_concreteFileInfo.FullName}' due to the path being too long", - e); - } - catch (Exception e) when (e is SecurityException or UnauthorizedAccessException) - { - _fsWrapperFactory.Logger.LogHandledException( - $"Could not get parent of '{_concreteFileInfo.FullName}' due to the path not being accessible", - e); - } - catch (Exception e) - { - _fsWrapperFactory.Logger.LogHandledException( - $"Could not get parent of '{_concreteFileInfo.FullName}' due to an exception", - e); - } - return null; - } - - /// - /// The directory containing the file. (Overrides ). - /// - public override DirectoryInfoBase ParentDirectory => SafeParentDirectory(); - } -} diff --git a/src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs b/src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs index 54a1f2894..cd26d9289 100644 --- a/src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs +++ b/src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs @@ -6,12 +6,13 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Management.Automation; using System.Security; using System.Text; -using Microsoft.Extensions.FileSystemGlobbing; +using System.Threading; using Microsoft.Extensions.Logging; +using Microsoft.PowerShell.EditorServices.Services.PowerShell; using Microsoft.PowerShell.EditorServices.Services.TextDocument; -using Microsoft.PowerShell.EditorServices.Services.Workspace; using Microsoft.PowerShell.EditorServices.Utility; using OmniSharp.Extensions.LanguageServer.Protocol; using OmniSharp.Extensions.LanguageServer.Protocol.Models; @@ -84,6 +85,8 @@ internal class WorkspaceService /// public bool FollowSymlinks { get; set; } + private readonly IInternalPowerShellExecutionService executionService; + #endregion #region Constructors @@ -91,13 +94,14 @@ internal class WorkspaceService /// /// Creates a new instance of the Workspace class. /// - public WorkspaceService(ILoggerFactory factory) + public WorkspaceService(ILoggerFactory factory, IInternalPowerShellExecutionService executionService) { powerShellVersion = VersionUtils.PSVersion; logger = factory.CreateLogger(); WorkspaceFolders = new List(); ExcludeFilesGlob = new List(); FollowSymlinks = true; + this.executionService = executionService; } #endregion @@ -139,19 +143,9 @@ public ScriptFile GetFile(DocumentUri documentUri) // Make sure the file isn't already loaded into the workspace if (!workspaceFiles.TryGetValue(keyName, out ScriptFile scriptFile)) { - // This method allows FileNotFoundException to bubble up - // if the file isn't found. - using (StreamReader streamReader = OpenStreamReader(documentUri)) - { - scriptFile = - new ScriptFile( - documentUri, - streamReader, - powerShellVersion); - - workspaceFiles[keyName] = scriptFile; - } - + string fileContent = ReadFileContents(documentUri); + scriptFile = new ScriptFile(documentUri, fileContent, powerShellVersion); + workspaceFiles[keyName] = scriptFile; logger.LogDebug("Opened file on disk: " + documentUri.ToString()); } @@ -348,7 +342,6 @@ public IEnumerable EnumeratePSFiles() ignoreReparsePoints: !FollowSymlinks ); } - /// /// Enumerate all the PowerShell (ps1, psm1, psd1) files in the workspace folders in a /// recursive manner. Falls back to initial working directory if there are no workspace folders. @@ -360,33 +353,22 @@ public IEnumerable EnumeratePSFiles( int maxDepth, bool ignoreReparsePoints) { - Matcher matcher = new(); - foreach (string pattern in includeGlobs) { matcher.AddInclude(pattern); } - foreach (string pattern in excludeGlobs) { matcher.AddExclude(pattern); } + PSCommand psCommand = new(); + psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Get-ChildItem") + .AddParameter("Path", WorkspacePaths) + .AddParameter("File") + .AddParameter("Recurse") + .AddParameter("ErrorAction", "SilentlyContinue") + .AddParameter("Force") + .AddParameter("Include", includeGlobs.Concat(VersionUtils.IsNetCore ? s_psFileExtensionsCoreFramework : s_psFileExtensionsFullFramework)) + .AddParameter("Exclude", excludeGlobs) + .AddParameter("Depth", maxDepth) + .AddParameter("FollowSymlink", !ignoreReparsePoints) + .AddCommand("Select-Object") + .AddParameter("ExpandObject", "FullName"); + IEnumerable results = executionService.ExecutePSCommandAsync(psCommand, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult(); + return results; - foreach (string rootPath in WorkspacePaths) - { - if (!Directory.Exists(rootPath)) - { - continue; - } - - WorkspaceFileSystemWrapperFactory fsFactory = new( - rootPath, - maxDepth, - VersionUtils.IsNetCore ? s_psFileExtensionsCoreFramework : s_psFileExtensionsFullFramework, - ignoreReparsePoints, - logger); - - PatternMatchingResult fileMatchResult = matcher.Execute(fsFactory.RootDirectory); - foreach (FilePatternMatch item in fileMatchResult.Files) - { - // item.Path always contains forward slashes in paths when it should be backslashes on Windows. - // Since we're returning strings here, it's important to use the correct directory separator. - string path = VersionUtils.IsWindows ? item.Path.Replace('/', Path.DirectorySeparatorChar) : item.Path; - yield return Path.Combine(rootPath, path); - } - } } #endregion @@ -403,10 +385,57 @@ internal static StreamReader OpenStreamReader(DocumentUri uri) return new StreamReader(fileStream, new UTF8Encoding(), detectEncodingFromByteOrderMarks: true); } - internal static string ReadFileContents(DocumentUri uri) + internal string ReadFileContents(DocumentUri uri) { - using StreamReader reader = OpenStreamReader(uri); - return reader.ReadToEnd(); + PSCommand psCommand = new(); + string pspath; + if (uri.Scheme == Uri.UriSchemeFile) + { + pspath = uri.ToUri().LocalPath; + } + else + { + string PSProvider = uri.Authority; + string path = uri.Path; + pspath = $"{PSProvider}::{path}"; + } + /* uri - "file:///c:/Users/dkattan/source/repos/immybot-ref/submodules/PowerShellEditorServices/test/PowerShellEditorServices.Test.Shared/Completion/CompletionExamples.psm1" + * Authority = "" + * Fragment = "" + * Path = "/C:/Users/dkattan/source/repos/immybot-ref/submodules/PowerShellEditorServices/test/PowerShellEditorServices.Test.Shared/Completion/CompletionExamples.psm1" + * Query = "" + * Scheme = "file" + * PSPath - "Microsoft.PowerShell.Core\FileSystem::C:\Users\dkattan\source\repos\immybot-ref\submodules\PowerShellEditorServices\test\PowerShellEditorServices.Test.Shared\Completion\CompletionExamples.psm1" + * + * Suggested Format: + * Authority = "Microsoft.PowerShell.Core\FileSystem" + * Scheme = "PSProvider" + * Path = "/C:/Users/dkattan/source/repos/immybot-ref/submodules/PowerShellEditorServices/test/PowerShellEditorServices.Test.Shared/Completion/CompletionExamples.psm1" + * Result -> "PSProvider://Microsoft.PowerShell.Core/FileSystem::C:/Users/dkattan/source/repos/immybot-ref/submodules/PowerShellEditorServices/test/PowerShellEditorServices.Test.Shared/Completion/CompletionExamples.psm1" + * + * Suggested Format 2: + * Authority = "" + * Scheme = "FileSystem" + * Path = "/C:/Users/dkattan/source/repos/immybot-ref/submodules/PowerShellEditorServices/test/PowerShellEditorServices.Test.Shared/Completion/CompletionExamples.psm1" + * Result "FileSystem://c:/Users/dkattan/source/repos/immybot-ref/submodules/PowerShellEditorServices/test/PowerShellEditorServices.Test.Shared/Completion/CompletionExamples.psm1" + + */ + psCommand.AddCommand("Get-Content") + .AddParameter("LiteralPath", pspath) + .AddParameter("Raw", true) + .AddParameter("ErrorAction", ActionPreference.Stop); + try + { + IEnumerable result = executionService.ExecutePSCommandAsync(psCommand, CancellationToken.None, new PowerShell.Execution.PowerShellExecutionOptions() + { + ThrowOnError = true + }).ConfigureAwait(false).GetAwaiter().GetResult(); + return result.FirstOrDefault(); + } + catch (ActionPreferenceStopException ex) when (ex.ErrorRecord.CategoryInfo.Category == ErrorCategory.ObjectNotFound && ex.ErrorRecord.TargetObject is string[] missingFiles && missingFiles.Count() == 1) + { + throw new FileNotFoundException(ex.ErrorRecord.ToString(), missingFiles.First(), ex.ErrorRecord.Exception); + } } internal string ResolveWorkspacePath(string path) => ResolveRelativeScriptPath(InitialWorkingDirectory, path); @@ -429,10 +458,18 @@ internal string ResolveRelativeScriptPath(string baseFilePath, string relativePa // Get the directory of the original script file, combine it // with the given path and then resolve the absolute file path. combinedPath = - Path.GetFullPath( - Path.Combine( - baseFilePath, - relativePath)); + Path.GetFullPath( + Path.Combine( + baseFilePath, + relativePath)); + + PSCommand psCommand = new(); + psCommand.AddCommand("Resolve-Path") + .AddParameter("Relative", true) + .AddParameter("Path", relativePath) + .AddParameter("RelativeBasePath", baseFilePath); + IEnumerable result = executionService.ExecutePSCommandAsync(psCommand, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult(); + combinedPath = result.FirstOrDefault(); } catch (NotSupportedException e) { diff --git a/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs b/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs index 30b020c30..670cac4e1 100644 --- a/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs +++ b/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs @@ -70,7 +70,7 @@ public DebugServiceTests() debugService.DebuggerStopped += OnDebuggerStopped; // Load the test debug files. - workspace = new WorkspaceService(NullLoggerFactory.Instance); + workspace = new WorkspaceService(NullLoggerFactory.Instance, PsesHostFactory.Create(NullLoggerFactory.Instance)); debugScriptFile = GetDebugScript("DebugTest.ps1"); oddPathScriptFile = GetDebugScript("Debug' W&ith $Params [Test].ps1"); variableScriptFile = GetDebugScript("VariableTest.ps1"); diff --git a/test/PowerShellEditorServices.Test/Language/CompletionHandlerTests.cs b/test/PowerShellEditorServices.Test/Language/CompletionHandlerTests.cs index fae0f8104..bed56fe45 100644 --- a/test/PowerShellEditorServices.Test/Language/CompletionHandlerTests.cs +++ b/test/PowerShellEditorServices.Test/Language/CompletionHandlerTests.cs @@ -30,7 +30,7 @@ public class CompletionHandlerTests : IDisposable public CompletionHandlerTests() { psesHost = PsesHostFactory.Create(NullLoggerFactory.Instance); - workspace = new WorkspaceService(NullLoggerFactory.Instance); + workspace = new WorkspaceService(NullLoggerFactory.Instance, psesHost); completionHandler = new PsesCompletionHandler(NullLoggerFactory.Instance, psesHost, psesHost, workspace); } @@ -42,12 +42,12 @@ public void Dispose() GC.SuppressFinalize(this); } - private ScriptFile GetScriptFile(ScriptRegion scriptRegion) => workspace.GetFile(TestUtilities.GetSharedPath(scriptRegion.File)); + private async Task GetScriptFile(ScriptRegion scriptRegion) => workspace.GetFile(TestUtilities.GetSharedPath(scriptRegion.File)); - private Task GetCompletionResultsAsync(ScriptRegion scriptRegion) + private async Task GetCompletionResultsAsync(ScriptRegion scriptRegion) { - return completionHandler.GetCompletionsInFileAsync( - GetScriptFile(scriptRegion), + return await completionHandler.GetCompletionsInFileAsync( + await GetScriptFile(scriptRegion), scriptRegion.StartLineNumber, scriptRegion.StartColumnNumber, CancellationToken.None); diff --git a/test/PowerShellEditorServices.Test/Language/SymbolsServiceTests.cs b/test/PowerShellEditorServices.Test/Language/SymbolsServiceTests.cs index f078d8d42..3a9a793b5 100644 --- a/test/PowerShellEditorServices.Test/Language/SymbolsServiceTests.cs +++ b/test/PowerShellEditorServices.Test/Language/SymbolsServiceTests.cs @@ -40,7 +40,7 @@ public class SymbolsServiceTests : IDisposable public SymbolsServiceTests() { psesHost = PsesHostFactory.Create(NullLoggerFactory.Instance); - workspace = new WorkspaceService(NullLoggerFactory.Instance); + workspace = new WorkspaceService(NullLoggerFactory.Instance, psesHost); workspace.WorkspaceFolders.Add(new WorkspaceFolder { Uri = DocumentUri.FromFileSystemPath(TestUtilities.GetSharedPath("References")) diff --git a/test/PowerShellEditorServices.Test/Services/Symbols/AstOperationsTests.cs b/test/PowerShellEditorServices.Test/Services/Symbols/AstOperationsTests.cs index 649ef32fd..fe8048d4f 100644 --- a/test/PowerShellEditorServices.Test/Services/Symbols/AstOperationsTests.cs +++ b/test/PowerShellEditorServices.Test/Services/Symbols/AstOperationsTests.cs @@ -7,6 +7,7 @@ using Microsoft.PowerShell.EditorServices.Services; using Microsoft.PowerShell.EditorServices.Services.Symbols; using Microsoft.PowerShell.EditorServices.Services.TextDocument; +using Microsoft.PowerShell.EditorServices.Test; using Microsoft.PowerShell.EditorServices.Test.Shared; using OmniSharp.Extensions.LanguageServer.Protocol.Models; using Xunit; @@ -20,7 +21,7 @@ public class AstOperationsTests public AstOperationsTests() { - WorkspaceService workspace = new(NullLoggerFactory.Instance); + WorkspaceService workspace = new(NullLoggerFactory.Instance, PsesHostFactory.Create(NullLoggerFactory.Instance)); scriptFile = workspace.GetFile(TestUtilities.GetSharedPath("References/FunctionReference.ps1")); } diff --git a/test/PowerShellEditorServices.Test/Services/Symbols/PSScriptAnalyzerTests.cs b/test/PowerShellEditorServices.Test/Services/Symbols/PSScriptAnalyzerTests.cs index 1155db102..ed7782999 100644 --- a/test/PowerShellEditorServices.Test/Services/Symbols/PSScriptAnalyzerTests.cs +++ b/test/PowerShellEditorServices.Test/Services/Symbols/PSScriptAnalyzerTests.cs @@ -15,7 +15,7 @@ namespace PowerShellEditorServices.Test.Services.Symbols [Trait("Category", "PSScriptAnalyzer")] public class PSScriptAnalyzerTests { - private readonly WorkspaceService workspaceService = new(NullLoggerFactory.Instance); + private readonly WorkspaceService workspaceService = new(NullLoggerFactory.Instance, PsesHostFactory.Create(NullLoggerFactory.Instance)); private readonly AnalysisService analysisService; private const string script = "function Do-Work {}"; diff --git a/test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs b/test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs index 01f31325a..c35a17304 100644 --- a/test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs +++ b/test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs @@ -12,6 +12,7 @@ using Microsoft.PowerShell.EditorServices.Utility; using OmniSharp.Extensions.LanguageServer.Protocol.Models; using OmniSharp.Extensions.LanguageServer.Protocol; +using Microsoft.PowerShell.EditorServices.Test; namespace PowerShellEditorServices.Test.Session { @@ -39,7 +40,7 @@ public void CanResolveWorkspaceRelativePath() ScriptFile testPathOutside = CreateScriptFile("c:/Test/PeerPath/FilePath.ps1"); ScriptFile testPathAnotherDrive = CreateScriptFile("z:/TryAndFindMe/FilePath.ps1"); - WorkspaceService workspace = new(NullLoggerFactory.Instance); + WorkspaceService workspace = new(NullLoggerFactory.Instance, PsesHostFactory.Create(NullLoggerFactory.Instance)); // Test with zero workspace folders Assert.Equal( @@ -77,7 +78,7 @@ public void CanResolveWorkspaceRelativePath() internal static WorkspaceService FixturesWorkspace() { - return new WorkspaceService(NullLoggerFactory.Instance) + return new WorkspaceService(NullLoggerFactory.Instance, PsesHostFactory.Create(NullLoggerFactory.Instance)) { WorkspaceFolders = { diff --git a/test/PowerShellEditorServices.Test/packages.lock.json b/test/PowerShellEditorServices.Test/packages.lock.json index 002721a39..7ab35988d 100644 --- a/test/PowerShellEditorServices.Test/packages.lock.json +++ b/test/PowerShellEditorServices.Test/packages.lock.json @@ -11,15 +11,6 @@ "Microsoft.CodeCoverage": "17.8.0" } }, - "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" - } - }, "Microsoft.PowerShell.5.ReferenceAssemblies": { "type": "Direct", "requested": "[1.1.0, )", @@ -183,11 +174,6 @@ "System.Runtime.CompilerServices.Unsafe": "6.0.0" } }, - "Microsoft.NETFramework.ReferenceAssemblies.net462": { - "type": "Transitive", - "resolved": "1.0.3", - "contentHash": "IzAV30z22ESCeQfxP29oVf4qEo8fBGXLXSU6oacv/9Iqe6PzgHDKCaWfwMBak7bSJQM0F5boXWoZS+kChztRIQ==" - }, "Microsoft.TestPlatform.ObjectModel": { "type": "Transitive", "resolved": "17.8.0", @@ -550,7 +536,7 @@ "Microsoft.PowerShell.EditorServices.Test.Shared": { "type": "Project", "dependencies": { - "Microsoft.PowerShell.EditorServices": "[3.16.0, )" + "Microsoft.PowerShell.EditorServices": "[3.17.0, )" } } }, @@ -1691,7 +1677,7 @@ "Microsoft.PowerShell.EditorServices.Test.Shared": { "type": "Project", "dependencies": { - "Microsoft.PowerShell.EditorServices": "[3.16.0, )" + "Microsoft.PowerShell.EditorServices": "[3.17.0, )" } } }, @@ -2820,7 +2806,7 @@ "Microsoft.PowerShell.EditorServices.Test.Shared": { "type": "Project", "dependencies": { - "Microsoft.PowerShell.EditorServices": "[3.16.0, )" + "Microsoft.PowerShell.EditorServices": "[3.17.0, )" } } }, @@ -3948,7 +3934,7 @@ "Microsoft.PowerShell.EditorServices.Test.Shared": { "type": "Project", "dependencies": { - "Microsoft.PowerShell.EditorServices": "[3.16.0, )" + "Microsoft.PowerShell.EditorServices": "[3.17.0, )" } } }