diff --git a/module/PowerShellEditorServices/Commands/Public/CmdletInterface.ps1 b/module/PowerShellEditorServices/Commands/Public/CmdletInterface.ps1 index 690506bd3..285e26120 100644 --- a/module/PowerShellEditorServices/Commands/Public/CmdletInterface.ps1 +++ b/module/PowerShellEditorServices/Commands/Public/CmdletInterface.ps1 @@ -47,7 +47,7 @@ function Register-EditorCommand { $commandArgs += $Function } - $editorCommand = New-Object Microsoft.PowerShell.EditorServices.Services.PowerShellContext.EditorCommand -ArgumentList $commandArgs + $editorCommand = New-Object Microsoft.PowerShell.EditorServices.Extensions.EditorCommand -ArgumentList $commandArgs if ($psEditor.RegisterCommand($editorCommand)) { Write-Verbose "Registered new command '$Name'" diff --git a/src/PowerShellEditorServices.Hosting/Configuration/HostLogger.cs b/src/PowerShellEditorServices.Hosting/Configuration/HostLogger.cs index a59551977..704dde9ab 100644 --- a/src/PowerShellEditorServices.Hosting/Configuration/HostLogger.cs +++ b/src/PowerShellEditorServices.Hosting/Configuration/HostLogger.cs @@ -32,7 +32,7 @@ public enum PsesLogLevel /// A logging front-end for host startup allowing handover to the backend /// and decoupling from the host's particular logging sink. /// - public class HostLogger : + public sealed class HostLogger : IObservable<(PsesLogLevel logLevel, string message)>, IObservable<(int logLevel, string message)> { diff --git a/src/PowerShellEditorServices.Hosting/Configuration/SessionFileWriter.cs b/src/PowerShellEditorServices.Hosting/Configuration/SessionFileWriter.cs index 12842d618..e155de96d 100644 --- a/src/PowerShellEditorServices.Hosting/Configuration/SessionFileWriter.cs +++ b/src/PowerShellEditorServices.Hosting/Configuration/SessionFileWriter.cs @@ -36,7 +36,7 @@ public interface ISessionFileWriter /// /// The default session file writer, which uses PowerShell to write a session file. /// - public class SessionFileWriter : ISessionFileWriter + public sealed class SessionFileWriter : ISessionFileWriter { // Use BOM-less UTF-8 for session file private static readonly Encoding s_sessionFileEncoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false); diff --git a/src/PowerShellEditorServices.Hosting/Configuration/TransportConfig.cs b/src/PowerShellEditorServices.Hosting/Configuration/TransportConfig.cs index 072f2dc6d..2287169df 100644 --- a/src/PowerShellEditorServices.Hosting/Configuration/TransportConfig.cs +++ b/src/PowerShellEditorServices.Hosting/Configuration/TransportConfig.cs @@ -41,7 +41,7 @@ public interface ITransportConfig /// /// Configuration for the standard input/output transport. /// - public class StdioTransportConfig : ITransportConfig + public sealed class StdioTransportConfig : ITransportConfig { public string EndpointDetails => ""; @@ -58,7 +58,7 @@ public class StdioTransportConfig : ITransportConfig /// /// Configuration for a full duplex named pipe. /// - public class DuplexNamedPipeTransportConfig : ITransportConfig + public sealed class DuplexNamedPipeTransportConfig : ITransportConfig { /// /// Create a duplex named pipe transport config with an automatically generated pipe name. @@ -108,7 +108,7 @@ private DuplexNamedPipeTransportConfig(string pipeName) /// /// Configuration for two simplex named pipes. /// - public class SimplexNamedPipeTransportConfig : ITransportConfig + public sealed class SimplexNamedPipeTransportConfig : ITransportConfig { private const string InPipePrefix = "in"; private const string OutPipePrefix = "out"; diff --git a/src/PowerShellEditorServices.VSCode/Cmdlets/VSCodeHtmlContentViewCommands.cs b/src/PowerShellEditorServices.VSCode/Cmdlets/VSCodeHtmlContentViewCommands.cs index de767821c..d81933e26 100644 --- a/src/PowerShellEditorServices.VSCode/Cmdlets/VSCodeHtmlContentViewCommands.cs +++ b/src/PowerShellEditorServices.VSCode/Cmdlets/VSCodeHtmlContentViewCommands.cs @@ -7,7 +7,7 @@ using System.Management.Automation; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Microsoft.PowerShell.EditorServices.Services.PowerShellContext; +using Microsoft.PowerShell.EditorServices.Extensions; using Microsoft.PowerShell.EditorServices.VSCode.CustomViews; using OmniSharp.Extensions.LanguageServer.Protocol.Server; @@ -20,8 +20,6 @@ public class NewVSCodeHtmlContentViewCommand : PSCmdlet { private HtmlContentViewsFeature _htmlContentViewsFeature; - private ILogger _logger; - private ViewColumn? _showInColumn; /// @@ -44,13 +42,8 @@ protected override void BeginProcessing() { if (GetVariableValue("psEditor") is EditorObject psEditor) { - _logger = psEditor.Components.GetService().CreateLogger("PowerShellEditorServices.VSCode"); - _htmlContentViewsFeature = new HtmlContentViewsFeature( - psEditor.Components.GetService(), - _logger); - - _logger.LogInformation("PowerShell Editor Services VS Code module loaded."); + psEditor.GetExtensionServiceProvider().LanguageServer); } else { diff --git a/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewBase.cs b/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewBase.cs index 524ea181b..adf47996b 100644 --- a/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewBase.cs +++ b/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewBase.cs @@ -5,16 +5,13 @@ using System; using System.Threading.Tasks; -using Microsoft.Extensions.Logging; -using OmniSharp.Extensions.LanguageServer.Protocol.Server; +using Microsoft.PowerShell.EditorServices.Extensions.Services; namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews { internal abstract class CustomViewBase : ICustomView { - protected ILanguageServer languageServer; - - protected ILogger logger; + protected ILanguageServerService languageServer; public Guid Id { get; private set; } @@ -25,19 +22,17 @@ internal abstract class CustomViewBase : ICustomView public CustomViewBase( string viewTitle, CustomViewType viewType, - ILanguageServer languageServer, - ILogger logger) + ILanguageServerService languageServer) { this.Id = Guid.NewGuid(); this.Title = viewTitle; this.ViewType = viewType; this.languageServer = languageServer; - this.logger = logger; } internal async Task CreateAsync() { - await languageServer.SendRequest( + await languageServer.SendRequestAsync( NewCustomViewRequest.Method, new NewCustomViewRequest { @@ -50,7 +45,7 @@ await languageServer.SendRequest( public async Task Show(ViewColumn viewColumn) { - await languageServer.SendRequest( + await languageServer.SendRequestAsync( ShowCustomViewRequest.Method, new ShowCustomViewRequest { @@ -62,7 +57,7 @@ await languageServer.SendRequest( public async Task Close() { - await languageServer.SendRequest( + await languageServer.SendRequestAsync( CloseCustomViewRequest.Method, new CloseCustomViewRequest { diff --git a/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewFeature.cs b/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewFeature.cs index 0e6c9a85f..e5475fc2c 100644 --- a/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewFeature.cs +++ b/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewFeature.cs @@ -5,26 +5,22 @@ using System; using System.Collections.Generic; -using Microsoft.Extensions.Logging; -using OmniSharp.Extensions.LanguageServer.Protocol.Server; +using Microsoft.PowerShell.EditorServices.Extensions.Services; namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews { internal abstract class CustomViewFeatureBase where TView : ICustomView { - protected ILanguageServer languageServer; + protected ILanguageServerService languageServer; - protected ILogger logger; private readonly Dictionary viewIndex; public CustomViewFeatureBase( - ILanguageServer languageServer, - ILogger logger) + ILanguageServerService languageServer) { this.viewIndex = new Dictionary(); this.languageServer = languageServer; - this.logger = logger; } protected void AddView(TView view) diff --git a/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentView.cs b/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentView.cs index b615e58fe..685e11615 100644 --- a/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentView.cs +++ b/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentView.cs @@ -7,8 +7,7 @@ using System.IO; using System.Linq; using System.Threading.Tasks; -using Microsoft.Extensions.Logging; -using OmniSharp.Extensions.LanguageServer.Protocol.Server; +using Microsoft.PowerShell.EditorServices.Extensions.Services; namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews { @@ -16,19 +15,17 @@ internal class HtmlContentView : CustomViewBase, IHtmlContentView { public HtmlContentView( string viewTitle, - ILanguageServer languageServer, - ILogger logger) + ILanguageServerService languageServer) : base( viewTitle, CustomViewType.HtmlContent, - languageServer, - logger) + languageServer) { } public async Task SetContentAsync(string htmlBodyContent) { - await languageServer.SendRequest( + await languageServer.SendRequestAsync( SetHtmlContentViewRequest.Method, new SetHtmlContentViewRequest { @@ -48,7 +45,7 @@ public async Task SetContentAsync(HtmlContent htmlContent) StyleSheetPaths = this.GetUriPaths(htmlContent.StyleSheetPaths) }; - await languageServer.SendRequest( + await languageServer.SendRequestAsync( SetHtmlContentViewRequest.Method, new SetHtmlContentViewRequest { @@ -60,7 +57,7 @@ await languageServer.SendRequest( public async Task AppendContentAsync(string appendedHtmlBodyContent) { - await languageServer.SendRequest( + await languageServer.SendRequestAsync( AppendHtmlContentViewRequest.Method, new AppendHtmlContentViewRequest { diff --git a/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentViewsFeature.cs b/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentViewsFeature.cs index e23d1b552..39ca58ba3 100644 --- a/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentViewsFeature.cs +++ b/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentViewsFeature.cs @@ -4,17 +4,15 @@ // using System.Threading.Tasks; -using Microsoft.Extensions.Logging; -using OmniSharp.Extensions.LanguageServer.Protocol.Server; +using Microsoft.PowerShell.EditorServices.Extensions.Services; namespace Microsoft.PowerShell.EditorServices.VSCode.CustomViews { internal class HtmlContentViewsFeature : CustomViewFeatureBase, IHtmlContentViews { public HtmlContentViewsFeature( - ILanguageServer languageServer, - ILogger logger) - : base(languageServer, logger) + ILanguageServerService languageServer) + : base(languageServer) { } @@ -23,8 +21,7 @@ public async Task CreateHtmlContentViewAsync(string viewTitle) HtmlContentView htmlView = new HtmlContentView( viewTitle, - this.languageServer, - this.logger); + languageServer); await htmlView.CreateAsync(); this.AddView(htmlView); diff --git a/src/PowerShellEditorServices/Extensions/Api/DocumentSymbolService.cs b/src/PowerShellEditorServices/Extensions/Api/DocumentSymbolService.cs new file mode 100644 index 000000000..1a4c0fc4e --- /dev/null +++ b/src/PowerShellEditorServices/Extensions/Api/DocumentSymbolService.cs @@ -0,0 +1,279 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Management.Automation.Language; +using Microsoft.PowerShell.EditorServices.Services; +using Microsoft.PowerShell.EditorServices.Services.TextDocument; + +using Internal = Microsoft.PowerShell.EditorServices.Services.Symbols; + +// TODO: This is currently disabled in the csproj +// Redesign this API and bring it back once it's fit for purpose + +namespace Microsoft.PowerShell.EditorServices.Extensions.Services +{ + /// + /// A way to define symbols on a higher level + /// + public enum SymbolType + { + /// + /// The symbol type is unknown + /// + Unknown = 0, + + /// + /// The symbol is a vairable + /// + Variable = 1, + + /// + /// The symbol is a function + /// + Function = 2, + + /// + /// The symbol is a parameter + /// + Parameter = 3, + + /// + /// The symbol is a DSC configuration + /// + Configuration = 4, + + /// + /// The symbol is a workflow + /// + Workflow = 5, + + /// + /// The symbol is a hashtable key + /// + HashtableKey = 6, + } + + /// + /// Interface to instantiate to create a provider of document symbols. + /// + public interface IDocumentSymbolProvider + { + /// + /// The unique ID of this provider. + /// + string ProviderId { get; } + + /// + /// Run this provider to provide symbols to PSES from the given file. + /// + /// The script file to provide symbols for. + /// Symbols about the file. + IEnumerable ProvideDocumentSymbols(IEditorScriptFile scriptFile); + } + + /// + /// A class that holds the type, name, script extent, and source line of a symbol + /// + [DebuggerDisplay("SymbolType = {SymbolType}, SymbolName = {SymbolName}")] + public class SymbolReference + { + /// + /// Constructs an instance of a SymbolReference + /// + /// The higher level type of the symbol + /// The script extent of the symbol + /// The file path of the symbol + /// The line contents of the given symbol (defaults to empty string) + public SymbolReference(SymbolType symbolType, IScriptExtent scriptExtent) + : this(symbolType, scriptExtent.Text, scriptExtent) + { + } + + /// + /// Constructs and instance of a SymbolReference + /// + /// The higher level type of the symbol + /// The name of the symbol + /// The script extent of the symbol + /// The file path of the symbol + /// The line contents of the given symbol (defaults to empty string) + public SymbolReference( + SymbolType symbolType, + string symbolName, + IScriptExtent scriptExtent) + : this(symbolType, scriptExtent, symbolName, filePath: string.Empty, sourceLine: string.Empty) + { + } + + public SymbolReference( + SymbolType symbolType, + IScriptExtent scriptExtent, + string symbolName, + string filePath) + : this(symbolType, scriptExtent, symbolName, filePath, sourceLine: string.Empty) + { + } + + public SymbolReference(SymbolType symbolType, IScriptExtent scriptExtent, string symbolName, string filePath, string sourceLine) + { + // TODO: Verify params + SymbolType = symbolType; + ScriptRegion = ScriptRegion.Create(scriptExtent); + SymbolName = symbolName; + FilePath = filePath; + SourceLine = sourceLine; + + // TODO: Make sure end column number usage is correct + } + + #region Properties + + /// + /// Gets the symbol's type + /// + public SymbolType SymbolType { get; } + + /// + /// Gets the name of the symbol + /// + public string SymbolName { get; } + + /// + /// Gets the script extent of the symbol + /// + public ScriptRegion ScriptRegion { get; } + + /// + /// Gets the contents of the line the given symbol is on + /// + public string SourceLine { get; } + + /// + /// Gets the path of the file in which the symbol was found. + /// + public string FilePath { get; internal set; } + + #endregion + } + + /// + /// Service for registration of document symbol providers in PSES. + /// + public interface IDocumentSymbolService + { + /// + /// Register a document symbol provider by its ID. + /// If another provider is already registered by the same ID, this will fail and return false. + /// + /// The document symbol provider to register. + /// True if the symbol provider was successfully registered, false otherwise. + bool RegisterDocumentSymbolProvider(IDocumentSymbolProvider documentSymbolProvider); + + /// + /// Deregister a symbol provider of the given ID. + /// + /// The ID of the provider to deregister. + /// True if a provider by the given ID was deregistered, false if no such provider was found. + bool DeregisterDocumentSymbolProvider(string providerId); + } + + internal class DocumentSymbolService : IDocumentSymbolService + { + private readonly SymbolsService _symbolsService; + + internal DocumentSymbolService(SymbolsService symbolsService) + { + _symbolsService = symbolsService; + } + + public bool RegisterDocumentSymbolProvider(IDocumentSymbolProvider documentSymbolProvider) + { + return _symbolsService.TryRegisterDocumentSymbolProvider(new ExternalDocumentSymbolProviderAdapter(documentSymbolProvider)); + } + + public bool DeregisterDocumentSymbolProvider(string providerId) + { + return _symbolsService.DeregisterCodeLensProvider(providerId); + } + } + + internal class ExternalDocumentSymbolProviderAdapter : Internal.IDocumentSymbolProvider + { + private readonly IDocumentSymbolProvider _symbolProvider; + + public ExternalDocumentSymbolProviderAdapter( + IDocumentSymbolProvider externalDocumentSymbolProvider) + { + _symbolProvider = externalDocumentSymbolProvider; + } + + public string ProviderId => _symbolProvider.ProviderId; + + public IEnumerable ProvideDocumentSymbols(ScriptFile scriptFile) + { + foreach (SymbolReference symbolReference in _symbolProvider.ProvideDocumentSymbols(new EditorScriptFile(scriptFile))) + { + yield return new ExternalSymbolReferenceAdapter(symbolReference); + } + } + } + + internal class ExternalSymbolReferenceAdapter : Internal.ISymbolReference + { + private readonly SymbolReference _symbolReference; + + public ExternalSymbolReferenceAdapter(SymbolReference symbolReference) + { + _symbolReference = symbolReference; + } + + public Internal.SymbolType SymbolType => _symbolReference.SymbolType.ToInternalSymbolType(); + + public string SymbolName => _symbolReference.SymbolName; + + public ScriptRegion ScriptRegion => _symbolReference.ScriptRegion; + + public string SourceLine => _symbolReference.SourceLine; + + public string FilePath => _symbolReference.FilePath; + } + + internal static class SymbolTypeExtensions + { + public static Internal.SymbolType ToInternalSymbolType(this SymbolType symbolType) + { + switch (symbolType) + { + case SymbolType.Unknown: + return Internal.SymbolType.Unknown; + + case SymbolType.Variable: + return Internal.SymbolType.Variable; + + case SymbolType.Function: + return Internal.SymbolType.Function; + + case SymbolType.Parameter: + return Internal.SymbolType.Parameter; + + case SymbolType.Configuration: + return Internal.SymbolType.Configuration; + + case SymbolType.Workflow: + return Internal.SymbolType.Workflow; + + case SymbolType.HashtableKey: + return Internal.SymbolType.HashtableKey; + + default: + throw new InvalidOperationException($"Unknown symbol type '{symbolType}'"); + } + } + } +} + diff --git a/src/PowerShellEditorServices/Extensions/Api/EditorContextService.cs b/src/PowerShellEditorServices/Extensions/Api/EditorContextService.cs new file mode 100644 index 000000000..4440dede4 --- /dev/null +++ b/src/PowerShellEditorServices/Extensions/Api/EditorContextService.cs @@ -0,0 +1,154 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Threading.Tasks; +using Microsoft.PowerShell.EditorServices.Handlers; +using OmniSharp.Extensions.LanguageServer.Protocol.Server; + +namespace Microsoft.PowerShell.EditorServices.Extensions.Services +{ + /// + /// Service for managing the editor context from PSES extensions. + /// + public interface IEditorContextService + { + /// + /// Get the file context of the currently open file. + /// + /// The file context of the currently open file. + Task GetCurrentLspFileContextAsync(); + + /// + /// Open a fresh untitled file in the editor. + /// + /// A task that resolves when the file has been opened. + Task OpenNewUntitledFileAsync(); + + /// + /// Open the given file in the editor. + /// + /// The absolute URI to the file to open. + /// A task that resolves when the file has been opened. + Task OpenFileAsync(Uri fileUri); + + /// + /// Open the given file in the editor. + /// + /// The absolute URI to the file to open. + /// If true, open the file as a preview. + /// A task that resolves when the file is opened. + Task OpenFileAsync(Uri fileUri, bool preview); + + /// + /// Close the given file in the editor. + /// + /// The absolute URI to the file to close. + /// A task that resolves when the file has been closed. + Task CloseFileAsync(Uri fileUri); + + /// + /// Save the given file in the editor. + /// + /// The absolute URI of the file to save. + /// A task that resolves when the file has been saved. + Task SaveFileAsync(Uri fileUri); + + /// + /// Save the given file under a new name in the editor. + /// + /// The absolute URI of the file to save. + /// The absolute URI of the location to save the file. + /// + Task SaveFileAsync(Uri oldFileUri, Uri newFileUri); + + /// + /// Set the selection in the currently focused editor window. + /// + /// The range in the file to select. + /// A task that resolves when the range has been selected. + Task SetSelectionAsync(ILspFileRange range); + + /// + /// Insert text into a given file. + /// + /// The absolute URI of the file to insert text into. + /// The text to insert into the file. + /// The range over which to insert the given text. + /// A task that resolves when the text has been inserted. + Task InsertTextAsync(Uri fileUri, string text, ILspFileRange range); + } + + internal class EditorContextService : IEditorContextService + { + private readonly ILanguageServer _languageServer; + + internal EditorContextService( + ILanguageServer languageServer) + { + _languageServer = languageServer; + } + + public async Task GetCurrentLspFileContextAsync() + { + ClientEditorContext clientContext = + await _languageServer.SendRequest( + "editor/getEditorContext", + new GetEditorContextRequest()).ConfigureAwait(false); + + return new LspCurrentFileContext(clientContext); + } + + public Task OpenNewUntitledFileAsync() + { + return _languageServer.SendRequest("editor/newFile", null); + } + + public Task OpenFileAsync(Uri fileUri) => OpenFileAsync(fileUri, preview: false); + + public Task OpenFileAsync(Uri fileUri, bool preview) + { + return _languageServer.SendRequest("editor/openFile", new OpenFileDetails + { + FilePath = fileUri.LocalPath, + Preview = preview, + }); + } + + public Task CloseFileAsync(Uri fileUri) + { + return _languageServer.SendRequest("editor/closeFile", fileUri.LocalPath); + } + + public Task SaveFileAsync(Uri fileUri) => SaveFileAsync(fileUri, null); + + public Task SaveFileAsync(Uri oldFileUri, Uri newFileUri) + { + return _languageServer.SendRequest("editor/saveFile", new SaveFileDetails + { + FilePath = oldFileUri.LocalPath, + NewPath = newFileUri?.LocalPath, + }); + } + + public Task SetSelectionAsync(ILspFileRange range) + { + return _languageServer.SendRequest("editor/setSelection", new SetSelectionRequest + { + SelectionRange = range.ToOmnisharpRange() + }); + } + + public Task InsertTextAsync(Uri fileUri, string text, ILspFileRange range) + { + return _languageServer.SendRequest("editor/insertText", new InsertTextRequest + { + FilePath = fileUri.LocalPath, + InsertText = text, + InsertRange = range.ToOmnisharpRange(), + }); + } + } +} diff --git a/src/PowerShellEditorServices/Extensions/Api/EditorExtensionServiceProvider.cs b/src/PowerShellEditorServices/Extensions/Api/EditorExtensionServiceProvider.cs new file mode 100644 index 000000000..da3cf0629 --- /dev/null +++ b/src/PowerShellEditorServices/Extensions/Api/EditorExtensionServiceProvider.cs @@ -0,0 +1,215 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Linq.Expressions; +using System.Reflection; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.PowerShell.EditorServices.Services; +using Microsoft.PowerShell.EditorServices.Utility; +using OmniSharp.Extensions.LanguageServer.Protocol.Server; + +using Internal = Microsoft.PowerShell.EditorServices.Services; + +namespace Microsoft.PowerShell.EditorServices.Extensions.Services +{ + /// + /// Object to provide extension service APIs to extensions to PSES. + /// + public class EditorExtensionServiceProvider + { + private static readonly Assembly s_psesAsm = typeof(EditorExtensionServiceProvider).Assembly; + + private static readonly Lazy s_psesAsmLoadContextLazy = new Lazy(GetPsesAsmLoadContext); + + private static readonly Lazy s_asmLoadContextType = new Lazy(() => Type.GetType("System.Runtime.Loader.AssemblyLoadContext")); + + private static readonly Lazy> s_enterPsesReflectionContextLazy = new Lazy>(GetPsesAlcReflectionContextEntryFunc); + + private static readonly Lazy> s_loadAssemblyInPsesAlc = new Lazy>(GetPsesAlcLoadAsmFunc); + + private static Type AsmLoadContextType => s_asmLoadContextType.Value; + + private static object PsesAssemblyLoadContext => s_psesAsmLoadContextLazy.Value; + + private static Func EnterPsesAlcReflectionContext => s_enterPsesReflectionContextLazy.Value; + + private static Func LoadAssemblyInPsesAlc => s_loadAssemblyInPsesAlc.Value; + + private readonly IServiceProvider _serviceProvider; + + internal EditorExtensionServiceProvider(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + LanguageServer = new LanguageServerService(_serviceProvider.GetService()); + //DocumentSymbols = new DocumentSymbolService(_serviceProvider.GetService()); + ExtensionCommands = new ExtensionCommandService(_serviceProvider.GetService()); + Workspace = new WorkspaceService(_serviceProvider.GetService()); + EditorContext = new EditorContextService(_serviceProvider.GetService()); + EditorUI = new EditorUIService(_serviceProvider.GetService()); + } + + /// + /// A service wrapper around the language server allowing sending notifications and requests to the LSP client. + /// + public ILanguageServerService LanguageServer { get; } + + /// + /// Service providing document symbol provider registration. + /// + // public IDocumentSymbolService DocumentSymbols { get; } + + /// + /// Service providing extension command registration and functionality. + /// + public IExtensionCommandService ExtensionCommands { get; } + + /// + /// Service providing editor workspace functionality. + /// + public IWorkspaceService Workspace { get; } + + /// + /// Service providing current editor context functionality. + /// + public IEditorContextService EditorContext { get; } + + /// + /// Service providing editor UI functionality. + /// + public IEditorUIService EditorUI { get; } + + /// + /// Get an underlying service object from PSES by type name. + /// + /// The full type name of the service to get. + /// The service object requested, or null if no service of that type name exists. + /// + /// This method is intended as a trapdoor and should not be used in the first instance. + /// Consider using the public extension services if possible. + /// + public object GetService(string psesServiceFullTypeName) => GetService(psesServiceFullTypeName, "Microsoft.PowerShell.EditorServices"); + + /// + /// Get an underlying service object from PSES by type name. + /// + /// The full type name of the service to get. + /// The assembly name from which the service comes. + /// The service object requested, or null if no service of that type name exists. + /// + /// This method is intended as a trapdoor and should not be used in the first instance. + /// Consider using the public extension services if possible. + /// + public object GetService(string fullTypeName, string assemblyName) + { + string asmQualifiedName = $"{fullTypeName}, {assemblyName}"; + return GetServiceByAssemblyQualifiedName(asmQualifiedName); + } + + /// + /// Get a PSES service by its fully assembly qualified name. + /// + /// The fully assembly qualified name of the service type to load. + /// The service corresponding to the given type, or null if none was found. + /// + /// It's not recommended to run this method in parallel with anything, + /// since the global reflection context change may have side effects in other threads. + /// + public object GetServiceByAssemblyQualifiedName(string asmQualifiedTypeName) + { + Type serviceType; + if (VersionUtils.IsNetCore) + { + using (EnterPsesAlcReflectionContext()) + { + serviceType = s_psesAsm.GetType(asmQualifiedTypeName); + } + } + else + { + serviceType = Type.GetType(asmQualifiedTypeName); + } + + return GetService(serviceType); + } + + /// + /// Get an underlying service object from PSES by type name. + /// + /// The type of the service to fetch. + /// The service object requested, or null if no service of that type name exists. + /// + /// This method is intended as a trapdoor and should not be used in the first instance. + /// Consider using the public extension services if possible. + /// + /// Also note that services in PSES may live in a separate assembly load context, + /// meaning that a type of the seemingly correct name may fail to fetch to a service + /// that is known under a type of the same name but loaded in a different context. + /// + public object GetService(Type serviceType) + { + return _serviceProvider.GetService(serviceType); + } + + /// + /// Get the assembly load context the PSES loads its dependencies into. + /// In .NET Framework, this returns null. + /// + /// The assembly load context used for loading PSES, or null in .NET Framework. + public object GetPsesAssemblyLoadContext() + { + if (!VersionUtils.IsNetCore) + { + return null; + } + + return PsesAssemblyLoadContext; + } + + /// + /// Load the given assembly in the PSES assembly load context. + /// In .NET Framework, this simple loads the assembly in the LoadFrom context. + /// + /// The absolute path of the assembly to load. + /// The loaded assembly object. + public Assembly LoadAssemblyInPsesLoadContext(string assemblyPath) + { + if (!VersionUtils.IsNetCore) + { + return Assembly.LoadFrom(assemblyPath); + } + + return LoadAssemblyInPsesAlc(assemblyPath); + } + + private static Func GetPsesAlcReflectionContextEntryFunc() + { + MethodInfo enterReflectionContextMethod = AsmLoadContextType.GetMethod("EnterContextualReflection", BindingFlags.Public | BindingFlags.Instance); + + return Expression.Lambda>( + Expression.Convert( + Expression.Call(Expression.Constant(PsesAssemblyLoadContext), enterReflectionContextMethod), + typeof(IDisposable))).Compile(); + } + + private static Func GetPsesAlcLoadAsmFunc() + { + MethodInfo loadFromAssemblyPathMethod = AsmLoadContextType.GetMethod("LoadFromAssemblyPath", BindingFlags.Public | BindingFlags.Instance); + return (Func)loadFromAssemblyPathMethod.CreateDelegate(typeof(Func), PsesAssemblyLoadContext); + } + + private static object GetPsesAsmLoadContext() + { + if (!VersionUtils.IsNetCore) + { + return null; + } + + Type alcType = Type.GetType("System.Runtime.Loader.AssemblyLoadContext"); + MethodInfo getAlcMethod = alcType.GetMethod("GetLoadContext", BindingFlags.Public | BindingFlags.Static); + return getAlcMethod.Invoke(obj: null, new object[] { s_psesAsm }); + } + } +} diff --git a/src/PowerShellEditorServices/Extensions/Api/EditorUIService.cs b/src/PowerShellEditorServices/Extensions/Api/EditorUIService.cs new file mode 100644 index 000000000..3eaade2a1 --- /dev/null +++ b/src/PowerShellEditorServices/Extensions/Api/EditorUIService.cs @@ -0,0 +1,201 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.PowerShell.EditorServices.Services.PowerShellContext; +using OmniSharp.Extensions.LanguageServer.Protocol.Server; + +namespace Microsoft.PowerShell.EditorServices.Extensions.Services +{ + /// + /// Object specifying a UI prompt option to display to the user. + /// + public sealed class PromptChoiceDetails + { + /// + /// Construct a prompt choice object for display in a prompt to the user. + /// + /// The label to identify this prompt choice. May not contain commas (','). + /// The message to display to users. + public PromptChoiceDetails(string label, string helpMessage) + { + if (label == null) + { + throw new ArgumentNullException(nameof(label)); + } + + // Currently VSCode sends back selected labels as a single string concatenated with ',' + // When this is fixed, we'll be able to allow commas in labels + if (label.Contains(",")) + { + throw new ArgumentException($"Labels may not contain ','. Label: '{label}'", nameof(label)); + } + + Label = label; + HelpMessage = helpMessage; + } + + /// + /// The label to identify this prompt message. + /// + public string Label { get; } + + /// + /// The message to display to users in the UI for this prompt choice. + /// + public string HelpMessage { get; } + } + + /// + /// A service to manipulate the editor user interface. + /// + public interface IEditorUIService + { + /// + /// Prompt input after displaying the given message. + /// + /// The message to display with the prompt. + /// The input entered by the user, or null if the prompt was canceled. + Task PromptInputAsync(string message); + + /// + /// Prompt a single selection from a set of choices. + /// + /// The message to display for the prompt. + /// The choices to give the user. + /// The label of the selected choice, or null if the prompt was canceled. + Task PromptSelectionAsync(string message, IReadOnlyList choices); + + /// + /// Prompt a single selection from a set of choices. + /// + /// The message to display for the prompt. + /// The choices to give the user. + /// The index in the choice list of the default choice. + /// The label of the selected choice, or null if the prompt was canceled. + Task PromptSelectionAsync(string message, IReadOnlyList choices, int defaultChoiceIndex); + + /// + /// Prompt a set of selections from a list of choices. + /// + /// The message to display for the prompt. + /// The choices to give the user. + /// A list of the labels of selected choices, or null if the prompt was canceled. + Task> PromptMultipleSelectionAsync(string message, IReadOnlyList choices); + + /// + /// Prompt a set of selections from a list of choices. + /// + /// The message to display for the prompt. + /// The choices to give the user. + /// A list of the indexes of choices to mark as default. + /// A list of the labels of selected choices, or null if the prompt was canceled. + Task> PromptMultipleSelectionAsync(string message, IReadOnlyList choices, IReadOnlyList defaultChoiceIndexes); + } + + internal class EditorUIService : IEditorUIService + { + private static string[] s_choiceResponseLabelSeparators = new[] { ", " }; + + private readonly ILanguageServer _languageServer; + + public EditorUIService(ILanguageServer languageServer) + { + _languageServer = languageServer; + } + + public async Task PromptInputAsync(string message) + { + // The VSCode client currently doesn't use the Label field, so we ignore it + ShowInputPromptResponse response = await _languageServer.SendRequest( + "powerShell/showInputPrompt", + new ShowInputPromptRequest + { + Name = message, + }); + + if (response.PromptCancelled) + { + return null; + } + + return response.ResponseText; + } + + public Task> PromptMultipleSelectionAsync(string message, IReadOnlyList choices) => + PromptMultipleSelectionAsync(message, choices, defaultChoiceIndexes: null); + + public async Task> PromptMultipleSelectionAsync(string message, IReadOnlyList choices, IReadOnlyList defaultChoiceIndexes) + { + ChoiceDetails[] choiceDetails = GetChoiceDetails(choices); + + ShowChoicePromptResponse response = await _languageServer.SendRequest( + "powerShell/showChoicePrompt", + new ShowChoicePromptRequest + { + IsMultiChoice = true, + Caption = string.Empty, + Message = message, + Choices = choiceDetails, + DefaultChoices = defaultChoiceIndexes?.ToArray(), + }); + + if (response.PromptCancelled) + { + return null; + } + + return response.ResponseText.Split(s_choiceResponseLabelSeparators, StringSplitOptions.None); + } + + public Task PromptSelectionAsync(string message, IReadOnlyList choices) => + PromptSelectionAsync(message, choices, defaultChoiceIndex: -1); + + public async Task PromptSelectionAsync(string message, IReadOnlyList choices, int defaultChoiceIndex) + { + ChoiceDetails[] choiceDetails = GetChoiceDetails(choices); + + ShowChoicePromptResponse response = await _languageServer.SendRequest( + "powerShell/showChoicePrompt", + new ShowChoicePromptRequest + { + IsMultiChoice = false, + Caption = string.Empty, + Message = message, + Choices = choiceDetails, + DefaultChoices = defaultChoiceIndex > -1 ? new[] { defaultChoiceIndex } : null, + }); + + if (response.PromptCancelled) + { + return null; + } + + return response.ResponseText; + } + + private static ChoiceDetails[] GetChoiceDetails(IReadOnlyList promptChoiceDetails) + { + var choices = new ChoiceDetails[promptChoiceDetails.Count]; + for (int i = 0; i < promptChoiceDetails.Count; i++) + { + choices[i] = new ChoiceDetails + { + Label = promptChoiceDetails[i].Label, + HelpMessage = promptChoiceDetails[i].HelpMessage, + // There were intended to enable hotkey use for choice selections, + // but currently VSCode does not do anything with them. + // They can be exposed once VSCode supports them. + HotKeyIndex = -1, + HotKeyCharacter = null, + }; + } + return choices; + } + } +} diff --git a/src/PowerShellEditorServices/Extensions/Api/ExtensionCommandService.cs b/src/PowerShellEditorServices/Extensions/Api/ExtensionCommandService.cs new file mode 100644 index 000000000..eeae9499e --- /dev/null +++ b/src/PowerShellEditorServices/Extensions/Api/ExtensionCommandService.cs @@ -0,0 +1,104 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using Microsoft.PowerShell.EditorServices.Services; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Microsoft.PowerShell.EditorServices.Extensions.Services +{ + /// + /// Service for registration and invocation of extension commands. + /// + public interface IExtensionCommandService + { + /// + /// Invoke an extension command asynchronously. + /// + /// The name of the extension command to invoke. + /// The editor context in which to invoke the command. + /// A task that resolves when the command has been run. + Task InvokeCommandAsync(string commandName, EditorContext editorContext); + + /// + /// Registers a new EditorCommand with the ExtensionService and + /// causes its details to be sent to the host editor. + /// + /// The details about the editor command to be registered. + /// True if the command is newly registered, false if the command already exists. + bool RegisterCommand(EditorCommand editorCommand); + + /// + /// Unregisters an existing EditorCommand based on its registered name. + /// + /// The name of the command to be unregistered. + void UnregisterCommand(string commandName); + + /// + /// Returns all registered EditorCommands. + /// + /// A list of all registered EditorCommands. + IReadOnlyList GetCommands(); + + /// + /// Raised when a new editor command is added. + /// + event EventHandler CommandAdded; + + /// + /// Raised when an existing editor command is updated. + /// + event EventHandler CommandUpdated; + + /// + /// Raised when an existing editor command is removed. + /// + event EventHandler CommandRemoved; + } + + internal class ExtensionCommandService : IExtensionCommandService + { + private readonly ExtensionService _extensionService; + + public ExtensionCommandService(ExtensionService extensionService) + { + _extensionService = extensionService; + + _extensionService.CommandAdded += OnCommandAdded; + _extensionService.CommandUpdated += OnCommandUpdated; + _extensionService.CommandRemoved += OnCommandRemoved; + } + + public event EventHandler CommandAdded; + + public event EventHandler CommandUpdated; + + public event EventHandler CommandRemoved; + + public IReadOnlyList GetCommands() => _extensionService.GetCommands(); + + public Task InvokeCommandAsync(string commandName, EditorContext editorContext) => _extensionService.InvokeCommandAsync(commandName, editorContext); + + public bool RegisterCommand(EditorCommand editorCommand) => _extensionService.RegisterCommand(editorCommand); + + public void UnregisterCommand(string commandName) => _extensionService.UnregisterCommand(commandName); + + private void OnCommandAdded(object sender, EditorCommand editorCommand) + { + CommandAdded?.Invoke(this, editorCommand); + } + + private void OnCommandUpdated(object sender, EditorCommand editorCommand) + { + CommandUpdated?.Invoke(this, editorCommand); + } + + private void OnCommandRemoved(object sender, EditorCommand editorCommand) + { + CommandRemoved?.Invoke(this, editorCommand); + } + } +} diff --git a/src/PowerShellEditorServices/Extensions/Api/LanguageServerService.cs b/src/PowerShellEditorServices/Extensions/Api/LanguageServerService.cs new file mode 100644 index 000000000..a50b600ad --- /dev/null +++ b/src/PowerShellEditorServices/Extensions/Api/LanguageServerService.cs @@ -0,0 +1,115 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using MediatR; +using OmniSharp.Extensions.LanguageServer.Protocol.Server; +using System.Threading.Tasks; + +namespace Microsoft.PowerShell.EditorServices.Extensions.Services +{ + /// + /// Service allowing the sending of notifications and requests to the PowerShell LSP language client from the server. + /// + public interface ILanguageServerService + { + /// + /// Send a parameterless notification. + /// + /// The method to send. + void SendNotification(string method); + + /// + /// Send a notification with parameters. + /// + /// The type of the parameter object. + /// The method to send. + /// The parameters to send. + void SendNotification(string method, T parameters); + + /// + /// Send a parameterless request with no response output. + /// + /// The method to send. + /// A task that resolves when the request is acknowledged. + Task SendRequestAsync(string method); + + /// + /// Send a request with no response output. + /// + /// The type of the request parameter object. + /// The method to send. + /// The request parameter object/body. + /// A task that resolves when the request is acknowledged. + Task SendRequestAsync(string method, T parameters); + + /// + /// Send a parameterless request and get its response. + /// + /// The type of the response expected. + /// The method to send. + /// A task that resolves to the response sent by the server. + Task SendRequestAsync(string method); + + /// + /// Send a request and get its response. + /// + /// The type of the parameter object. + /// The type of the response expected. + /// The method to send. + /// The parameters to send. + /// A task that resolves to the response sent by the server. + Task SendRequestAsync(string method, T parameters); + } + + internal class LanguageServerService : ILanguageServerService + { + private readonly ILanguageServer _languageServer; + + internal LanguageServerService(ILanguageServer languageServer) + { + _languageServer = languageServer; + } + + public void SendNotification(string method) + { + _languageServer.SendNotification(method); + } + + public void SendNotification(string method, T parameters) + { + _languageServer.SendNotification(method, parameters); + } + + public void SendNotification(string method, object parameters) + { + _languageServer.SendNotification(method, parameters); + } + + public Task SendRequestAsync(string method) + { + return _languageServer.SendRequest(method); + } + + public Task SendRequestAsync(string method, T parameters) + { + return _languageServer.SendRequest(method, parameters); + } + + public Task SendRequestAsync(string method) + { + return _languageServer.SendRequest(method); + } + + public Task SendRequestAsync(string method, T parameters) + { + return _languageServer.SendRequest(method, parameters); + } + + public Task SendRequestAsync(string method, object parameters) + { + return _languageServer.SendRequest(method, parameters); + } + } +} diff --git a/src/PowerShellEditorServices/Extensions/Api/WorkspaceService.cs b/src/PowerShellEditorServices/Extensions/Api/WorkspaceService.cs new file mode 100644 index 000000000..3cb5635b5 --- /dev/null +++ b/src/PowerShellEditorServices/Extensions/Api/WorkspaceService.cs @@ -0,0 +1,157 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using Microsoft.PowerShell.EditorServices.Services.TextDocument; +using System; +using System.Collections.Generic; +using System.Management.Automation.Language; +using System.Threading.Tasks; + +namespace Microsoft.PowerShell.EditorServices.Extensions.Services +{ + /// + /// A script file in the current editor workspace. + /// + public interface IEditorScriptFile + { + /// + /// The URI of the script file. + /// + Uri Uri { get; } + + /// + /// The text content of the file. + /// + string Content { get; } + + /// + /// The lines of the file. + /// + IReadOnlyList Lines { get; } + + /// + /// The PowerShell AST of the script in the file. + /// + ScriptBlockAst Ast { get; } + + /// + /// The PowerShell syntactic tokens of the script in the file. + /// + IReadOnlyList Tokens { get; } + } + + /// + /// A service for querying and manipulating the editor workspace. + /// + public interface IWorkspaceService + { + /// + /// The root path of the workspace. + /// + string WorkspacePath { get; } + + /// + /// Indicates whether the editor is configured to follow symlinks. + /// + bool FollowSymlinks { get; } + + /// + /// The list of file globs to exclude from workspace management. + /// + IReadOnlyList ExcludedFileGlobs { get; } + + /// + /// Get a file within the workspace. + /// + /// The absolute URI of the file to get. + /// A representation of the file. + IEditorScriptFile GetFile(Uri fileUri); + + /// + /// Attempt to get a file within the workspace. + /// + /// The absolute URI of the file to get. + /// The file, if it was found. + /// True if the file was found, false otherwise. + bool TryGetFile(Uri fileUri, out IEditorScriptFile file); + + /// + /// Get all the open files in the editor workspace. + /// The result is not kept up to date as files are opened or closed. + /// + /// All open files in the editor workspace. + IReadOnlyList GetOpenedFiles(); + } + + internal class EditorScriptFile : IEditorScriptFile + { + private readonly ScriptFile _scriptFile; + + internal EditorScriptFile( + ScriptFile scriptFile) + { + _scriptFile = scriptFile; + Uri = new Uri(scriptFile.DocumentUri); + Lines = _scriptFile.FileLines.AsReadOnly(); + } + + public Uri Uri { get; } + + public IReadOnlyList Lines { get; } + + public string Content => _scriptFile.Contents; + + public ScriptBlockAst Ast => _scriptFile.ScriptAst; + + public IReadOnlyList Tokens => _scriptFile.ScriptTokens; + } + + internal class WorkspaceService : IWorkspaceService + { + private readonly EditorServices.Services.WorkspaceService _workspaceService; + + internal WorkspaceService( + EditorServices.Services.WorkspaceService workspaceService) + { + _workspaceService = workspaceService; + ExcludedFileGlobs = _workspaceService.ExcludeFilesGlob.AsReadOnly(); + } + + public string WorkspacePath => _workspaceService.WorkspacePath; + + public bool FollowSymlinks => _workspaceService.FollowSymlinks; + + public IReadOnlyList ExcludedFileGlobs { get; } + + public IEditorScriptFile GetFile(Uri fileUri) => GetEditorFileFromScriptFile(_workspaceService.GetFile(fileUri)); + + public bool TryGetFile(Uri fileUri, out IEditorScriptFile file) + { + if (!_workspaceService.TryGetFile(fileUri.LocalPath, out ScriptFile scriptFile)) + { + file = null; + return false; + } + + file = GetEditorFileFromScriptFile(scriptFile); + return true; + } + + public IReadOnlyList GetOpenedFiles() + { + var files = new List(); + foreach (ScriptFile openedFile in _workspaceService.GetOpenedFiles()) + { + files.Add(GetEditorFileFromScriptFile(openedFile)); + } + return files.AsReadOnly(); + } + + private IEditorScriptFile GetEditorFileFromScriptFile(ScriptFile file) + { + return new EditorScriptFile(file); + } + } +} diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorCommand.cs b/src/PowerShellEditorServices/Extensions/EditorCommand.cs similarity index 96% rename from src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorCommand.cs rename to src/PowerShellEditorServices/Extensions/EditorCommand.cs index 7f24d04a2..c9e212b9c 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorCommand.cs +++ b/src/PowerShellEditorServices/Extensions/EditorCommand.cs @@ -5,13 +5,13 @@ using System.Management.Automation; -namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext +namespace Microsoft.PowerShell.EditorServices.Extensions { /// /// Provides details about a command that has been registered /// with the editor. /// - public class EditorCommand + public sealed class EditorCommand { #region Properties diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorCommandAttribute.cs b/src/PowerShellEditorServices/Extensions/EditorCommandAttribute.cs similarity index 86% rename from src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorCommandAttribute.cs rename to src/PowerShellEditorServices/Extensions/EditorCommandAttribute.cs index 59aa71df3..49984cb21 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorCommandAttribute.cs +++ b/src/PowerShellEditorServices/Extensions/EditorCommandAttribute.cs @@ -1,13 +1,13 @@ using System; -namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext +namespace Microsoft.PowerShell.EditorServices.Extensions { /// /// Provides an attribute that can be used to target PowerShell /// commands for import as editor commands. /// [AttributeUsage(AttributeTargets.Class)] - public class EditorCommandAttribute : Attribute + public sealed class EditorCommandAttribute : Attribute { #region Properties diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorContext.cs b/src/PowerShellEditorServices/Extensions/EditorContext.cs similarity index 81% rename from src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorContext.cs rename to src/PowerShellEditorServices/Extensions/EditorContext.cs index 144c7db53..cc7398d3e 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorContext.cs +++ b/src/PowerShellEditorServices/Extensions/EditorContext.cs @@ -4,16 +4,14 @@ // using System; -using System.Linq; -using System.Management.Automation.Language; using Microsoft.PowerShell.EditorServices.Services.TextDocument; -namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext +namespace Microsoft.PowerShell.EditorServices.Extensions { /// /// Provides context for the host editor at the time of creation. /// - public class EditorContext + public sealed class EditorContext { #region Private Fields @@ -31,12 +29,12 @@ public class EditorContext /// /// Gets the BufferRange representing the current selection in the file. /// - public BufferRange SelectedRange { get; private set; } + public IFileRange SelectedRange { get; private set; } /// /// Gets the FilePosition representing the current cursor position. /// - public FilePosition CursorPosition { get; private set; } + public IFilePosition CursorPosition { get; private set; } #endregion @@ -50,7 +48,7 @@ public class EditorContext /// The position of the user's cursor in the active editor buffer. /// The range of the user's selection in the active editor buffer. /// Determines the language of the file.false If it is not specified, then it defaults to "Unknown" - public EditorContext( + internal EditorContext( IEditorOperations editorOperations, ScriptFile currentFile, BufferPosition cursorPosition, @@ -59,8 +57,8 @@ public EditorContext( { this.editorOperations = editorOperations; this.CurrentFile = new FileContext(currentFile, this, editorOperations, language); - this.SelectedRange = selectedRange; - this.CursorPosition = new FilePosition(currentFile, cursorPosition); + this.SelectedRange = new BufferFileRange(selectedRange); + this.CursorPosition = new BufferFilePosition(cursorPosition); } #endregion @@ -81,9 +79,9 @@ public void SetSelection( int endColumn) { this.SetSelection( - new BufferRange( - startLine, startColumn, - endLine, endColumn)); + new FileRange( + new FilePosition(startLine, startColumn), + new FilePosition(endLine, endColumn))); } /// @@ -92,11 +90,11 @@ public void SetSelection( /// The starting position of the selection. /// The ending position of the selection. public void SetSelection( - BufferPosition startPosition, - BufferPosition endPosition) + FilePosition startPosition, + FilePosition endPosition) { this.SetSelection( - new BufferRange( + new FileRange( startPosition, endPosition)); } @@ -105,10 +103,10 @@ public void SetSelection( /// Sets a selection in the host editor's active buffer. /// /// The range of the selection. - public void SetSelection(BufferRange selectionRange) + public void SetSelection(FileRange selectionRange) { this.editorOperations - .SetSelectionAsync(selectionRange) + .SetSelectionAsync(selectionRange.ToBufferRange()) .Wait(); } diff --git a/src/PowerShellEditorServices/Extensions/EditorFileRanges.cs b/src/PowerShellEditorServices/Extensions/EditorFileRanges.cs new file mode 100644 index 000000000..9db857986 --- /dev/null +++ b/src/PowerShellEditorServices/Extensions/EditorFileRanges.cs @@ -0,0 +1,371 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using Microsoft.PowerShell.EditorServices.Handlers; +using Microsoft.PowerShell.EditorServices.Services.TextDocument; +using OmniSharp.Extensions.LanguageServer.Protocol.Models; +using System; + +namespace Microsoft.PowerShell.EditorServices.Extensions +{ + /// + /// A 1-based file position, referring to a point in a file. + /// + public interface IFilePosition + { + /// + /// The line number of the file position. + /// + int Line { get; } + + /// + /// The column number of the file position. + /// + int Column { get; } + } + + /// + /// A 1-based file range, referring to a range within a file. + /// + public interface IFileRange + { + /// + /// The start position of the range. + /// + IFilePosition Start { get; } + + /// + /// The end position of the range. + /// + IFilePosition End { get; } + } + + /// + /// A snapshot of a file, including the URI of the file + /// and its textual contents when accessed. + /// + public interface IFileContext + { + /// + /// The URI of the file. + /// + Uri Uri { get; } + + /// + /// The content of the file when it was accessed. + /// + string Content { get; } + } + + /// + /// 0-based position within a file, conformant with the Language Server Protocol. + /// + public interface ILspFilePosition + { + /// + /// The line index of the position within the file. + /// + long Line { get; } + + /// + /// The character offset from the line of the position. + /// + long Character { get; } + } + + /// + /// 0-based range within a file, conformant with the Language Server Protocol. + /// + public interface ILspFileRange + { + /// + /// The start position of the range. + /// + ILspFilePosition Start { get; } + + /// + /// The end position of the range. + /// + ILspFilePosition End { get; } + } + + /// + /// Snapshot of a file in focus in the editor. + /// + public interface ILspCurrentFileContext : IFileContext + { + /// + /// The language the editor associates with this file. + /// + string Language { get; } + + /// + /// The position of the cursor within the file when it was accessed. + /// If the cursor is not in the file, values may be negative. + /// + ILspFilePosition CursorPosition { get; } + + /// + /// The currently selected range when the file was accessed. + /// If no selection is made, values may be negative. + /// + ILspFileRange SelectionRange { get; } + } + + internal struct OmnisharpLspPosition : ILspFilePosition, IEquatable + { + private readonly Position _position; + + public OmnisharpLspPosition(Position position) + { + _position = position; + } + + public long Line => _position.Line; + + public long Character => _position.Character; + + public bool Equals(OmnisharpLspPosition other) + { + return _position == other._position; + } + } + + internal struct OmnisharpLspRange : ILspFileRange, IEquatable + { + private readonly Range _range; + + public OmnisharpLspRange(Range range) + { + _range = range; + } + + public ILspFilePosition Start => new OmnisharpLspPosition(_range.Start); + + public ILspFilePosition End => new OmnisharpLspPosition(_range.End); + + public bool Equals(OmnisharpLspRange other) + { + return _range == other._range; + } + } + + internal struct BufferFilePosition : IFilePosition, IEquatable + { + private readonly BufferPosition _position; + + public BufferFilePosition(BufferPosition position) + { + _position = position; + } + + public int Line => _position.Line; + + public int Column => _position.Column; + + public bool Equals(BufferFilePosition other) + { + return _position == other._position + || _position.Equals(other._position); + } + } + + internal struct BufferFileRange : IFileRange, IEquatable + { + private readonly BufferRange _range; + + public BufferFileRange(BufferRange range) + { + _range = range; + } + + public IFilePosition Start => new BufferFilePosition(_range.Start); + + public IFilePosition End => new BufferFilePosition(_range.End); + + public bool Equals(BufferFileRange other) + { + return _range == other._range + || _range.Equals(other._range); + } + } + + /// + /// A 1-based file position. + /// + public class FilePosition : IFilePosition + { + public FilePosition(int line, int column) + { + Line = line; + Column = column; + } + + public int Line { get; } + + public int Column { get; } + } + + /// + /// A 0-based file position. + /// + public class LspFilePosition : ILspFilePosition + { + public LspFilePosition(long line, long column) + { + Line = line; + Character = column; + } + + public long Line { get; } + + public long Character { get; } + } + + /// + /// A 1-based file range. + /// + public class FileRange : IFileRange + { + public FileRange(IFilePosition start, IFilePosition end) + : this(start, end, file: null) + { + } + + public FileRange(IFilePosition start, IFilePosition end, string file) + { + Start = start; + End = end; + File = file; + } + + public IFilePosition Start { get; } + + public IFilePosition End { get; } + + public string File { get; } + } + + /// + /// A 0-based file range. + /// + public class LspFileRange : ILspFileRange + { + public LspFileRange(ILspFilePosition start, ILspFilePosition end) + { + Start = start; + End = end; + } + + public ILspFilePosition Start { get; } + + public ILspFilePosition End { get; } + } + + internal class LspCurrentFileContext : ILspCurrentFileContext + { + private readonly ClientEditorContext _editorContext; + + public LspCurrentFileContext(ClientEditorContext editorContext) + { + _editorContext = editorContext; + Uri = new Uri(editorContext.CurrentFilePath); + } + + public string Language => _editorContext.CurrentFileLanguage; + + public ILspFilePosition CursorPosition => new OmnisharpLspPosition(_editorContext.CursorPosition); + + public ILspFileRange SelectionRange => new OmnisharpLspRange(_editorContext.SelectionRange); + + public Uri Uri { get; } + + public string Content => _editorContext.CurrentFileContent; + } + + /// + /// Extension methods to conveniently convert between file position and range types. + /// + public static class FileObjectExtensionMethods + { + + /// + /// Convert a 1-based file position to a 0-based file position. + /// + /// The 1-based file position to convert. + /// An equivalent 0-based file position. + public static ILspFilePosition ToLspPosition(this IFilePosition position) + { + return new LspFilePosition(position.Line - 1, position.Column - 1); + } + + /// + /// Convert a 1-based file range to a 0-based file range. + /// + /// The 1-based file range to convert. + /// An equivalent 0-based file range. + public static ILspFileRange ToLspRange(this IFileRange range) + { + return new LspFileRange(range.Start.ToLspPosition(), range.End.ToLspPosition()); + } + + /// + /// Convert a 0-based file position to a 1-based file position. + /// + /// The 0-based file position to convert. + /// An equivalent 1-based file position. + public static IFilePosition ToFilePosition(this ILspFilePosition position) + { + return new FilePosition((int)position.Line + 1, (int)position.Character + 1); + } + + /// + /// Convert a 0-based file range to a 1-based file range. + /// + /// The 0-based file range to convert. + /// An equivalent 1-based file range. + public static IFileRange ToFileRange(this ILspFileRange range) + { + return new FileRange(range.Start.ToFilePosition(), range.End.ToFilePosition()); + } + + internal static bool HasRange(this IFileRange range) + { + return range.Start.Line != 0 + && range.Start.Column != 0 + && range.End.Line != 0 + && range.End.Column != 0; + } + internal static ILspFilePosition ToLspPosition(this Position position) + { + return new OmnisharpLspPosition(position); + } + + internal static ILspFileRange ToLspRange(this Range range) + { + return new OmnisharpLspRange(range); + } + + internal static Position ToOmnisharpPosition(this ILspFilePosition position) + { + return new Position(position.Line, position.Character); + } + + internal static Range ToOmnisharpRange(this ILspFileRange range) + { + return new Range(range.Start.ToOmnisharpPosition(), range.End.ToOmnisharpPosition()); + } + + internal static BufferPosition ToBufferPosition(this IFilePosition position) + { + return new BufferPosition(position.Line, position.Column); + } + + internal static BufferRange ToBufferRange(this IFileRange range) + { + return new BufferRange(range.Start.ToBufferPosition(), range.End.ToBufferPosition()); + } + } +} diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorObject.cs b/src/PowerShellEditorServices/Extensions/EditorObject.cs similarity index 65% rename from src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorObject.cs rename to src/PowerShellEditorServices/Extensions/EditorObject.cs index e873cbe0d..56072e2db 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorObject.cs +++ b/src/PowerShellEditorServices/Extensions/EditorObject.cs @@ -5,25 +5,59 @@ using System; using System.Reflection; +using System.Threading.Tasks; +using Microsoft.PowerShell.EditorServices.Extensions.Services; +using Microsoft.PowerShell.EditorServices.Services; -namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext +namespace Microsoft.PowerShell.EditorServices.Extensions { + /// + /// Extension class to access the editor API with. + /// This is done so that the async/ALC APIs aren't exposed to PowerShell, where they're likely only to cause problems. + /// + public static class EditorObjectExtensions + { + /// + /// Get the provider of extension services for .NET extension tooling. + /// + /// The editor object ($psEditor). + /// The extension services provider. + public static EditorExtensionServiceProvider GetExtensionServiceProvider(this EditorObject editorObject) + { + return editorObject.Api; + } + } + /// /// Provides the entry point of the extensibility API, inserted into /// the PowerShell session as the "$psEditor" variable. /// public class EditorObject { + private static readonly TaskCompletionSource s_editorObjectReady = new TaskCompletionSource(); + + /// + /// A reference to the editor object instance. Only valid when completes. + /// + public static EditorObject Instance { get; private set; } + + /// + /// A task that completes when the editor object static instance has been set. + /// + public static Task EditorObjectReady => s_editorObjectReady.Task; + #region Private Fields - private readonly IServiceProvider _serviceProvider; private readonly ExtensionService _extensionService; private readonly IEditorOperations _editorOperations; + private readonly Lazy _apiLazy; #endregion #region Properties + internal EditorExtensionServiceProvider Api => _apiLazy.Value; + /// /// Gets the version of PowerShell Editor Services. /// @@ -42,11 +76,6 @@ public Version EditorServicesVersion /// public EditorWindow Window { get; private set; } - /// - /// Gets the components that are registered. - /// - public IServiceProvider Components => _serviceProvider; - #endregion /// @@ -54,18 +83,20 @@ public Version EditorServicesVersion /// /// An ExtensionService which handles command registration. /// An IEditorOperations implementation which handles operations in the host editor. - public EditorObject( + internal EditorObject( IServiceProvider serviceProvider, ExtensionService extensionService, IEditorOperations editorOperations) { - this._serviceProvider = serviceProvider; this._extensionService = extensionService; this._editorOperations = editorOperations; // Create API area objects this.Workspace = new EditorWorkspace(this._editorOperations); this.Window = new EditorWindow(this._editorOperations); + + // Create this lazily so that dependency injection does not have a circular call dependency + _apiLazy = new Lazy(() => new EditorExtensionServiceProvider(serviceProvider)); } /// @@ -105,13 +136,10 @@ public EditorContext GetEditorContext() return this._editorOperations.GetEditorContextAsync().Result; } - /// - /// Get's the desired service which allows for advanced control of PowerShellEditorServices. - /// - /// The singleton service object of the type requested. - public object GetService(Type type) + internal void SetAsStaticInstance() { - return _serviceProvider.GetService(type); + EditorObject.Instance = this; + s_editorObjectReady.SetResult(true); } } } diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorRequests.cs b/src/PowerShellEditorServices/Extensions/EditorRequests.cs similarity index 66% rename from src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorRequests.cs rename to src/PowerShellEditorServices/Extensions/EditorRequests.cs index bd639f249..e9d87d573 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorRequests.cs +++ b/src/PowerShellEditorServices/Extensions/EditorRequests.cs @@ -5,36 +5,36 @@ using OmniSharp.Extensions.LanguageServer.Protocol.Models; -namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext +namespace Microsoft.PowerShell.EditorServices.Extensions { - public class ExtensionCommandAddedNotification + internal class ExtensionCommandAddedNotification { public string Name { get; set; } public string DisplayName { get; set; } } - public class ExtensionCommandUpdatedNotification + internal class ExtensionCommandUpdatedNotification { public string Name { get; set; } } - public class ExtensionCommandRemovedNotification + internal class ExtensionCommandRemovedNotification { public string Name { get; set; } } - public class GetEditorContextRequest + internal class GetEditorContextRequest {} - public enum EditorCommandResponse + internal enum EditorCommandResponse { Unsupported, OK } - public class InsertTextRequest + internal class InsertTextRequest { public string FilePath { get; set; } @@ -43,34 +43,35 @@ public class InsertTextRequest public Range InsertRange { get; set; } } - public class SetSelectionRequest + internal class SetSelectionRequest { public Range SelectionRange { get; set; } } - public class SetCursorPositionRequest + internal class SetCursorPositionRequest { public Position CursorPosition { get; set; } } - public class OpenFileDetails + internal class OpenFileDetails { public string FilePath { get; set; } public bool Preview { get; set; } } - public class SaveFileDetails + internal class SaveFileDetails { public string FilePath { get; set; } public string NewPath { get; set; } } - public class StatusBarMessageDetails + internal class StatusBarMessageDetails { public string Message { get; set; } public int? Timeout { get; set; } } } + diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorTerminal.cs b/src/PowerShellEditorServices/Extensions/EditorTerminal.cs similarity index 94% rename from src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorTerminal.cs rename to src/PowerShellEditorServices/Extensions/EditorTerminal.cs index a6fb52ed2..f090e4bd4 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorTerminal.cs +++ b/src/PowerShellEditorServices/Extensions/EditorTerminal.cs @@ -3,7 +3,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext +namespace Microsoft.PowerShell.EditorServices.Extensions { /// /// Provides a PowerShell-facing API which allows scripts to diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorWindow.cs b/src/PowerShellEditorServices/Extensions/EditorWindow.cs similarity index 96% rename from src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorWindow.cs rename to src/PowerShellEditorServices/Extensions/EditorWindow.cs index cf580b961..04c9e3b31 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorWindow.cs +++ b/src/PowerShellEditorServices/Extensions/EditorWindow.cs @@ -3,13 +3,13 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext +namespace Microsoft.PowerShell.EditorServices.Extensions { /// /// Provides a PowerShell-facing API which allows scripts to /// interact with the editor's window. /// - public class EditorWindow + public sealed class EditorWindow { #region Private Fields diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorWorkspace.cs b/src/PowerShellEditorServices/Extensions/EditorWorkspace.cs similarity index 94% rename from src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorWorkspace.cs rename to src/PowerShellEditorServices/Extensions/EditorWorkspace.cs index 974d166e7..b0532a307 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/EditorWorkspace.cs +++ b/src/PowerShellEditorServices/Extensions/EditorWorkspace.cs @@ -3,13 +3,15 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext +using System.Threading.Tasks; + +namespace Microsoft.PowerShell.EditorServices.Extensions { /// /// Provides a PowerShell-facing API which allows scripts to /// interact with the editor's workspace. /// - public class EditorWorkspace + public sealed class EditorWorkspace { #region Private Fields diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/FileContext.cs b/src/PowerShellEditorServices/Extensions/FileContext.cs similarity index 85% rename from src/PowerShellEditorServices/Services/PowerShellContext/Extensions/FileContext.cs rename to src/PowerShellEditorServices/Extensions/FileContext.cs index 43023de24..1276726ea 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/FileContext.cs +++ b/src/PowerShellEditorServices/Extensions/FileContext.cs @@ -4,22 +4,23 @@ // using System; +using System.Collections.Generic; using System.IO; using System.Management.Automation.Language; using Microsoft.PowerShell.EditorServices.Services.TextDocument; -namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext +namespace Microsoft.PowerShell.EditorServices.Extensions { /// /// Provides context for a file that is open in the editor. /// - public class FileContext + public sealed class FileContext { #region Private Fields - internal ScriptFile scriptFile; - private EditorContext editorContext; - private IEditorOperations editorOperations; + private readonly ScriptFile scriptFile; + private readonly EditorContext editorContext; + private readonly IEditorOperations editorOperations; #endregion @@ -28,19 +29,13 @@ public class FileContext /// /// Gets the parsed abstract syntax tree for the file. /// - public Ast Ast - { - get { return this.scriptFile.ScriptAst; } - } + public Ast Ast => this.scriptFile.ScriptAst; /// /// Gets a BufferRange which represents the entire content /// range of the file. /// - public BufferRange FileRange - { - get { return this.scriptFile.FileRange; } - } + public IFileRange FileRange => new BufferFileRange(this.scriptFile.FileRange); /// /// Gets the language of the file. @@ -50,18 +45,17 @@ public BufferRange FileRange /// /// Gets the filesystem path of the file. /// - public string Path - { - get { return this.scriptFile.FilePath; } - } + public string Path => this.scriptFile.FilePath; + + /// + /// Gets the URI of the file. + /// + public Uri Uri { get; } /// /// Gets the parsed token list for the file. /// - public Token[] Tokens - { - get { return this.scriptFile.ScriptTokens; } - } + public IReadOnlyList Tokens => this.scriptFile.ScriptTokens; /// /// Gets the workspace-relative path of the file. @@ -87,7 +81,7 @@ public string WorkspacePath /// The EditorContext to which this file relates. /// An IEditorOperations implementation which performs operations in the editor. /// Determines the language of the file.false If it is not specified, then it defaults to "Unknown" - public FileContext( + internal FileContext( ScriptFile scriptFile, EditorContext editorContext, IEditorOperations editorOperations, @@ -102,6 +96,7 @@ public FileContext( this.editorContext = editorContext; this.editorOperations = editorOperations; this.Language = language; + this.Uri = new Uri(scriptFile.DocumentUri); } #endregion @@ -122,7 +117,7 @@ public string GetText() /// /// The buffer range for which content will be extracted. /// A string with the specified range of content. - public string GetText(BufferRange bufferRange) + public string GetText(FileRange bufferRange) { return string.Join( @@ -144,9 +139,9 @@ public string[] GetTextLines() /// /// The buffer range for which content will be extracted. /// An array of strings, each representing a line in the file within the specified range. - public string[] GetTextLines(BufferRange bufferRange) + public string[] GetTextLines(FileRange fileRange) { - return this.scriptFile.GetLinesInRange(bufferRange); + return this.scriptFile.GetLinesInRange(fileRange.ToBufferRange()); } #endregion @@ -161,7 +156,7 @@ public string[] GetTextLines(BufferRange bufferRange) public void InsertText(string textToInsert) { // Is there a selection? - if (this.editorContext.SelectedRange.HasRange) + if (this.editorContext.SelectedRange.HasRange()) { this.InsertText( textToInsert, @@ -180,11 +175,11 @@ public void InsertText(string textToInsert) /// /// The text string to insert. /// The position at which the text will be inserted. - public void InsertText(string textToInsert, BufferPosition insertPosition) + public void InsertText(string textToInsert, IFilePosition insertPosition) { this.InsertText( textToInsert, - new BufferRange(insertPosition, insertPosition)); + new FileRange(insertPosition, insertPosition)); } /// @@ -197,7 +192,7 @@ public void InsertText(string textToInsert, int insertLine, int insertColumn) { this.InsertText( textToInsert, - new BufferPosition(insertLine, insertColumn)); + new FilePosition(insertLine, insertColumn)); } /// @@ -220,11 +215,9 @@ public void InsertText( { this.InsertText( textToInsert, - new BufferRange( - startLine, - startColumn, - endLine, - endColumn)); + new FileRange( + new FilePosition(startLine, startColumn), + new FilePosition(endLine, endColumn))); } /// @@ -234,10 +227,10 @@ public void InsertText( /// /// The text string to insert. /// The buffer range which will be replaced by the string. - public void InsertText(string textToInsert, BufferRange insertRange) + public void InsertText(string textToInsert, IFileRange insertRange) { this.editorOperations - .InsertTextAsync(this.scriptFile.ClientFilePath, textToInsert, insertRange) + .InsertTextAsync(this.scriptFile.ClientFilePath, textToInsert, insertRange.ToBufferRange()) .Wait(); } diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/IEditorOperations.cs b/src/PowerShellEditorServices/Extensions/IEditorOperations.cs similarity index 98% rename from src/PowerShellEditorServices/Services/PowerShellContext/Extensions/IEditorOperations.cs rename to src/PowerShellEditorServices/Extensions/IEditorOperations.cs index ccc41e949..90ce720c9 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Extensions/IEditorOperations.cs +++ b/src/PowerShellEditorServices/Extensions/IEditorOperations.cs @@ -6,14 +6,14 @@ using System.Threading.Tasks; using Microsoft.PowerShell.EditorServices.Services.TextDocument; -namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext +namespace Microsoft.PowerShell.EditorServices.Extensions { /// /// Provides an interface that must be implemented by an editor /// host to perform operations invoked by extensions written in /// PowerShell. /// - public interface IEditorOperations + internal interface IEditorOperations { /// /// Gets the EditorContext for the editor's current state. diff --git a/src/PowerShellEditorServices/Hosting/EditorServicesServerFactory.cs b/src/PowerShellEditorServices/Hosting/EditorServicesServerFactory.cs index 19886ce9e..472d1157e 100644 --- a/src/PowerShellEditorServices/Hosting/EditorServicesServerFactory.cs +++ b/src/PowerShellEditorServices/Hosting/EditorServicesServerFactory.cs @@ -3,17 +3,17 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.Extensions.Logging; -using Microsoft.PowerShell.EditorServices.Server; -using PowerShellEditorServices.Logging; -using Serilog; -using Serilog.Events; using System; using System.Diagnostics; using System.IO; using Microsoft.Extensions.DependencyInjection; -using OmniSharp.Extensions.LanguageServer.Server; +using Microsoft.Extensions.Logging; +using Microsoft.PowerShell.EditorServices.Logging; +using Microsoft.PowerShell.EditorServices.Server; using Microsoft.PowerShell.EditorServices.Services; +using Serilog; +using Serilog.Events; +using OmniSharp.Extensions.LanguageServer.Server; #if DEBUG using Serilog.Debugging; @@ -58,7 +58,7 @@ public static EditorServicesServerFactory Create(string logPath, int minimumLogL private readonly ILoggerFactory _loggerFactory; - private readonly Extensions.Logging.ILogger _logger; + private readonly Microsoft.Extensions.Logging.ILogger _logger; private readonly LogLevel _minimumLogLevel; diff --git a/src/PowerShellEditorServices/Hosting/HostStartupInfo.cs b/src/PowerShellEditorServices/Hosting/HostStartupInfo.cs index a83ff2850..b6ff618a3 100644 --- a/src/PowerShellEditorServices/Hosting/HostStartupInfo.cs +++ b/src/PowerShellEditorServices/Hosting/HostStartupInfo.cs @@ -13,7 +13,7 @@ namespace Microsoft.PowerShell.EditorServices.Hosting /// Contains details about the host as well as any other information /// needed by Editor Services at startup time. /// - public class HostStartupInfo + public sealed class HostStartupInfo { #region Constants @@ -150,7 +150,7 @@ public HostStartupInfo( #endregion } - public class ProfilePathInfo + public sealed class ProfilePathInfo { public ProfilePathInfo( string currentUserAllHosts, diff --git a/src/PowerShellEditorServices/Logging/HostLoggerAdapter.cs b/src/PowerShellEditorServices/Logging/HostLoggerAdapter.cs index 6b65e5d9a..c8c289d61 100644 --- a/src/PowerShellEditorServices/Logging/HostLoggerAdapter.cs +++ b/src/PowerShellEditorServices/Logging/HostLoggerAdapter.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Text; -namespace PowerShellEditorServices.Logging +namespace Microsoft.PowerShell.EditorServices.Logging { /// /// Adapter class to allow logging events sent by the host to be recorded by PSES' logging infrastructure. diff --git a/src/PowerShellEditorServices/PowerShellEditorServices.csproj b/src/PowerShellEditorServices/PowerShellEditorServices.csproj index 7ba95880a..7861f3692 100644 --- a/src/PowerShellEditorServices/PowerShellEditorServices.csproj +++ b/src/PowerShellEditorServices/PowerShellEditorServices.csproj @@ -27,6 +27,9 @@ <_Parameter1>Microsoft.PowerShell.EditorServices.Test + + <_Parameter1>PowerShellEditorServices.Test.E2E + <_Parameter1>Microsoft.PowerShell.EditorServices.Test.Shared @@ -48,4 +51,8 @@ + + + + diff --git a/src/PowerShellEditorServices/Services/CodeLens/ICodeLensProvider.cs b/src/PowerShellEditorServices/Services/CodeLens/ICodeLensProvider.cs index f42525a19..df2f2d9e0 100644 --- a/src/PowerShellEditorServices/Services/CodeLens/ICodeLensProvider.cs +++ b/src/PowerShellEditorServices/Services/CodeLens/ICodeLensProvider.cs @@ -11,7 +11,7 @@ namespace Microsoft.PowerShell.EditorServices.CodeLenses /// /// Specifies the contract for a Code Lens provider. /// - public interface ICodeLensProvider + internal interface ICodeLensProvider { /// /// Specifies a unique identifier for the feature provider, typically a diff --git a/src/PowerShellEditorServices/Services/CodeLens/ICodeLenses.cs b/src/PowerShellEditorServices/Services/CodeLens/ICodeLenses.cs deleted file mode 100644 index fd6e1eadf..000000000 --- a/src/PowerShellEditorServices/Services/CodeLens/ICodeLenses.cs +++ /dev/null @@ -1,34 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -using System.Collections.Generic; -using Microsoft.PowerShell.EditorServices.Services.TextDocument; -using OmniSharp.Extensions.LanguageServer.Protocol.Models; - -namespace Microsoft.PowerShell.EditorServices.CodeLenses -{ - /// - /// Specifies the contract for an implementation of - /// the ICodeLenses component. - /// - public interface ICodeLenses - { - /// - /// Gets the collection of ICodeLensProvider implementations - /// that are registered with this component. - /// - List Providers { get; } - - /// - /// Provides a collection of CodeLenses for the given - /// document. - /// - /// - /// The document for which CodeLenses should be provided. - /// - /// An array of CodeLenses. - CodeLens[] ProvideCodeLenses(ScriptFile scriptFile); - } -} diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/BreakpointDetailsBase.cs b/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/BreakpointDetailsBase.cs index 061939836..eadbca233 100644 --- a/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/BreakpointDetailsBase.cs +++ b/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/BreakpointDetailsBase.cs @@ -9,7 +9,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.DebugAdapter /// Provides details about a breakpoint that is set in the /// PowerShell debugger. /// - public abstract class BreakpointDetailsBase + internal abstract class BreakpointDetailsBase { /// /// Gets or sets a boolean indicator that if true, breakpoint could be set diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/DebuggerStoppedEventArgs.cs b/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/DebuggerStoppedEventArgs.cs index 26ea3519a..7132add7f 100644 --- a/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/DebuggerStoppedEventArgs.cs +++ b/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/DebuggerStoppedEventArgs.cs @@ -12,7 +12,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.DebugAdapter /// /// Provides event arguments for the DebugService.DebuggerStopped event. /// - public class DebuggerStoppedEventArgs + internal class DebuggerStoppedEventArgs { #region Properties diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/StackFrameDetails.cs b/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/StackFrameDetails.cs index f99476980..bac6c3065 100644 --- a/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/StackFrameDetails.cs +++ b/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/StackFrameDetails.cs @@ -11,7 +11,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.DebugAdapter /// Contains details pertaining to a single stack frame in /// the current debugging session. /// - public class StackFrameDetails + internal class StackFrameDetails { #region Fields diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableContainerDetails.cs b/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableContainerDetails.cs index 75d264039..0510afe3e 100644 --- a/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableContainerDetails.cs +++ b/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableContainerDetails.cs @@ -19,7 +19,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.DebugAdapter /// way to organize variables into a useful UI structure. /// [DebuggerDisplay("Name = {Name}, Id = {Id}, Count = {Children.Count}")] - public class VariableContainerDetails : VariableDetailsBase + internal class VariableContainerDetails : VariableDetailsBase { /// /// Provides a constant for the name of the Global scope. diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableDetails.cs b/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableDetails.cs index 5980ca1cd..8b18fb73e 100644 --- a/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableDetails.cs +++ b/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableDetails.cs @@ -20,7 +20,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.DebugAdapter /// debugging session. /// [DebuggerDisplay("Name = {Name}, Id = {Id}, Value = {ValueString}")] - public class VariableDetails : VariableDetailsBase + internal class VariableDetails : VariableDetailsBase { #region Fields diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableDetailsBase.cs b/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableDetailsBase.cs index 357ebbea3..a23538841 100644 --- a/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableDetailsBase.cs +++ b/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableDetailsBase.cs @@ -12,7 +12,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.DebugAdapter /// Defines the common details between a variable and a variable container such as a scope /// in the current debugging session. /// - public abstract class VariableDetailsBase + internal abstract class VariableDetailsBase { /// /// Provides a constant that is used as the starting variable ID for all. diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableScope.cs b/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableScope.cs index 2e4a013e9..83e4dd441 100644 --- a/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableScope.cs +++ b/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/VariableScope.cs @@ -9,7 +9,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.DebugAdapter /// Contains details pertaining to a variable scope in the current /// debugging session. /// - public class VariableScope + internal class VariableScope { /// /// Gets a numeric ID that can be used in future operations diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/LaunchAndAttachHandler.cs b/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/LaunchAndAttachHandler.cs index 223aa995e..02e62a5f9 100644 --- a/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/LaunchAndAttachHandler.cs +++ b/src/PowerShellEditorServices/Services/DebugAdapter/Handlers/LaunchAndAttachHandler.cs @@ -22,12 +22,12 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { [Serial, Method("launch")] - interface IPsesLaunchHandler : IJsonRpcRequestHandler { } + internal interface IPsesLaunchHandler : IJsonRpcRequestHandler { } [Serial, Method("attach")] - interface IPsesAttachHandler : IJsonRpcRequestHandler { } + internal interface IPsesAttachHandler : IJsonRpcRequestHandler { } - public class PsesLaunchRequestArguments : IRequest + internal class PsesLaunchRequestArguments : IRequest { /// /// Gets or sets the absolute path to the script to debug. @@ -81,7 +81,7 @@ public class PsesLaunchRequestArguments : IRequest public Dictionary Env { get; set; } } - public class PsesAttachRequestArguments : IRequest + internal class PsesAttachRequestArguments : IRequest { public string ComputerName { get; set; } diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Console/ChoiceDetails.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Console/ChoiceDetails.cs index d93d0daca..e6071fd53 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Console/ChoiceDetails.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Console/ChoiceDetails.cs @@ -13,7 +13,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// to the user. This class is meant to be serializable to the /// user's UI. /// - public class ChoiceDetails + internal class ChoiceDetails { #region Private Fields diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Console/ChoicePromptHandler.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Console/ChoicePromptHandler.cs index 81b4b5a24..910436b56 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Console/ChoicePromptHandler.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Console/ChoicePromptHandler.cs @@ -16,7 +16,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// /// Indicates the style of prompt to be displayed. /// - public enum PromptStyle + internal enum PromptStyle { /// /// Indicates that the full prompt should be displayed @@ -37,7 +37,7 @@ public enum PromptStyle /// that present the user a set of options from which a selection /// should be made. /// - public abstract class ChoicePromptHandler : PromptHandler + internal abstract class ChoicePromptHandler : PromptHandler { #region Private Fields diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Console/CollectionFieldDetails.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Console/CollectionFieldDetails.cs index bfcf4cec8..7297f4f3b 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Console/CollectionFieldDetails.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Console/CollectionFieldDetails.cs @@ -13,7 +13,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// from an InputPromptHandler. This class is meant to be /// serializable to the user's UI. /// - public class CollectionFieldDetails : FieldDetails + internal class CollectionFieldDetails : FieldDetails { #region Private Fields diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Console/ConsoleChoicePromptHandler.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Console/ConsoleChoicePromptHandler.cs index bf209aeb0..754b2e940 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Console/ConsoleChoicePromptHandler.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Console/ConsoleChoicePromptHandler.cs @@ -12,7 +12,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// Provides a standard implementation of ChoicePromptHandler /// for use in the interactive console (REPL). /// - public abstract class ConsoleChoicePromptHandler : ChoicePromptHandler + internal abstract class ConsoleChoicePromptHandler : ChoicePromptHandler { #region Private Fields diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Console/ConsoleInputPromptHandler.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Console/ConsoleInputPromptHandler.cs index 1c9187b4f..bbaae7acb 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Console/ConsoleInputPromptHandler.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Console/ConsoleInputPromptHandler.cs @@ -12,7 +12,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// Provides a standard implementation of InputPromptHandler /// for use in the interactive console (REPL). /// - public abstract class ConsoleInputPromptHandler : InputPromptHandler + internal abstract class ConsoleInputPromptHandler : InputPromptHandler { #region Private Fields diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Console/CredentialFieldDetails.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Console/CredentialFieldDetails.cs index 5c27a70f6..f65a15874 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Console/CredentialFieldDetails.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Console/CredentialFieldDetails.cs @@ -14,7 +14,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// from an InputPromptHandler. This class is meant to /// be serializable to the user's UI. /// - public class CredentialFieldDetails : FieldDetails + internal class CredentialFieldDetails : FieldDetails { private string userName; private SecureString password; diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Console/FieldDetails.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Console/FieldDetails.cs index 3fe573659..a371f68d4 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Console/FieldDetails.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Console/FieldDetails.cs @@ -18,7 +18,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// InputPromptHandler. This class is meant to be /// serializable to the user's UI. /// - public class FieldDetails + internal class FieldDetails { #region Private Fields diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Console/IConsoleOperations.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Console/IConsoleOperations.cs index 2bfeb883c..68b66a4ad 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Console/IConsoleOperations.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Console/IConsoleOperations.cs @@ -12,7 +12,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// /// Provides platform specific console utilities. /// - public interface IConsoleOperations + internal interface IConsoleOperations { /// /// Obtains the next character or function key pressed by the user asynchronously. diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Console/InputPromptHandler.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Console/InputPromptHandler.cs index 85ddd6d16..886376d33 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Console/InputPromptHandler.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Console/InputPromptHandler.cs @@ -19,7 +19,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// that present the user a set of fields for which values /// should be entered. /// - public abstract class InputPromptHandler : PromptHandler + internal abstract class InputPromptHandler : PromptHandler { #region Private Fields diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Console/PromptHandler.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Console/PromptHandler.cs index 97e8c4c6a..706e4ed70 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Console/PromptHandler.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Console/PromptHandler.cs @@ -11,7 +11,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// /// Defines an abstract base class for prompt handler implementations. /// - public abstract class PromptHandler + internal abstract class PromptHandler { /// /// Gets the ILogger implementation used for this instance. diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/EditorOperationsService.cs b/src/PowerShellEditorServices/Services/PowerShellContext/EditorOperationsService.cs index d67f449e8..b489e7b1e 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/EditorOperationsService.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/EditorOperationsService.cs @@ -3,8 +3,8 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // +using Microsoft.PowerShell.EditorServices.Extensions; using Microsoft.PowerShell.EditorServices.Handlers; -using Microsoft.PowerShell.EditorServices.Services.PowerShellContext; using Microsoft.PowerShell.EditorServices.Services.TextDocument; using OmniSharp.Extensions.LanguageServer.Protocol.Models; using OmniSharp.Extensions.LanguageServer.Protocol.Server; diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/ExtensionService.cs b/src/PowerShellEditorServices/Services/PowerShellContext/ExtensionService.cs index f4e60bc53..28cd3e2a1 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/ExtensionService.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/ExtensionService.cs @@ -3,13 +3,14 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.PowerShell.EditorServices.Services.PowerShellContext; -using Microsoft.PowerShell.EditorServices.Utility; -using OmniSharp.Extensions.LanguageServer.Protocol.Server; using System; using System.Collections.Generic; using System.Management.Automation; using System.Threading.Tasks; +using Microsoft.PowerShell.EditorServices.Extensions; +using Microsoft.PowerShell.EditorServices.Services.PowerShellContext; +using Microsoft.PowerShell.EditorServices.Utility; +using OmniSharp.Extensions.LanguageServer.Protocol.Server; namespace Microsoft.PowerShell.EditorServices.Services { @@ -17,7 +18,7 @@ namespace Microsoft.PowerShell.EditorServices.Services /// Provides a high-level service which enables PowerShell scripts /// and modules to extend the behavior of the host editor. /// - public class ExtensionService + internal sealed class ExtensionService { #region Fields @@ -45,7 +46,7 @@ public class ExtensionService /// /// Gets the PowerShellContext in which extension code will be executed. /// - public PowerShellContextService PowerShellContext { get; private set; } + internal PowerShellContextService PowerShellContext { get; private set; } #endregion @@ -56,7 +57,7 @@ public class ExtensionService /// PowerShellContext for loading and executing extension code. /// /// A PowerShellContext used to execute extension code. - public ExtensionService(PowerShellContextService powerShellContext, ILanguageServer languageServer) + internal ExtensionService(PowerShellContextService powerShellContext, ILanguageServer languageServer) { this.PowerShellContext = powerShellContext; _languageServer = languageServer; @@ -72,7 +73,7 @@ public ExtensionService(PowerShellContextService powerShellContext, ILanguageSer /// /// An IEditorOperations implementation. /// A Task that can be awaited for completion. - public async Task InitializeAsync( + internal async Task InitializeAsync( IServiceProvider serviceProvider, IEditorOperations editorOperations) { @@ -87,6 +88,9 @@ public async Task InitializeAsync( this, editorOperations); + // Assign the new EditorObject to be the static instance available to binary APIs + this.EditorObject.SetAsStaticInstance(); + // Register the editor object in the runspace PSCommand variableCommand = new PSCommand(); using (RunspaceHandle handle = await this.PowerShellContext.GetRunspaceHandleAsync().ConfigureAwait(false)) diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/EvaluateHandler.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/EvaluateHandler.cs index 8399ce38b..4c93893bb 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/EvaluateHandler.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/EvaluateHandler.cs @@ -10,7 +10,7 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { - public class EvaluateHandler : IEvaluateHandler + internal class EvaluateHandler : IEvaluateHandler { private readonly ILogger _logger; private readonly PowerShellContextService _powerShellContextService; diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/ExpandAliasHandler.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/ExpandAliasHandler.cs index 662b91098..c063bb00c 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/ExpandAliasHandler.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/ExpandAliasHandler.cs @@ -15,19 +15,19 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { [Serial, Method("powerShell/expandAlias")] - public interface IExpandAliasHandler : IJsonRpcRequestHandler { } + internal interface IExpandAliasHandler : IJsonRpcRequestHandler { } - public class ExpandAliasParams : IRequest + internal class ExpandAliasParams : IRequest { public string Text { get; set; } } - public class ExpandAliasResult + internal class ExpandAliasResult { public string Text { get; set; } } - public class ExpandAliasHandler : IExpandAliasHandler + internal class ExpandAliasHandler : IExpandAliasHandler { private readonly ILogger _logger; private readonly PowerShellContextService _powerShellContextService; diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/GetCommandHandler.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/GetCommandHandler.cs index 59c73bb65..2d615360d 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/GetCommandHandler.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/GetCommandHandler.cs @@ -15,15 +15,15 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { [Serial, Method("powerShell/getCommand")] - public interface IGetCommandHandler : IJsonRpcRequestHandler> { } + internal interface IGetCommandHandler : IJsonRpcRequestHandler> { } - public class GetCommandParams : IRequest> { } + internal class GetCommandParams : IRequest> { } /// /// Describes the message to get the details for a single PowerShell Command /// from the current session /// - public class PSCommandMessage + internal class PSCommandMessage { public string Name { get; set; } public string ModuleName { get; set; } @@ -32,7 +32,7 @@ public class PSCommandMessage public System.Collections.ObjectModel.ReadOnlyCollection ParameterSets { get; set; } } - public class GetCommandHandler : IGetCommandHandler + internal class GetCommandHandler : IGetCommandHandler { private readonly ILogger _logger; private readonly PowerShellContextService _powerShellContextService; diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/GetVersionHandler.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/GetVersionHandler.cs index a1c738ee1..551cdc144 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/GetVersionHandler.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/GetVersionHandler.cs @@ -11,7 +11,7 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { - public class GetVersionHandler : IGetVersionHandler + internal class GetVersionHandler : IGetVersionHandler { private readonly ILogger _logger; diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IEvaluateHandler.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IEvaluateHandler.cs index 17293ec59..aeae4e458 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IEvaluateHandler.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IEvaluateHandler.cs @@ -9,9 +9,9 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { [Serial, Method("evaluate")] - public interface IEvaluateHandler : IJsonRpcRequestHandler { } + internal interface IEvaluateHandler : IJsonRpcRequestHandler { } - public class EvaluateRequestArguments : IRequest + internal class EvaluateRequestArguments : IRequest { /// /// The expression to evaluate. @@ -32,7 +32,7 @@ public class EvaluateRequestArguments : IRequest public int FrameId { get; set; } } - public class EvaluateResponseBody + internal class EvaluateResponseBody { /// /// The evaluation result. diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IGetCommentHelpHandler.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IGetCommentHelpHandler.cs index 0fc4fe4c7..4ba0fc8f3 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IGetCommentHelpHandler.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IGetCommentHelpHandler.cs @@ -10,14 +10,14 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { [Serial, Method("powerShell/getCommentHelp")] - public interface IGetCommentHelpHandler : IJsonRpcRequestHandler { } + internal interface IGetCommentHelpHandler : IJsonRpcRequestHandler { } - public class CommentHelpRequestResult + internal class CommentHelpRequestResult { public string[] Content { get; set; } } - public class CommentHelpRequestParams : IRequest + internal class CommentHelpRequestParams : IRequest { public string DocumentUri { get; set; } public Position TriggerPosition { get; set; } diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IGetPSHostProcessesHandler.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IGetPSHostProcessesHandler.cs index 2ab570891..8afd647d2 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IGetPSHostProcessesHandler.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IGetPSHostProcessesHandler.cs @@ -9,11 +9,11 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { [Serial, Method("powerShell/getPSHostProcesses")] - public interface IGetPSHostProcessesHandler : IJsonRpcRequestHandler { } + internal interface IGetPSHostProcessesHandler : IJsonRpcRequestHandler { } - public class GetPSHostProcesssesParams : IRequest { } + internal class GetPSHostProcesssesParams : IRequest { } - public class PSHostProcessResponse + internal class PSHostProcessResponse { public string ProcessName { get; set; } diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IGetRunspaceHandler.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IGetRunspaceHandler.cs index a4d3847cb..9c9b9d43a 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IGetRunspaceHandler.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IGetRunspaceHandler.cs @@ -9,14 +9,14 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { [Serial, Method("powerShell/getRunspace")] - public interface IGetRunspaceHandler : IJsonRpcRequestHandler { } + internal interface IGetRunspaceHandler : IJsonRpcRequestHandler { } - public class GetRunspaceParams : IRequest + internal class GetRunspaceParams : IRequest { public string ProcessId {get; set; } } - public class RunspaceResponse + internal class RunspaceResponse { public int Id { get; set; } diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IGetVersionHandler.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IGetVersionHandler.cs index 6fbf59ceb..7ee38f26a 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IGetVersionHandler.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IGetVersionHandler.cs @@ -10,11 +10,11 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { [Serial, Method("powerShell/getVersion")] - public interface IGetVersionHandler : IJsonRpcRequestHandler { } + internal interface IGetVersionHandler : IJsonRpcRequestHandler { } - public class GetVersionParams : IRequest { } + internal class GetVersionParams : IRequest { } - public class PowerShellVersion + internal class PowerShellVersion { public string Version { get; set; } public string DisplayVersion { get; set; } diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IInvokeExtensionCommandHandler.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IInvokeExtensionCommandHandler.cs index 633a58217..eedb4dd7a 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IInvokeExtensionCommandHandler.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IInvokeExtensionCommandHandler.cs @@ -10,16 +10,16 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { [Serial, Method("powerShell/invokeExtensionCommand")] - public interface IInvokeExtensionCommandHandler : IJsonRpcNotificationHandler { } + internal interface IInvokeExtensionCommandHandler : IJsonRpcNotificationHandler { } - public class InvokeExtensionCommandParams : IRequest + internal class InvokeExtensionCommandParams : IRequest { public string Name { get; set; } public ClientEditorContext Context { get; set; } } - public class ClientEditorContext + internal class ClientEditorContext { public string CurrentFileContent { get; set; } diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/ITemplateHandlers.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/ITemplateHandlers.cs index d3783318a..96f725510 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/ITemplateHandlers.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/ITemplateHandlers.cs @@ -9,17 +9,17 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { [Serial, Method("powerShell/getProjectTemplates")] - public interface IGetProjectTemplatesHandler : IJsonRpcRequestHandler { } + internal interface IGetProjectTemplatesHandler : IJsonRpcRequestHandler { } [Serial, Method("powerShell/newProjectFromTemplate")] - public interface INewProjectFromTemplateHandler : IJsonRpcRequestHandler { } + internal interface INewProjectFromTemplateHandler : IJsonRpcRequestHandler { } - public class GetProjectTemplatesRequest : IRequest + internal class GetProjectTemplatesRequest : IRequest { public bool IncludeInstalledModules { get; set; } } - public class GetProjectTemplatesResponse + internal class GetProjectTemplatesResponse { public bool NeedsModuleInstall { get; set; } @@ -29,7 +29,7 @@ public class GetProjectTemplatesResponse /// /// Provides details about a file or project template. /// - public class TemplateDetails + internal class TemplateDetails { /// /// Gets or sets the title of the template. @@ -62,14 +62,14 @@ public class TemplateDetails public string TemplatePath { get; set; } } - public class NewProjectFromTemplateRequest : IRequest + internal class NewProjectFromTemplateRequest : IRequest { public string DestinationPath { get; set; } public string TemplatePath { get; set; } } - public class NewProjectFromTemplateResponse + internal class NewProjectFromTemplateResponse { public bool CreationSuccessful { get; set; } } diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/InvokeExtensionCommandHandler.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/InvokeExtensionCommandHandler.cs index 7773096a6..d9e3311db 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/InvokeExtensionCommandHandler.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/InvokeExtensionCommandHandler.cs @@ -5,10 +5,10 @@ using System.Threading; using System.Threading.Tasks; +using MediatR; using Microsoft.Extensions.Logging; using Microsoft.PowerShell.EditorServices.Services; -using Microsoft.PowerShell.EditorServices.Services.PowerShellContext; -using MediatR; +using Microsoft.PowerShell.EditorServices.Extensions; namespace Microsoft.PowerShell.EditorServices.Handlers { diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/PSHostProcessAndRunspaceHandlers.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/PSHostProcessAndRunspaceHandlers.cs index bdb0e0c77..1b6ccc8f0 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/PSHostProcessAndRunspaceHandlers.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/PSHostProcessAndRunspaceHandlers.cs @@ -15,7 +15,7 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { using System.Management.Automation; - public class PSHostProcessAndRunspaceHandlers : IGetPSHostProcessesHandler, IGetRunspaceHandler + internal class PSHostProcessAndRunspaceHandlers : IGetPSHostProcessesHandler, IGetRunspaceHandler { private readonly ILogger _logger; private readonly PowerShellContextService _powerShellContextService; diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/ShowHelpHandler.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/ShowHelpHandler.cs index 5c48e9937..55df6bf6a 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/ShowHelpHandler.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/ShowHelpHandler.cs @@ -14,14 +14,14 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { [Serial, Method("powerShell/showHelp")] - public interface IShowHelpHandler : IJsonRpcNotificationHandler { } + internal interface IShowHelpHandler : IJsonRpcNotificationHandler { } - public class ShowHelpParams : IRequest + internal class ShowHelpParams : IRequest { public string Text { get; set; } } - public class ShowHelpHandler : IShowHelpHandler + internal class ShowHelpHandler : IShowHelpHandler { private readonly ILogger _logger; private readonly PowerShellContextService _powerShellContextService; diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/TemplateHandlers.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/TemplateHandlers.cs index 48a2d2b34..646c79358 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/TemplateHandlers.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Handlers/TemplateHandlers.cs @@ -12,7 +12,7 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { - public class TemplateHandlers : IGetProjectTemplatesHandler, INewProjectFromTemplateHandler + internal class TemplateHandlers : IGetProjectTemplatesHandler, INewProjectFromTemplateHandler { private readonly ILogger _logger; private readonly TemplateService _templateService; diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs b/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs index efe33f120..b919958d7 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs @@ -33,7 +33,7 @@ namespace Microsoft.PowerShell.EditorServices.Services /// Handles nested PowerShell prompts and also manages execution of /// commands whether inside or outside of the debugger. /// - public class PowerShellContextService : IDisposable, IHostSupportsInteractiveSession + internal class PowerShellContextService : IDisposable, IHostSupportsInteractiveSession { private static readonly string s_commandsModulePath = Path.GetFullPath( Path.Combine( @@ -1836,7 +1836,7 @@ private void PowerShellContext_RunspaceChangedAsync(object sender, RunspaceChang // P.S. MinifiedRunspaceDetails use to be called RunspaceDetails... as in, there were 2 DIFFERENT // RunspaceDetails types in this codebase but I've changed it to be minified since the type is // slightly simpler than the other RunspaceDetails. - public class MinifiedRunspaceDetails + internal class MinifiedRunspaceDetails { public PowerShellVersion PowerShellVersion { get; set; } diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/RemoteFileManagerService.cs b/src/PowerShellEditorServices/Services/PowerShellContext/RemoteFileManagerService.cs index ac44f445d..0695ae523 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/RemoteFileManagerService.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/RemoteFileManagerService.cs @@ -4,6 +4,7 @@ // using Microsoft.Extensions.Logging; +using Microsoft.PowerShell.EditorServices.Extensions; using Microsoft.PowerShell.EditorServices.Logging; using Microsoft.PowerShell.EditorServices.Services.PowerShellContext; using Microsoft.PowerShell.EditorServices.Utility; diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/ExecutionOptions.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/ExecutionOptions.cs index fba9736e0..31e0ab1de 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/ExecutionOptions.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/ExecutionOptions.cs @@ -8,7 +8,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// /// Defines options for the execution of a command. /// - public class ExecutionOptions + internal class ExecutionOptions { private bool? _shouldExecuteInOriginalRunspace; diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/ExecutionStatus.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/ExecutionStatus.cs index 66caef00e..b804c2828 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/ExecutionStatus.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/ExecutionStatus.cs @@ -9,7 +9,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// Enumerates the possible execution results that can occur after /// executing a command or script. /// - public enum ExecutionStatus + internal enum ExecutionStatus { /// /// Indicates that execution has not yet started. diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/ExecutionStatusChangedEventArgs.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/ExecutionStatusChangedEventArgs.cs index f9abb1cbb..f920767f5 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/ExecutionStatusChangedEventArgs.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/ExecutionStatusChangedEventArgs.cs @@ -8,7 +8,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// /// Contains details about an executed /// - public class ExecutionStatusChangedEventArgs + internal class ExecutionStatusChangedEventArgs { #region Properties diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHost.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHost.cs index 5eda7bd6c..e43dab169 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHost.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHost.cs @@ -17,7 +17,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// ConsoleService and routes its calls to an IConsoleHost /// implementation. /// - public class EditorServicesPSHost : PSHost, IHostSupportsInteractiveSession + internal class EditorServicesPSHost : PSHost, IHostSupportsInteractiveSession { #region Private Fields diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs index 843de0bff..4bd510a9a 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs @@ -24,7 +24,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// for the ConsoleService and routes its calls to an IConsoleHost /// implementation. /// - public abstract class EditorServicesPSHostUserInterface : + internal abstract class EditorServicesPSHostUserInterface : PSHostUserInterface, IHostInput, IHostOutput, diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/IHostInput.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/IHostInput.cs index cdce37129..5e35e6478 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/IHostInput.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/IHostInput.cs @@ -8,7 +8,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// /// Provides methods for integrating with the host's input system. /// - public interface IHostInput + internal interface IHostInput { /// /// Starts the host's interactive command loop. diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/IHostOutput.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/IHostOutput.cs index 9b5565f37..c3039bff8 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/IHostOutput.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/IHostOutput.cs @@ -11,7 +11,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// Provides a simplified interface for writing output to a /// PowerShell host implementation. /// - public interface IHostOutput + internal interface IHostOutput { /// /// Writes output of the given type to the user interface with @@ -44,7 +44,7 @@ void WriteOutput( /// /// Provides helpful extension methods for the IHostOutput interface. /// - public static class IHostOutputExtensions + internal static class IHostOutputExtensions { /// /// Writes normal output with a newline to the user interface. diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/PromptEvents.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/PromptEvents.cs index 967830d9d..f9b0f3344 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/PromptEvents.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/PromptEvents.cs @@ -5,7 +5,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext { - public class ShowChoicePromptRequest + internal class ShowChoicePromptRequest { public bool IsMultiChoice { get; set; } @@ -18,14 +18,14 @@ public class ShowChoicePromptRequest public int[] DefaultChoices { get; set; } } - public class ShowChoicePromptResponse + internal class ShowChoicePromptResponse { public bool PromptCancelled { get; set; } public string ResponseText { get; set; } } - public class ShowInputPromptRequest + internal class ShowInputPromptRequest { /// /// Gets or sets the name of the field. @@ -38,7 +38,7 @@ public class ShowInputPromptRequest public string Label { get; set; } } - public class ShowInputPromptResponse + internal class ShowInputPromptResponse { public bool PromptCancelled { get; set; } diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/SimplePSHostRawUserInterface.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/SimplePSHostRawUserInterface.cs index 701f48851..17ca7408f 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/SimplePSHostRawUserInterface.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/SimplePSHostRawUserInterface.cs @@ -12,7 +12,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// /// Provides an simple implementation of the PSHostRawUserInterface class. /// - public class SimplePSHostRawUserInterface : PSHostRawUserInterface + internal class SimplePSHostRawUserInterface : PSHostRawUserInterface { #region Private Fields diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs index 20e5398c4..65043e38f 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/TerminalPSHostUserInterface.cs @@ -17,7 +17,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// Provides an EditorServicesPSHostUserInterface implementation /// that integrates with the user's terminal UI. /// - public class TerminalPSHostUserInterface : EditorServicesPSHostUserInterface + internal class TerminalPSHostUserInterface : EditorServicesPSHostUserInterface { #region Private Fields diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/IPromptContext.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/IPromptContext.cs index 2d1785670..501489cbd 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/IPromptContext.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/IPromptContext.cs @@ -11,7 +11,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// /// Provides methods for interacting with implementations of ReadLine. /// - public interface IPromptContext + internal interface IPromptContext { /// /// Read a string that has been input by the user. diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/OutputType.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/OutputType.cs index 92b5ef540..d56305adf 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/OutputType.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/OutputType.cs @@ -9,7 +9,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// Enumerates the types of output lines that will be sent /// to an IConsoleHost implementation. /// - public enum OutputType + internal enum OutputType { /// /// A normal output line, usually written with the or Write-Host or diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/OutputWrittenEventArgs.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/OutputWrittenEventArgs.cs index 284dc5dc5..e17e29b12 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/OutputWrittenEventArgs.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/OutputWrittenEventArgs.cs @@ -11,7 +11,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// Provides details about output that has been written to the /// PowerShell host. /// - public class OutputWrittenEventArgs + internal class OutputWrittenEventArgs { /// /// Gets the text of the output. diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/PowerShellContextState.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/PowerShellContextState.cs index c2742e270..6a7d8630c 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/PowerShellContextState.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/PowerShellContextState.cs @@ -8,7 +8,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// /// Enumerates the possible states for a PowerShellContext. /// - public enum PowerShellContextState + internal enum PowerShellContextState { /// /// Indicates an unknown, potentially uninitialized state. diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/PowerShellExecutionResult.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/PowerShellExecutionResult.cs index 1be771187..a05037daf 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/PowerShellExecutionResult.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/PowerShellExecutionResult.cs @@ -9,7 +9,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// Enumerates the possible execution results that can occur after /// executing a command or script. /// - public enum PowerShellExecutionResult + internal enum PowerShellExecutionResult { /// /// Indicates that execution is not yet finished. diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/PowerShellVersionDetails.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/PowerShellVersionDetails.cs index 6e1a1a32e..72b8dc5be 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/PowerShellVersionDetails.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/PowerShellVersionDetails.cs @@ -13,7 +13,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// /// Defines the possible enumeration values for the PowerShell process architecture. /// - public enum PowerShellProcessArchitecture + internal enum PowerShellProcessArchitecture { /// /// The processor architecture is unknown or wasn't accessible. @@ -34,7 +34,7 @@ public enum PowerShellProcessArchitecture /// /// Provides details about the version of the PowerShell runtime. /// - public class PowerShellVersionDetails + internal class PowerShellVersionDetails { #region Properties diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/ProgressDetails.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/ProgressDetails.cs index fc7fb2047..3f63edafd 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/ProgressDetails.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/ProgressDetails.cs @@ -10,7 +10,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// /// Provides details about the progress of a particular activity. /// - public class ProgressDetails + internal class ProgressDetails { /// /// Gets the percentage of the activity that has been completed. diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/RunspaceChangedEventArgs.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/RunspaceChangedEventArgs.cs index 77512c9c1..590488c30 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/RunspaceChangedEventArgs.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/RunspaceChangedEventArgs.cs @@ -10,7 +10,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// /// Defines the set of actions that will cause the runspace to be changed. /// - public enum RunspaceChangeAction + internal enum RunspaceChangeAction { /// /// The runspace change was caused by entering a new session. @@ -31,7 +31,7 @@ public enum RunspaceChangeAction /// /// Provides arguments for the PowerShellContext.RunspaceChanged event. /// - public class RunspaceChangedEventArgs + internal class RunspaceChangedEventArgs { /// /// Gets the RunspaceChangeAction which caused this event. diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/RunspaceDetails.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/RunspaceDetails.cs index 54f38cf34..d5013c9f9 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/RunspaceDetails.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/RunspaceDetails.cs @@ -15,7 +15,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// /// Specifies the possible types of a runspace. /// - public enum RunspaceLocation + internal enum RunspaceLocation { /// /// A runspace on the local machine. @@ -31,7 +31,7 @@ public enum RunspaceLocation /// /// Specifies the context in which the runspace was encountered. /// - public enum RunspaceContext + internal enum RunspaceContext { /// /// The original runspace in a local or remote session. @@ -53,7 +53,7 @@ public enum RunspaceContext /// Provides details about a runspace being used in the current /// editing session. /// - public class RunspaceDetails + internal class RunspaceDetails { #region Private Fields diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/RunspaceHandle.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/RunspaceHandle.cs index 650cce9d2..f6e9a61d5 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/RunspaceHandle.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/RunspaceHandle.cs @@ -13,7 +13,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// Provides a handle to the runspace that is managed by /// a PowerShellContext. The holder of this handle. /// - public class RunspaceHandle : IDisposable + internal class RunspaceHandle : IDisposable { private PowerShellContextService powerShellContext; diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/SessionDetails.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/SessionDetails.cs index d30722d9f..9054e5784 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/SessionDetails.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/SessionDetails.cs @@ -13,7 +13,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// /// Provides details about the current PowerShell session. /// - public class SessionDetails + internal class SessionDetails { /// /// Gets the process ID of the current process. diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Session/SessionStateChangedEventArgs.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Session/SessionStateChangedEventArgs.cs index 70c40a7f2..3d3d60e9f 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Session/SessionStateChangedEventArgs.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Session/SessionStateChangedEventArgs.cs @@ -10,7 +10,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// /// Provides details about a change in state of a PowerShellContext. /// - public class SessionStateChangedEventArgs + internal class SessionStateChangedEventArgs { /// /// Gets the new state for the session. diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/TemplateService.cs b/src/PowerShellEditorServices/Services/PowerShellContext/TemplateService.cs index 7dfd8e022..7e5f4916f 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/TemplateService.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/TemplateService.cs @@ -19,7 +19,7 @@ namespace Microsoft.PowerShell.EditorServices.Services /// new projects from those templates. This service leverages the Plaster /// module for creating projects from templates. /// - public class TemplateService + internal class TemplateService { #region Private Fields diff --git a/src/PowerShellEditorServices/Services/PowerShellContext/Utilities/CommandHelpers.cs b/src/PowerShellEditorServices/Services/PowerShellContext/Utilities/CommandHelpers.cs index 347b2faa8..8e3ddc1c9 100644 --- a/src/PowerShellEditorServices/Services/PowerShellContext/Utilities/CommandHelpers.cs +++ b/src/PowerShellEditorServices/Services/PowerShellContext/Utilities/CommandHelpers.cs @@ -14,7 +14,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext /// /// Provides utility methods for working with PowerShell commands. /// - public static class CommandHelpers + internal static class CommandHelpers { private static readonly ConcurrentDictionary NounExclusionList = new ConcurrentDictionary(); diff --git a/src/PowerShellEditorServices/Services/Symbols/IDocumentSymbolProvider.cs b/src/PowerShellEditorServices/Services/Symbols/IDocumentSymbolProvider.cs index efb5af5d8..ed0fe594b 100644 --- a/src/PowerShellEditorServices/Services/Symbols/IDocumentSymbolProvider.cs +++ b/src/PowerShellEditorServices/Services/Symbols/IDocumentSymbolProvider.cs @@ -11,8 +11,10 @@ namespace Microsoft.PowerShell.EditorServices.Services.Symbols /// /// Specifies the contract for a document symbols provider. /// - public interface IDocumentSymbolProvider + internal interface IDocumentSymbolProvider { + string ProviderId { get; } + /// /// Provides a list of symbols for the given document. /// @@ -20,6 +22,6 @@ public interface IDocumentSymbolProvider /// The document for which SymbolReferences should be provided. /// /// An IEnumerable collection of SymbolReferences. - IEnumerable ProvideDocumentSymbols(ScriptFile scriptFile); + IEnumerable ProvideDocumentSymbols(ScriptFile scriptFile); } } diff --git a/src/PowerShellEditorServices/Services/Symbols/IDocumentSymbols.cs b/src/PowerShellEditorServices/Services/Symbols/IDocumentSymbols.cs deleted file mode 100644 index b1cd09c1b..000000000 --- a/src/PowerShellEditorServices/Services/Symbols/IDocumentSymbols.cs +++ /dev/null @@ -1,33 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -using System.Collections.Generic; -using System.Collections.ObjectModel; -using Microsoft.PowerShell.EditorServices.Services.TextDocument; - -namespace Microsoft.PowerShell.EditorServices.Services.Symbols -{ - /// - /// Specifies the contract for an implementation of - /// the IDocumentSymbols component. - /// - public interface IDocumentSymbols - { - /// - /// Gets the collection of IDocumentSymbolsProvider implementations - /// that are registered with this component. - /// - Collection Providers { get; } - - /// - /// Provides a list of symbols for the given document. - /// - /// - /// The document for which SymbolReferences should be provided. - /// - /// An IEnumerable collection of SymbolReferences. - IEnumerable ProvideDocumentSymbols(ScriptFile scriptFile); - } -} diff --git a/src/PowerShellEditorServices/Services/Symbols/ParameterSetSignatures.cs b/src/PowerShellEditorServices/Services/Symbols/ParameterSetSignatures.cs index df61a0179..7c1028e0d 100644 --- a/src/PowerShellEditorServices/Services/Symbols/ParameterSetSignatures.cs +++ b/src/PowerShellEditorServices/Services/Symbols/ParameterSetSignatures.cs @@ -14,7 +14,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.Symbols /// A class for containing the commandName, the command's /// possible signatures, and the script extent of the command /// - public class ParameterSetSignatures + internal class ParameterSetSignatures { #region Properties @@ -56,7 +56,7 @@ public ParameterSetSignatures(IEnumerable commandInfoSe /// /// A class for containing the signature text and the collection of parameters for a signature /// - public class ParameterSetSignature + internal class ParameterSetSignature { private static readonly ConcurrentDictionary commonParameterNames = new ConcurrentDictionary(); @@ -111,7 +111,7 @@ public ParameterSetSignature(CommandParameterSetInfo commandParamInfoSet) /// /// A class for containing the parameter info of a parameter /// - public class ParameterInfo + internal class ParameterInfo { #region Properties /// diff --git a/src/PowerShellEditorServices/Services/Symbols/PesterDocumentSymbolProvider.cs b/src/PowerShellEditorServices/Services/Symbols/PesterDocumentSymbolProvider.cs index 1f754a235..d90306855 100644 --- a/src/PowerShellEditorServices/Services/Symbols/PesterDocumentSymbolProvider.cs +++ b/src/PowerShellEditorServices/Services/Symbols/PesterDocumentSymbolProvider.cs @@ -15,10 +15,11 @@ namespace Microsoft.PowerShell.EditorServices.Services.Symbols /// Provides an IDocumentSymbolProvider implementation for /// enumerating test symbols in Pester test (tests.ps1) files. /// - public class PesterDocumentSymbolProvider : IDocumentSymbolProvider + internal class PesterDocumentSymbolProvider : IDocumentSymbolProvider { + string IDocumentSymbolProvider.ProviderId => nameof(PesterDocumentSymbolProvider); - IEnumerable IDocumentSymbolProvider.ProvideDocumentSymbols( + IEnumerable IDocumentSymbolProvider.ProvideDocumentSymbols( ScriptFile scriptFile) { if (!scriptFile.FilePath.EndsWith( @@ -150,7 +151,7 @@ private static bool TryGetTestNameArgument(CommandElementAst commandElementAst, /// /// Defines command types for Pester test blocks. /// - public enum PesterCommandType + internal enum PesterCommandType { /// /// Identifies a Describe block. @@ -172,7 +173,7 @@ public enum PesterCommandType /// Provides a specialization of SymbolReference containing /// extra information about Pester test symbols. /// - public class PesterSymbolReference : SymbolReference + internal class PesterSymbolReference : SymbolReference { /// /// Lookup for Pester keywords we support. Ideally we could extract these from Pester itself diff --git a/src/PowerShellEditorServices/Services/Symbols/PsdDocumentSymbolProvider.cs b/src/PowerShellEditorServices/Services/Symbols/PsdDocumentSymbolProvider.cs index 3a9d5b2a9..083e2e495 100644 --- a/src/PowerShellEditorServices/Services/Symbols/PsdDocumentSymbolProvider.cs +++ b/src/PowerShellEditorServices/Services/Symbols/PsdDocumentSymbolProvider.cs @@ -15,9 +15,11 @@ namespace Microsoft.PowerShell.EditorServices.Services.Symbols /// Provides an IDocumentSymbolProvider implementation for /// enumerating symbols in .psd1 files. /// - public class PsdDocumentSymbolProvider : IDocumentSymbolProvider + internal class PsdDocumentSymbolProvider : IDocumentSymbolProvider { - IEnumerable IDocumentSymbolProvider.ProvideDocumentSymbols( + string IDocumentSymbolProvider.ProviderId => nameof(PsdDocumentSymbolProvider); + + IEnumerable IDocumentSymbolProvider.ProvideDocumentSymbols( ScriptFile scriptFile) { if ((scriptFile.FilePath != null && diff --git a/src/PowerShellEditorServices/Services/Symbols/ScriptDocumentSymbolProvider.cs b/src/PowerShellEditorServices/Services/Symbols/ScriptDocumentSymbolProvider.cs index 6cc43250d..cb5b1f00e 100644 --- a/src/PowerShellEditorServices/Services/Symbols/ScriptDocumentSymbolProvider.cs +++ b/src/PowerShellEditorServices/Services/Symbols/ScriptDocumentSymbolProvider.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Management.Automation.Language; using Microsoft.PowerShell.EditorServices.Services.TextDocument; @@ -15,9 +16,11 @@ namespace Microsoft.PowerShell.EditorServices.Services.Symbols /// Provides an IDocumentSymbolProvider implementation for /// enumerating symbols in script (.psd1, .psm1) files. /// - public class ScriptDocumentSymbolProvider : IDocumentSymbolProvider + internal class ScriptDocumentSymbolProvider : IDocumentSymbolProvider { - IEnumerable IDocumentSymbolProvider.ProvideDocumentSymbols( + string IDocumentSymbolProvider.ProviderId => nameof(ScriptDocumentSymbolProvider); + + IEnumerable IDocumentSymbolProvider.ProvideDocumentSymbols( ScriptFile scriptFile) { // If we have an AST, then we know it's a PowerShell file diff --git a/src/PowerShellEditorServices/Services/Symbols/ScriptExtent.cs b/src/PowerShellEditorServices/Services/Symbols/ScriptExtent.cs index 6abff2626..969e5b807 100644 --- a/src/PowerShellEditorServices/Services/Symbols/ScriptExtent.cs +++ b/src/PowerShellEditorServices/Services/Symbols/ScriptExtent.cs @@ -13,7 +13,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.Symbols /// containing details about a section of script content /// in a file. /// - public class ScriptExtent : IScriptExtent + internal class ScriptExtent : IScriptExtent { #region Properties diff --git a/src/PowerShellEditorServices/Services/Symbols/SymbolDetails.cs b/src/PowerShellEditorServices/Services/Symbols/SymbolDetails.cs index a11fe38f2..2dea6429a 100644 --- a/src/PowerShellEditorServices/Services/Symbols/SymbolDetails.cs +++ b/src/PowerShellEditorServices/Services/Symbols/SymbolDetails.cs @@ -14,7 +14,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.Symbols /// Provides detailed information for a given symbol. /// [DebuggerDisplay("SymbolReference = {SymbolReference.SymbolType}/{SymbolReference.SymbolName}, DisplayString = {DisplayString}")] - public class SymbolDetails + internal class SymbolDetails { #region Properties diff --git a/src/PowerShellEditorServices/Services/Symbols/SymbolReference.cs b/src/PowerShellEditorServices/Services/Symbols/SymbolReference.cs index 02a808c2d..f6af0fe3c 100644 --- a/src/PowerShellEditorServices/Services/Symbols/SymbolReference.cs +++ b/src/PowerShellEditorServices/Services/Symbols/SymbolReference.cs @@ -9,11 +9,39 @@ namespace Microsoft.PowerShell.EditorServices.Services.Symbols { + internal interface ISymbolReference + { + /// + /// Gets the symbol's type + /// + SymbolType SymbolType { get; } + + /// + /// Gets the name of the symbol + /// + string SymbolName { get; } + + /// + /// Gets the script extent of the symbol + /// + ScriptRegion ScriptRegion { get; } + + /// + /// Gets the contents of the line the given symbol is on + /// + string SourceLine { get; } + + /// + /// Gets the path of the file in which the symbol was found. + /// + string FilePath { get; } + } + /// /// A class that holds the type, name, script extent, and source line of a symbol /// [DebuggerDisplay("SymbolType = {SymbolType}, SymbolName = {SymbolName}")] - public class SymbolReference + internal class SymbolReference : ISymbolReference { #region Properties @@ -75,7 +103,7 @@ public SymbolReference( } /// - /// Constructs and instance of a SymbolReference + /// Constructs an instance of a SymbolReference /// /// The higher level type of the symbol /// The script extent of the symbol diff --git a/src/PowerShellEditorServices/Services/Symbols/SymbolType.cs b/src/PowerShellEditorServices/Services/Symbols/SymbolType.cs index 29352e24b..a8bc6ecc3 100644 --- a/src/PowerShellEditorServices/Services/Symbols/SymbolType.cs +++ b/src/PowerShellEditorServices/Services/Symbols/SymbolType.cs @@ -8,7 +8,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.Symbols /// /// A way to define symbols on a higher level /// - public enum SymbolType + internal enum SymbolType { /// /// The symbol type is unknown diff --git a/src/PowerShellEditorServices/Services/Symbols/SymbolsService.cs b/src/PowerShellEditorServices/Services/Symbols/SymbolsService.cs index a87467789..b9e959f87 100644 --- a/src/PowerShellEditorServices/Services/Symbols/SymbolsService.cs +++ b/src/PowerShellEditorServices/Services/Symbols/SymbolsService.cs @@ -4,6 +4,7 @@ // using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.Specialized; using System.IO; @@ -14,6 +15,7 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.Extensions.Logging; +using Microsoft.PowerShell.EditorServices.CodeLenses; using Microsoft.PowerShell.EditorServices.Logging; using Microsoft.PowerShell.EditorServices.Services.PowerShellContext; using Microsoft.PowerShell.EditorServices.Services.Symbols; @@ -26,14 +28,16 @@ namespace Microsoft.PowerShell.EditorServices.Services /// Provides a high-level service for performing code completion and /// navigation operations on PowerShell scripts. /// - public class SymbolsService + internal class SymbolsService { #region Private Fields private readonly ILogger _logger; private readonly PowerShellContextService _powerShellContextService; private readonly WorkspaceService _workspaceService; - private readonly IDocumentSymbolProvider[] _documentSymbolProviders; + + private readonly ConcurrentDictionary _codeLensProviders; + private readonly ConcurrentDictionary _documentSymbolProviders; #endregion @@ -52,16 +56,63 @@ public SymbolsService( _logger = factory.CreateLogger(); _powerShellContextService = powerShellContextService; _workspaceService = workspaceService; - _documentSymbolProviders = new IDocumentSymbolProvider[] + + _codeLensProviders = new ConcurrentDictionary(); + var codeLensProviders = new ICodeLensProvider[] + { + new ReferencesCodeLensProvider(_workspaceService, this), + new PesterCodeLensProvider(), + }; + foreach (ICodeLensProvider codeLensProvider in codeLensProviders) + { + _codeLensProviders.TryAdd(codeLensProvider.ProviderId, codeLensProvider); + } + + _documentSymbolProviders = new ConcurrentDictionary(); + var documentSymbolProviders = new IDocumentSymbolProvider[] { new ScriptDocumentSymbolProvider(), new PsdDocumentSymbolProvider(), - new PesterDocumentSymbolProvider() + new PesterDocumentSymbolProvider(), }; + foreach (IDocumentSymbolProvider documentSymbolProvider in documentSymbolProviders) + { + _documentSymbolProviders.TryAdd(documentSymbolProvider.ProviderId, documentSymbolProvider); + } } #endregion + public bool TryResgisterCodeLensProvider(ICodeLensProvider codeLensProvider) + { + return _codeLensProviders.TryAdd(codeLensProvider.ProviderId, codeLensProvider); + } + + public bool DeregisterCodeLensProvider(string providerId) + { + return _codeLensProviders.TryRemove(providerId, out _); + } + + public IEnumerable GetCodeLensProviders() + { + return _codeLensProviders.Values; + } + + public bool TryRegisterDocumentSymbolProvider(IDocumentSymbolProvider documentSymbolProvider) + { + return _documentSymbolProviders.TryAdd(documentSymbolProvider.ProviderId, documentSymbolProvider); + } + + public bool DeregisterDocumentSymbolProvider(string providerId) + { + return _documentSymbolProviders.TryRemove(providerId, out _); + } + + public IEnumerable GetDocumentSymbolProviders() + { + return _documentSymbolProviders.Values; + } + /// /// Finds all the symbols in a file. /// @@ -72,7 +123,7 @@ public List FindSymbolsInFile(ScriptFile scriptFile) Validate.IsNotNull(nameof(scriptFile), scriptFile); var foundOccurrences = new List(); - foreach (IDocumentSymbolProvider symbolProvider in _documentSymbolProviders) + foreach (IDocumentSymbolProvider symbolProvider in GetDocumentSymbolProviders()) { foreach (SymbolReference reference in symbolProvider.ProvideDocumentSymbols(scriptFile)) { diff --git a/src/PowerShellEditorServices/Services/TextDocument/BufferPosition.cs b/src/PowerShellEditorServices/Services/TextDocument/BufferPosition.cs index 1cdf6cf67..7bbd25ddb 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/BufferPosition.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/BufferPosition.cs @@ -13,7 +13,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.TextDocument /// first line and column in the file is position 1,1). /// [DebuggerDisplay("Position = {Line}:{Column}")] - public class BufferPosition + internal class BufferPosition { #region Properties diff --git a/src/PowerShellEditorServices/Services/TextDocument/BufferRange.cs b/src/PowerShellEditorServices/Services/TextDocument/BufferRange.cs index dbc577b05..74143b5cd 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/BufferRange.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/BufferRange.cs @@ -13,7 +13,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.TextDocument /// a file buffer. /// [DebuggerDisplay("Start = {Start.Line}:{Start.Column}, End = {End.Line}:{End.Column}")] - public class BufferRange + internal sealed class BufferRange { #region Properties diff --git a/src/PowerShellEditorServices/Services/TextDocument/CompletionResults.cs b/src/PowerShellEditorServices/Services/TextDocument/CompletionResults.cs index 26c5d7515..0b8996434 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/CompletionResults.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/CompletionResults.cs @@ -16,7 +16,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.TextDocument /// /// Provides the results of a single code completion request. /// - public sealed class CompletionResults + internal sealed class CompletionResults { #region Properties @@ -87,7 +87,7 @@ private static CompletionDetails[] GetCompletionsArray( /// /// Enumerates the completion types that may be returned. /// - public enum CompletionType + internal enum CompletionType { /// /// Completion type is unknown, either through being uninitialized or @@ -156,7 +156,7 @@ public enum CompletionType /// Provides the details about a single completion result. /// [DebuggerDisplay("CompletionType = {CompletionType.ToString()}, CompletionText = {CompletionText}")] - public sealed class CompletionDetails + internal sealed class CompletionDetails { #region Properties diff --git a/src/PowerShellEditorServices/Services/TextDocument/FileChange.cs b/src/PowerShellEditorServices/Services/TextDocument/FileChange.cs index c407ae881..82685d3ec 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/FileChange.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/FileChange.cs @@ -8,7 +8,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.TextDocument /// /// Contains details relating to a content change in an open file. /// - public class FileChange + public sealed class FileChange { /// /// The string which is to be inserted in the file. diff --git a/src/PowerShellEditorServices/Services/TextDocument/FilePosition.cs b/src/PowerShellEditorServices/Services/TextDocument/FilePosition.cs index 8b0e4e970..e80f8a2c8 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/FilePosition.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/FilePosition.cs @@ -9,7 +9,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.TextDocument /// Provides details and operations for a buffer position in a /// specific file. /// - public class FilePosition : BufferPosition + internal sealed class FilePosition : BufferPosition { #region Private Fields diff --git a/src/PowerShellEditorServices/Services/TextDocument/FoldingReference.cs b/src/PowerShellEditorServices/Services/TextDocument/FoldingReference.cs index d2e54be70..a450a4b46 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/FoldingReference.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/FoldingReference.cs @@ -12,7 +12,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.TextDocument /// /// A class that holds the information for a foldable region of text in a document /// - public class FoldingReference: IComparable, IEquatable + internal class FoldingReference: IComparable, IEquatable { /// /// The zero-based line number from where the folded range starts. @@ -85,7 +85,7 @@ public int CompareTo(FoldingReference that) { /// A class that holds a list of FoldingReferences and ensures that when adding a reference that the /// folding rules are obeyed, e.g. Only one fold per start line /// - public class FoldingReferenceList + internal class FoldingReferenceList { private readonly Dictionary references = new Dictionary(); diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeLensHandlers.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeLensHandlers.cs index d594e4318..80aa5e671 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeLensHandlers.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/CodeLensHandlers.cs @@ -21,7 +21,7 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { - public class CodeLensHandlers : ICodeLensHandler, ICodeLensResolveHandler + internal class CodeLensHandlers : ICodeLensHandler, ICodeLensResolveHandler { private readonly DocumentSelector _documentSelector = new DocumentSelector( new DocumentFilter @@ -34,8 +34,6 @@ public class CodeLensHandlers : ICodeLensHandler, ICodeLensResolveHandler private readonly SymbolsService _symbolsService; private readonly WorkspaceService _workspaceService; - private readonly ICodeLensProvider[] _providers; - private CodeLensCapability _capability; public CodeLensHandlers(ILoggerFactory factory, SymbolsService symbolsService, WorkspaceService workspaceService) @@ -43,11 +41,6 @@ public CodeLensHandlers(ILoggerFactory factory, SymbolsService symbolsService, W _logger = factory.CreateLogger(); _workspaceService = workspaceService; _symbolsService = symbolsService; - _providers = new ICodeLensProvider[] - { - new ReferencesCodeLensProvider(_workspaceService, _symbolsService), - new PesterCodeLensProvider() - }; } CodeLensRegistrationOptions IRegistration.GetRegistrationOptions() @@ -79,7 +72,7 @@ public TextDocumentRegistrationOptions GetRegistrationOptions() public bool CanResolve(CodeLens value) { CodeLensData codeLensData = value.Data.ToObject(); - return value?.Data != null && _providers.Any(provider => provider.ProviderId.Equals(codeLensData.ProviderId)); + return value?.Data != null && _symbolsService.GetCodeLensProviders().Any(provider => provider.ProviderId.Equals(codeLensData.ProviderId)); } public Task Handle(CodeLens request, CancellationToken cancellationToken) @@ -87,9 +80,9 @@ public Task Handle(CodeLens request, CancellationToken cancellationTok // TODO: Catch deserializtion exception on bad object CodeLensData codeLensData = request.Data.ToObject(); - ICodeLensProvider originalProvider = - _providers.FirstOrDefault( - provider => provider.ProviderId.Equals(codeLensData.ProviderId)); + ICodeLensProvider originalProvider = _symbolsService + .GetCodeLensProviders() + .FirstOrDefault(provider => provider.ProviderId.Equals(codeLensData.ProviderId)); ScriptFile scriptFile = _workspaceService.GetFile( @@ -131,7 +124,7 @@ private IEnumerable InvokeProviders( Stopwatch invokeTimer = new Stopwatch(); List providerResults = new List(); - foreach (var provider in this._providers) + foreach (ICodeLensProvider provider in _symbolsService.GetCodeLensProviders()) { try { diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DefinitionHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DefinitionHandler.cs index fae3aea65..a050dce5c 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DefinitionHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DefinitionHandler.cs @@ -17,7 +17,7 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { - public class DefinitionHandler : IDefinitionHandler + internal class DefinitionHandler : IDefinitionHandler { private readonly DocumentSelector _documentSelector = new DocumentSelector( new DocumentFilter diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentHighlightHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentHighlightHandler.cs index c984b1489..2859c57e3 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentHighlightHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentHighlightHandler.cs @@ -17,7 +17,7 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { - public class DocumentHighlightHandler : IDocumentHighlightHandler + internal class DocumentHighlightHandler : IDocumentHighlightHandler { private static readonly DocumentHighlightContainer s_emptyHighlightContainer = new DocumentHighlightContainer(); diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentSymbolHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentSymbolHandler.cs index 53ffb1f2b..ae12cbc39 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentSymbolHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentSymbolHandler.cs @@ -22,7 +22,7 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { - public class DocumentSymbolHandler : IDocumentSymbolHandler + internal class DocumentSymbolHandler : IDocumentSymbolHandler { private readonly DocumentSelector _documentSelector = new DocumentSelector( new DocumentFilter @@ -62,7 +62,7 @@ public Task Handle(DocumentSymbolPar { ScriptFile scriptFile = _workspaceService.GetFile(request.TextDocument.Uri); - IEnumerable foundSymbols = + IEnumerable foundSymbols = this.ProvideDocumentSymbols(scriptFile); SymbolInformationOrDocumentSymbol[] symbols = null; @@ -103,7 +103,7 @@ public void SetCapability(DocumentSymbolCapability capability) _capability = capability; } - private IEnumerable ProvideDocumentSymbols( + private IEnumerable ProvideDocumentSymbols( ScriptFile scriptFile) { return @@ -164,7 +164,7 @@ private static SymbolKind GetSymbolKind(SymbolType symbolType) } } - private static string GetDecoratedSymbolName(SymbolReference symbolReference) + private static string GetDecoratedSymbolName(ISymbolReference symbolReference) { string name = symbolReference.SymbolName; diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/FoldingRangeHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/FoldingRangeHandler.cs index 6945e379f..08c37536b 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/FoldingRangeHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/FoldingRangeHandler.cs @@ -15,7 +15,7 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { - public class FoldingRangeHandler : IFoldingRangeHandler + internal class FoldingRangeHandler : IFoldingRangeHandler { private readonly DocumentSelector _documentSelector = new DocumentSelector( new DocumentFilter() diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/HoverHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/HoverHandler.cs index 722b03d78..9a968fdc2 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/HoverHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/HoverHandler.cs @@ -16,7 +16,7 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { - public class HoverHandler : IHoverHandler + internal class HoverHandler : IHoverHandler { private readonly DocumentSelector _documentSelector = new DocumentSelector( new DocumentFilter diff --git a/src/PowerShellEditorServices/Services/TextDocument/Handlers/SignatureHelpHandler.cs b/src/PowerShellEditorServices/Services/TextDocument/Handlers/SignatureHelpHandler.cs index 2220a921d..f2acaf562 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/Handlers/SignatureHelpHandler.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/Handlers/SignatureHelpHandler.cs @@ -17,7 +17,7 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { - public class SignatureHelpHandler : ISignatureHelpHandler + internal class SignatureHelpHandler : ISignatureHelpHandler { private static readonly SignatureInformation[] s_emptySignatureResult = Array.Empty(); diff --git a/src/PowerShellEditorServices/Services/TextDocument/ScriptFile.cs b/src/PowerShellEditorServices/Services/TextDocument/ScriptFile.cs index edc0ac74b..7b9858c3f 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/ScriptFile.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/ScriptFile.cs @@ -17,7 +17,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.TextDocument /// /// Contains the details and contents of an open script file. /// - public class ScriptFile + internal sealed class ScriptFile { #region Private Fields @@ -153,7 +153,7 @@ public string[] ReferencedFiles /// The System.Uri of the file. /// The TextReader to use for reading the file's contents. /// The version of PowerShell for which the script is being parsed. - public ScriptFile( + internal ScriptFile( Uri fileUri, TextReader textReader, Version powerShellVersion) @@ -180,7 +180,7 @@ public ScriptFile( /// The System.Uri of the file. /// The initial contents of the script file. /// The version of PowerShell for which the script is being parsed. - public ScriptFile( + internal ScriptFile( Uri fileUri, string initialBuffer, Version powerShellVersion) @@ -200,8 +200,7 @@ public ScriptFile( /// /// Input string to be split up into lines. /// The lines in the string. - [Obsolete("This method is not designed for public exposure and will be retired in later versions of EditorServices")] - public static IList GetLines(string text) + internal static IList GetLines(string text) { return GetLinesInternal(text); } @@ -227,7 +226,7 @@ internal static List GetLinesInternal(string text) /// /// The path to check. /// True if the path is an untitled file, false otherwise. - public static bool IsUntitledPath(string path) + internal static bool IsUntitledPath(string path) { Validate.IsNotNull(nameof(path), path); @@ -323,19 +322,6 @@ public void ValidatePosition(int line, int column) } } - - /// - /// Defunct ValidatePosition method call. The isInsertion parameter is ignored. - /// - /// - /// - /// - [Obsolete("Use ValidatePosition(int, int) instead")] - public void ValidatePosition(int line, int column, bool isInsertion) - { - ValidatePosition(line, column); - } - /// /// Applies the provided FileChange to the file's contents /// diff --git a/src/PowerShellEditorServices/Services/TextDocument/ScriptFileMarker.cs b/src/PowerShellEditorServices/Services/TextDocument/ScriptFileMarker.cs index 11356aa35..975ee143e 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/ScriptFileMarker.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/ScriptFileMarker.cs @@ -15,7 +15,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.TextDocument /// /// Contains details for a code correction which can be applied from a ScriptFileMarker. /// - public class MarkerCorrection + public sealed class MarkerCorrection { /// /// Gets or sets the display name of the code correction. diff --git a/src/PowerShellEditorServices/Services/Workspace/ConfigurationService.cs b/src/PowerShellEditorServices/Services/Workspace/ConfigurationService.cs index e9d54359a..e0b5325a2 100644 --- a/src/PowerShellEditorServices/Services/Workspace/ConfigurationService.cs +++ b/src/PowerShellEditorServices/Services/Workspace/ConfigurationService.cs @@ -7,7 +7,7 @@ namespace Microsoft.PowerShell.EditorServices.Services { - public class ConfigurationService + internal class ConfigurationService { // This probably needs some sort of lock... or maybe LanguageServerSettings needs it. public LanguageServerSettings CurrentSettings { get; } = new LanguageServerSettings(); diff --git a/src/PowerShellEditorServices/Services/Workspace/Handlers/WorkspaceSymbolsHandler.cs b/src/PowerShellEditorServices/Services/Workspace/Handlers/WorkspaceSymbolsHandler.cs index c10c138e7..fdb026556 100644 --- a/src/PowerShellEditorServices/Services/Workspace/Handlers/WorkspaceSymbolsHandler.cs +++ b/src/PowerShellEditorServices/Services/Workspace/Handlers/WorkspaceSymbolsHandler.cs @@ -19,7 +19,7 @@ namespace Microsoft.PowerShell.EditorServices.Handlers { - public class WorkspaceSymbolsHandler : IWorkspaceSymbolsHandler + internal class WorkspaceSymbolsHandler : IWorkspaceSymbolsHandler { private readonly ILogger _logger; private readonly SymbolsService _symbolsService; diff --git a/src/PowerShellEditorServices/Services/Workspace/LanguageServerSettings.cs b/src/PowerShellEditorServices/Services/Workspace/LanguageServerSettings.cs index dbdefc9de..1afc9c650 100644 --- a/src/PowerShellEditorServices/Services/Workspace/LanguageServerSettings.cs +++ b/src/PowerShellEditorServices/Services/Workspace/LanguageServerSettings.cs @@ -14,7 +14,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.Configuration { - public class LanguageServerSettings + internal class LanguageServerSettings { private readonly object updateLock = new object(); public bool EnableProfileLoading { get; set; } @@ -53,7 +53,7 @@ public void Update( } } - public class ScriptAnalysisSettings + internal class ScriptAnalysisSettings { private readonly object updateLock = new object(); @@ -128,7 +128,7 @@ ex is PathTooLongException || /// Code formatting presets. /// See https://en.wikipedia.org/wiki/Indent_style for details on indent and brace styles. /// - public enum CodeFormattingPreset + internal enum CodeFormattingPreset { /// /// Use the formatting settings as-is. @@ -154,7 +154,7 @@ public enum CodeFormattingPreset /// /// Multi-line pipeline style settings. /// - public enum PipelineIndentationStyle + internal enum PipelineIndentationStyle { /// /// After the indentation level only once after the first pipeline and keep this level for the following pipelines. @@ -172,7 +172,7 @@ public enum PipelineIndentationStyle NoIndentation } - public class CodeFormattingSettings + internal class CodeFormattingSettings { /// /// Default constructor. @@ -321,7 +321,7 @@ private Hashtable GetCustomPSSASettingsHashtable(int tabSize, bool insertSpaces) /// /// Code folding settings /// - public class CodeFoldingSettings + internal class CodeFoldingSettings { /// /// Whether the folding is enabled. Default is true as per VSCode @@ -357,7 +357,7 @@ public void Update( /// Additional settings from the Language Client that affect Language Server operations but /// do not exist under the 'powershell' section /// - public class EditorFileSettings + internal class EditorFileSettings { /// /// Exclude files globs consists of hashtable with the key as the glob and a boolean value to indicate if the @@ -370,7 +370,7 @@ public class EditorFileSettings /// Additional settings from the Language Client that affect Language Server operations but /// do not exist under the 'powershell' section /// - public class EditorSearchSettings + internal class EditorSearchSettings { /// /// Exclude files globs consists of hashtable with the key as the glob and a boolean value to indicate if the @@ -383,7 +383,7 @@ public class EditorSearchSettings public bool FollowSymlinks { get; set; } = true; } - public class LanguageServerSettingsWrapper + internal class LanguageServerSettingsWrapper { // NOTE: This property is capitalized as 'Powershell' because the // mode name sent from the client is written as 'powershell' and diff --git a/src/PowerShellEditorServices/Services/Workspace/WorkspaceFileSystemWrapper.cs b/src/PowerShellEditorServices/Services/Workspace/WorkspaceFileSystemWrapper.cs index 89335db09..2e5ebfc9e 100644 --- a/src/PowerShellEditorServices/Services/Workspace/WorkspaceFileSystemWrapper.cs +++ b/src/PowerShellEditorServices/Services/Workspace/WorkspaceFileSystemWrapper.cs @@ -19,7 +19,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.Workspace /// with a maximum recursion depth and silently ignores most file system errors. Typically this is used by the /// Microsoft.Extensions.FileSystemGlobbing library. /// - public class WorkspaceFileSystemWrapperFactory + internal class WorkspaceFileSystemWrapperFactory { private readonly DirectoryInfoBase _rootDirectory; private readonly string[] _allowedExtensions; @@ -179,7 +179,7 @@ internal IEnumerable SafeEnumerateFileSystemInfos(DirectoryInfo /// . /// Based on https://github.com/aspnet/Extensions/blob/c087cadf1dfdbd2b8785ef764e5ef58a1a7e5ed0/src/FileSystemGlobbing/src/Abstractions/DirectoryInfoWrapper.cs /// - public class WorkspaceFileSystemDirectoryWrapper : DirectoryInfoBase + internal class WorkspaceFileSystemDirectoryWrapper : DirectoryInfoBase { private readonly DirectoryInfo _concreteDirectoryInfo; private readonly bool _isParentPath; @@ -306,7 +306,7 @@ public override DirectoryInfoBase ParentDirectory /// /// Wraps an instance of to provide implementation of . /// - public class WorkspaceFileSystemFileInfoWrapper : FileInfoBase + internal class WorkspaceFileSystemFileInfoWrapper : FileInfoBase { private readonly FileInfo _concreteFileInfo; private readonly WorkspaceFileSystemWrapperFactory _fsWrapperFactory; diff --git a/src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs b/src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs index 6cff2008e..52e39c4bd 100644 --- a/src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs +++ b/src/PowerShellEditorServices/Services/Workspace/WorkspaceService.cs @@ -23,7 +23,7 @@ namespace Microsoft.PowerShell.EditorServices.Services /// Manages a "workspace" of script files that are open for a particular /// editing session. Also helps to navigate references between ScriptFiles. /// - public class WorkspaceService + internal class WorkspaceService { #region Private Fields diff --git a/src/PowerShellEditorServices/Utility/AsyncLock.cs b/src/PowerShellEditorServices/Utility/AsyncLock.cs index 65e92aa4f..aab8935ec 100644 --- a/src/PowerShellEditorServices/Utility/AsyncLock.cs +++ b/src/PowerShellEditorServices/Utility/AsyncLock.cs @@ -14,7 +14,7 @@ namespace Microsoft.PowerShell.EditorServices.Utility /// synchronization locking inside of async calls. Cannot be /// used recursively. /// - public class AsyncLock + internal class AsyncLock { #region Fields diff --git a/src/PowerShellEditorServices/Utility/AsyncQueue.cs b/src/PowerShellEditorServices/Utility/AsyncQueue.cs index 98cbed9bf..0232c0d9b 100644 --- a/src/PowerShellEditorServices/Utility/AsyncQueue.cs +++ b/src/PowerShellEditorServices/Utility/AsyncQueue.cs @@ -15,7 +15,7 @@ namespace Microsoft.PowerShell.EditorServices.Utility /// operations. This is primarily used for producer/consumer scenarios. /// /// The type of item contained in the queue. - public class AsyncQueue + internal class AsyncQueue { #region Private Fields diff --git a/test/PowerShellEditorServices.Test.Shared/Completion/CompleteAttributeValue.cs b/test/PowerShellEditorServices.Test.Shared/Completion/CompleteAttributeValue.cs index ceba353fd..c649e67ea 100644 --- a/test/PowerShellEditorServices.Test.Shared/Completion/CompleteAttributeValue.cs +++ b/test/PowerShellEditorServices.Test.Shared/Completion/CompleteAttributeValue.cs @@ -7,7 +7,7 @@ namespace Microsoft.PowerShell.EditorServices.Test.Shared.Completion { - public class CompleteAttributeValue + internal class CompleteAttributeValue { public static readonly ScriptRegion SourceDetails = new ScriptRegion( diff --git a/test/PowerShellEditorServices.Test.Shared/Completion/CompleteCommandFromModule.cs b/test/PowerShellEditorServices.Test.Shared/Completion/CompleteCommandFromModule.cs index bc5b2ff9d..e850a3590 100644 --- a/test/PowerShellEditorServices.Test.Shared/Completion/CompleteCommandFromModule.cs +++ b/test/PowerShellEditorServices.Test.Shared/Completion/CompleteCommandFromModule.cs @@ -8,7 +8,7 @@ namespace Microsoft.PowerShell.EditorServices.Test.Shared.Completion { - public class CompleteCommandFromModule + internal class CompleteCommandFromModule { private static readonly string[] s_getRandomParamSets = { "Get-Random [[-Maximum] ] [-SetSeed ] [-Minimum ] []", diff --git a/test/PowerShellEditorServices.Test.Shared/Completion/CompleteCommandInFile.cs b/test/PowerShellEditorServices.Test.Shared/Completion/CompleteCommandInFile.cs index a4d4b7576..6e8a2e73e 100644 --- a/test/PowerShellEditorServices.Test.Shared/Completion/CompleteCommandInFile.cs +++ b/test/PowerShellEditorServices.Test.Shared/Completion/CompleteCommandInFile.cs @@ -7,7 +7,7 @@ namespace Microsoft.PowerShell.EditorServices.Test.Shared.Completion { - public class CompleteCommandInFile + internal class CompleteCommandInFile { public static readonly ScriptRegion SourceDetails = new ScriptRegion( diff --git a/test/PowerShellEditorServices.Test.Shared/Completion/CompleteFilePath.cs b/test/PowerShellEditorServices.Test.Shared/Completion/CompleteFilePath.cs index 828b17061..3e6639ca5 100644 --- a/test/PowerShellEditorServices.Test.Shared/Completion/CompleteFilePath.cs +++ b/test/PowerShellEditorServices.Test.Shared/Completion/CompleteFilePath.cs @@ -7,7 +7,7 @@ namespace Microsoft.PowerShell.EditorServices.Test.Shared.Completion { - public class CompleteFilePath + internal class CompleteFilePath { public static readonly ScriptRegion SourceDetails = new ScriptRegion( diff --git a/test/PowerShellEditorServices.Test.Shared/Completion/CompleteVariableInFile.cs b/test/PowerShellEditorServices.Test.Shared/Completion/CompleteVariableInFile.cs index 92e38e8d8..d9f47ef84 100644 --- a/test/PowerShellEditorServices.Test.Shared/Completion/CompleteVariableInFile.cs +++ b/test/PowerShellEditorServices.Test.Shared/Completion/CompleteVariableInFile.cs @@ -7,7 +7,7 @@ namespace Microsoft.PowerShell.EditorServices.Test.Shared.Completion { - public class CompleteVariableInFile + internal class CompleteVariableInFile { public static readonly ScriptRegion SourceDetails = new ScriptRegion( diff --git a/test/PowerShellEditorServices.Test.Shared/PowerShellEditorServices.Test.Shared.csproj b/test/PowerShellEditorServices.Test.Shared/PowerShellEditorServices.Test.Shared.csproj index 84bf41ab8..d617352a9 100644 --- a/test/PowerShellEditorServices.Test.Shared/PowerShellEditorServices.Test.Shared.csproj +++ b/test/PowerShellEditorServices.Test.Shared/PowerShellEditorServices.Test.Shared.csproj @@ -12,4 +12,9 @@ true true + + + <_Parameter1>Microsoft.PowerShell.EditorServices.Test + + diff --git a/test/PowerShellEditorServices.Test/Console/ChoicePromptHandlerTests.cs b/test/PowerShellEditorServices.Test/Console/ChoicePromptHandlerTests.cs index 3dc6b47cc..90976669f 100644 --- a/test/PowerShellEditorServices.Test/Console/ChoicePromptHandlerTests.cs +++ b/test/PowerShellEditorServices.Test/Console/ChoicePromptHandlerTests.cs @@ -47,7 +47,7 @@ public void ChoicePromptReturnsCorrectIdForChoice() } [Trait("Category", "Prompt")] - [Fact] + [Fact(Skip = "Hotkeys are not exposed while VSCode ignores them")] public void ChoicePromptReturnsCorrectIdForHotKey() { TestChoicePromptHandler choicePromptHandler = new TestChoicePromptHandler(); diff --git a/test/PowerShellEditorServices.Test/Console/InputPromptHandlerTests.cs b/test/PowerShellEditorServices.Test/Console/InputPromptHandlerTests.cs index 9f4bb6a5d..96074c668 100644 --- a/test/PowerShellEditorServices.Test/Console/InputPromptHandlerTests.cs +++ b/test/PowerShellEditorServices.Test/Console/InputPromptHandlerTests.cs @@ -15,6 +15,9 @@ namespace Microsoft.PowerShell.EditorServices.Test.Console { + // TODO: Bring these tests back when we've mocked more of the O# LSP middleware + + /* public class InputPromptHandlerTests { const string NameField = "Name"; @@ -145,7 +148,7 @@ public Task ReturnInputString(string inputString) // TODO: refactor tests to not need this Delay. There seems to be a race condition // in how this test cleans up after SetResult is run. - return Task.Delay(100); + return Task.Delay(300); } public void ReturnSecureString(SecureString secureString) @@ -179,4 +182,5 @@ protected override void ShowErrorMessage(Exception e) this.LastError = e; } } + */ } diff --git a/test/PowerShellEditorServices.Test/Extensions/ExtensionCommandTests.cs b/test/PowerShellEditorServices.Test/Extensions/ExtensionCommandTests.cs new file mode 100644 index 000000000..08dbab382 --- /dev/null +++ b/test/PowerShellEditorServices.Test/Extensions/ExtensionCommandTests.cs @@ -0,0 +1,196 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.PowerShell.EditorServices.Extensions; +using Microsoft.PowerShell.EditorServices.Extensions.Services; +using Microsoft.PowerShell.EditorServices.Services; +using Microsoft.PowerShell.EditorServices.Services.TextDocument; +using Microsoft.PowerShell.EditorServices.Test.Shared; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Management.Automation; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.PowerShell.EditorServices.Test.Extensions +{ + // TODO: + // These tests require being able to instantiate a language server and use the service provider. + // Re-enable them when we have mocked out more infrastructure for testing. + + /* + public class ExtensionCommandTests : IDisposable + { + private readonly PowerShellContextService _powershellContextService; + + private readonly IExtensionCommandService _extensionCommandService; + + private readonly ExtensionService _extensionService; + + public ExtensionCommandTests() + { + _powershellContextService = PowerShellContextFactory.Create(NullLogger.Instance); + _extensionCommandService = EditorObject.Instance.GetExtensionServiceProvider().ExtensionCommands; + } + + [Trait("Category", "Extensions")] + [Fact] + public async Task CanRegisterAndInvokeCommandWithCmdletName() + { + string filePath = TestUtilities.NormalizePath("C:\\Temp\\Test.ps1"); + var currentFile = new ScriptFile(new Uri(filePath), "This is a test file", new Version("7.0")); + var editorContext = new EditorContext( + editorOperations: null, + currentFile, + new BufferPosition(line: 1, column: 1), + BufferRange.None); + + EditorCommand commandAdded = null; + _extensionCommandService.CommandAdded += (object sender, EditorCommand command) => + { + commandAdded = command; + }; + + string commandName = "test.function"; + string commandDisplayName = "Function extension"; + + + await _powershellContextService.ExecuteScriptStringAsync( + TestUtilities.NormalizeNewlines($@" +function Invoke-Extension {{ $global:testValue = 5 }} +Register-EditorCommand -Name {commandName} -DisplayName ""{commandDisplayName}"" -Function Invoke-Extension")); + + Assert.NotNull(commandAdded); + Assert.Equal(commandAdded.Name, commandName); + Assert.Equal(commandAdded.DisplayName, commandDisplayName); + + // Invoke the command + await _extensionCommandService.InvokeCommandAsync(commandName, editorContext); + + // Assert the expected value + PSCommand psCommand = new PSCommand().AddScript("$global:extensionValue"); + IEnumerable results = await _powershellContextService.ExecuteCommandAsync(psCommand); + Assert.Equal(5, results.FirstOrDefault()); + } + + [Trait("Category", "Extensions")] + [Fact] + public async Task CanRegisterAndInvokeCommandWithScriptBlock() + { + string filePath = TestUtilities.NormalizePath("C:\\Temp\\Test.ps1"); + var currentFile = new ScriptFile(new Uri(filePath), "This is a test file", new Version("7.0")); + var editorContext = new EditorContext( + editorOperations: null, + currentFile, + new BufferPosition(line: 1, column: 1), + BufferRange.None); + + + EditorCommand commandAdded = null; + _extensionCommandService.CommandAdded += (object sender, EditorCommand command) => + { + commandAdded = command; + }; + + + string commandName = "test.scriptblock"; + string commandDisplayName = "ScriptBlock extension"; + + await _powershellContextService.ExecuteCommandAsync(new PSCommand() + .AddCommand("Register-EditorCommand") + .AddParameter("Name", commandName) + .AddParameter("DisplayName", commandDisplayName) + .AddParameter("ScriptBlock", ScriptBlock.Create("$global:extensionValue = 10"))); + + Assert.NotNull(commandAdded); + Assert.Equal(commandName, commandAdded.Name); + Assert.Equal(commandDisplayName, commandAdded.DisplayName); + + // Invoke the command + await _extensionCommandService.InvokeCommandAsync("test.scriptblock", editorContext); + + // Assert the expected value + PSCommand psCommand = new PSCommand().AddScript("$global:extensionValue"); + IEnumerable results = await _powershellContextService.ExecuteCommandAsync(psCommand); + Assert.Equal(10, results.FirstOrDefault()); + } + + [Trait("Category", "Extensions")] + [Fact] + public async Task CanUpdateRegisteredCommand() + { + EditorCommand updatedCommand = null; + _extensionCommandService.CommandUpdated += (object sender, EditorCommand command) => + { + updatedCommand = command; + }; + + string commandName = "test.function"; + string commandDisplayName = "Updated function extension"; + + // Register a command and then update it + await _powershellContextService.ExecuteScriptStringAsync(TestUtilities.NormalizeNewlines( + "function Invoke-Extension { Write-Output \"Extension output!\" }\n" + + $"Register-EditorCommand -Name \"{commandName}\" -DisplayName \"Old function extension\" -Function \"Invoke-Extension\"\n" + + $"Register-EditorCommand -Name \"{commandName}\" -DisplayName \"{commandDisplayName}\" -Function \"Invoke-Extension\"")); + + // Wait for the add and update events + Assert.NotNull(updatedCommand); + Assert.Equal(commandName, updatedCommand.Name); + Assert.Equal(commandDisplayName, updatedCommand.DisplayName); + } + + [Trait("Category", "Extensions")] + [Fact] + public async Task CanUnregisterCommand() + { + string filePath = TestUtilities.NormalizePath("C:\\Temp\\Test.ps1"); + var currentFile = new ScriptFile(new Uri(filePath), "This is a test file", new Version("7.0")); + var editorContext = new EditorContext( + editorOperations: null, + currentFile, + new BufferPosition(line: 1, column: 1), + BufferRange.None); + + string commandName = "test.scriptblock"; + string commandDisplayName = "ScriptBlock extension"; + + EditorCommand removedCommand = null; + _extensionCommandService.CommandRemoved += (object sender, EditorCommand command) => + { + removedCommand = command; + }; + + // Add the command and wait for the add event + await _powershellContextService.ExecuteCommandAsync(new PSCommand() + .AddCommand("Register-EditorCommand") + .AddParameter("Name", commandName) + .AddParameter("DisplayName", commandDisplayName) + .AddParameter("ScriptBlock", ScriptBlock.Create("Write-Output \"Extension output!\""))); + + // Remove the command and wait for the remove event + await _powershellContextService.ExecuteCommandAsync(new PSCommand() + .AddCommand("Unregister-EditorCommand") + .AddParameter("Name", commandName)); + + Assert.NotNull(removedCommand); + Assert.Equal(commandName, removedCommand.Name); + Assert.Equal(commandDisplayName, removedCommand.DisplayName); + + // Ensure that the command has been unregistered + await Assert.ThrowsAsync(() => + _extensionCommandService.InvokeCommandAsync("test.scriptblock", editorContext)); + } + + public void Dispose() + { + _powershellContextService.Dispose(); + } + } + */ +} + diff --git a/test/PowerShellEditorServices.Test/Extensions/ExtensionServiceTests.cs b/test/PowerShellEditorServices.Test/Extensions/ExtensionServiceTests.cs deleted file mode 100644 index b45544efb..000000000 --- a/test/PowerShellEditorServices.Test/Extensions/ExtensionServiceTests.cs +++ /dev/null @@ -1,268 +0,0 @@ -// TODO: Bring this back with API refactor. - -// // -// // Copyright (c) Microsoft. All rights reserved. -// // Licensed under the MIT license. See LICENSE file in the project root for full license information. -// // - -// using Microsoft.Extensions.Logging.Abstractions; -// using Microsoft.PowerShell.EditorServices.Services; -// using Microsoft.PowerShell.EditorServices.Services.PowerShellContext; -// using Microsoft.PowerShell.EditorServices.Services.TextDocument; -// using Microsoft.PowerShell.EditorServices.Test.Shared; -// using Microsoft.PowerShell.EditorServices.Utility; -// using System; -// using System.Collections.Generic; -// using System.Linq; -// using System.Management.Automation; -// using System.Threading; -// using System.Threading.Tasks; -// using Xunit; - -// namespace Microsoft.PowerShell.EditorServices.Test.Extensions -// { -// public class ExtensionServiceTests : IAsyncLifetime -// { -// private ScriptFile currentFile; -// private EditorContext commandContext; -// private ExtensionService extensionService; -// private PowerShellContextService powerShellContext; -// private TestEditorOperations editorOperations; - -// private AsyncQueue> extensionEventQueue = -// new AsyncQueue>(); - -// private enum EventType -// { -// Add, -// Update, -// Remove -// } - -// public async Task InitializeAsync() -// { -// var logger = NullLogger.Instance; -// this.powerShellContext = PowerShellContextFactory.Create(logger); -// await this.powerShellContext.ImportCommandsModuleAsync( -// TestUtilities.NormalizePath("../../../../../module/PowerShellEditorServices/Commands")); - -// this.extensionService = new ExtensionService(this.powerShellContext, null); -// this.editorOperations = new TestEditorOperations(); - -// this.extensionService.CommandAdded += ExtensionService_ExtensionAdded; -// this.extensionService.CommandUpdated += ExtensionService_ExtensionUpdated; -// this.extensionService.CommandRemoved += ExtensionService_ExtensionRemoved; - -// await this.extensionService.InitializeAsync( -// serviceProvider: null, -// this.editorOperations); - -// var filePath = TestUtilities.NormalizePath("c:/Test/Test.ps1"); -// this.currentFile = new ScriptFile(new Uri(filePath), "This is a test file", new Version("5.0")); -// this.commandContext = -// new EditorContext( -// this.editorOperations, -// currentFile, -// new BufferPosition(1, 1), -// BufferRange.None); -// } - -// public Task DisposeAsync() -// { -// this.powerShellContext.Dispose(); -// return Task.FromResult(true); -// } - -// [Trait("Category", "Extensions")] -// [Fact] -// public async Task CanRegisterAndInvokeCommandWithCmdletName() -// { -// await extensionService.PowerShellContext.ExecuteScriptStringAsync( -// TestUtilities.NormalizeNewlines("function Invoke-Extension { $global:extensionValue = 5 }\n") + -// "Register-EditorCommand -Name \"test.function\" -DisplayName \"Function extension\" -Function \"Invoke-Extension\""); - -// // Wait for the add event -// EditorCommand command = await this.AssertExtensionEvent(EventType.Add, "test.function"); - -// // Invoke the command -// await extensionService.InvokeCommandAsync("test.function", this.commandContext); - -// // Assert the expected value -// PSCommand psCommand = new PSCommand(); -// psCommand.AddScript("$global:extensionValue"); -// var results = await powerShellContext.ExecuteCommandAsync(psCommand); -// Assert.Equal(5, results.FirstOrDefault()); -// } - -// [Trait("Category", "Extensions")] -// [Fact] -// public async Task CanRegisterAndInvokeCommandWithScriptBlock() -// { -// await extensionService.PowerShellContext.ExecuteScriptStringAsync( -// "Register-EditorCommand -Name \"test.scriptblock\" -DisplayName \"ScriptBlock extension\" -ScriptBlock { $global:extensionValue = 10 }"); - -// // Wait for the add event -// EditorCommand command = await this.AssertExtensionEvent(EventType.Add, "test.scriptblock"); - -// // Invoke the command -// await extensionService.InvokeCommandAsync("test.scriptblock", this.commandContext); - -// // Assert the expected value -// PSCommand psCommand = new PSCommand(); -// psCommand.AddScript("$global:extensionValue"); -// var results = await powerShellContext.ExecuteCommandAsync(psCommand); -// Assert.Equal(10, results.FirstOrDefault()); -// } - -// [Trait("Category", "Extensions")] -// [Fact] -// public async Task CanUpdateRegisteredCommand() -// { -// // Register a command and then update it -// await extensionService.PowerShellContext.ExecuteScriptStringAsync(TestUtilities.NormalizeNewlines( -// "function Invoke-Extension { Write-Output \"Extension output!\" }\n" + -// "Register-EditorCommand -Name \"test.function\" -DisplayName \"Function extension\" -Function \"Invoke-Extension\"\n" + -// "Register-EditorCommand -Name \"test.function\" -DisplayName \"Updated Function extension\" -Function \"Invoke-Extension\"")); - -// // Wait for the add and update events -// await this.AssertExtensionEvent(EventType.Add, "test.function"); -// EditorCommand updatedCommand = await this.AssertExtensionEvent(EventType.Update, "test.function"); - -// Assert.Equal("Updated Function extension", updatedCommand.DisplayName); -// } - -// [Trait("Category", "Extensions")] -// [Fact] -// public async Task CanUnregisterCommand() -// { -// // Add the command and wait for the add event -// await extensionService.PowerShellContext.ExecuteScriptStringAsync( -// "Register-EditorCommand -Name \"test.scriptblock\" -DisplayName \"ScriptBlock extension\" -ScriptBlock { Write-Output \"Extension output!\" }"); -// await this.AssertExtensionEvent(EventType.Add, "test.scriptblock"); - -// // Remove the command and wait for the remove event -// await extensionService.PowerShellContext.ExecuteScriptStringAsync( -// "Unregister-EditorCommand -Name \"test.scriptblock\""); -// await this.AssertExtensionEvent(EventType.Remove, "test.scriptblock"); - -// // Ensure that the command has been unregistered -// await Assert.ThrowsAsync(() => -// extensionService.InvokeCommandAsync("test.scriptblock", this.commandContext)); -// } - -// private async Task AssertExtensionEvent(EventType expectedEventType, string expectedExtensionName) -// { -// var eventExtensionTuple = -// await this.extensionEventQueue.DequeueAsync( -// new CancellationTokenSource(5000).Token); - -// Assert.Equal(expectedEventType, eventExtensionTuple.Item1); -// Assert.Equal(expectedExtensionName, eventExtensionTuple.Item2.Name); - -// return eventExtensionTuple.Item2; -// } - -// private async void ExtensionService_ExtensionAdded(object sender, EditorCommand e) -// { -// await this.extensionEventQueue.EnqueueAsync( -// new Tuple(EventType.Add, e)); -// } - -// private async void ExtensionService_ExtensionUpdated(object sender, EditorCommand e) -// { -// await this.extensionEventQueue.EnqueueAsync( -// new Tuple(EventType.Update, e)); -// } - -// private async void ExtensionService_ExtensionRemoved(object sender, EditorCommand e) -// { -// await this.extensionEventQueue.EnqueueAsync( -// new Tuple(EventType.Remove, e)); -// } -// } - -// public class TestEditorOperations : IEditorOperations -// { - -// public string GetWorkspacePath() -// { -// throw new NotImplementedException(); -// } - -// public string GetWorkspaceRelativePath(string filePath) -// { -// throw new NotImplementedException(); -// } - -// public Task NewFileAsync() -// { -// throw new NotImplementedException(); -// } - -// public Task OpenFileAsync(string filePath) -// { -// throw new NotImplementedException(); -// } - -// public Task OpenFileAsync(string filePath, bool preview) -// { -// throw new NotImplementedException(); -// } - -// public Task CloseFileAsync(string filePath) -// { -// throw new NotImplementedException(); -// } - -// public Task SaveFileAsync(string filePath) -// { -// return SaveFileAsync(filePath, null); -// } - -// public Task SaveFileAsync(string filePath, string newSavePath) -// { -// throw new NotImplementedException(); -// } - -// public Task InsertTextAsync(string filePath, string text, BufferRange insertRange) -// { -// throw new NotImplementedException(); -// } - -// public Task SetSelectionAsync(BufferRange selectionRange) -// { -// throw new NotImplementedException(); -// } - -// public Task GetEditorContextAsync() -// { -// throw new NotImplementedException(); -// } - -// public Task ShowInformationMessageAsync(string message) -// { -// throw new NotImplementedException(); -// } - -// public Task ShowErrorMessageAsync(string message) -// { -// throw new NotImplementedException(); -// } - -// public Task ShowWarningMessageAsync(string message) -// { -// throw new NotImplementedException(); -// } - -// public Task SetStatusBarMessageAsync(string message, int? timeout) -// { -// throw new NotImplementedException(); -// } - -// public void ClearTerminal() -// { -// throw new NotImplementedException(); -// } -// } -// } - diff --git a/test/PowerShellEditorServices.Test/PowerShellContextFactory.cs b/test/PowerShellEditorServices.Test/PowerShellContextFactory.cs index 5d92576e8..17d02c5ed 100644 --- a/test/PowerShellEditorServices.Test/PowerShellContextFactory.cs +++ b/test/PowerShellEditorServices.Test/PowerShellContextFactory.cs @@ -64,7 +64,7 @@ public static PowerShellContextService Create(ILogger logger) } } - public class TestPSHostUserInterface : EditorServicesPSHostUserInterface + internal class TestPSHostUserInterface : EditorServicesPSHostUserInterface { public TestPSHostUserInterface( PowerShellContextService powerShellContext, diff --git a/test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs b/test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs index 8ef4d74c9..98f06a1aa 100644 --- a/test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs +++ b/test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs @@ -48,7 +48,7 @@ public void CanResolveWorkspaceRelativePath() Assert.Equal(testPathAnotherDrive, workspace.GetRelativePath(testPathAnotherDrive)); } - public static WorkspaceService FixturesWorkspace() + internal static WorkspaceService FixturesWorkspace() { return new WorkspaceService(NullLoggerFactory.Instance) { WorkspacePath = TestUtilities.NormalizePath("Fixtures/Workspace") @@ -62,7 +62,7 @@ public static WorkspaceService FixturesWorkspace() private static int s_defaultMaxDepth = 64; private static bool s_defaultIgnoreReparsePoints = false; - public static List ExecuteEnumeratePSFiles( + internal static List ExecuteEnumeratePSFiles( WorkspaceService workspace, string[] excludeGlobs, string[] includeGlobs,