Skip to content

Commit

Permalink
Close over public APIs not designed for exposure and add new safe APIs (
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmholt authored Feb 19, 2020
1 parent 140c976 commit 945d616
Show file tree
Hide file tree
Showing 139 changed files with 2,237 additions and 693 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
public class HostLogger :
public sealed class HostLogger :
IObservable<(PsesLogLevel logLevel, string message)>,
IObservable<(int logLevel, string message)>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface ISessionFileWriter
/// <summary>
/// The default session file writer, which uses PowerShell to write a session file.
/// </summary>
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public interface ITransportConfig
/// <summary>
/// Configuration for the standard input/output transport.
/// </summary>
public class StdioTransportConfig : ITransportConfig
public sealed class StdioTransportConfig : ITransportConfig
{
public string EndpointDetails => "<stdio>";

Expand All @@ -58,7 +58,7 @@ public class StdioTransportConfig : ITransportConfig
/// <summary>
/// Configuration for a full duplex named pipe.
/// </summary>
public class DuplexNamedPipeTransportConfig : ITransportConfig
public sealed class DuplexNamedPipeTransportConfig : ITransportConfig
{
/// <summary>
/// Create a duplex named pipe transport config with an automatically generated pipe name.
Expand Down Expand Up @@ -108,7 +108,7 @@ private DuplexNamedPipeTransportConfig(string pipeName)
/// <summary>
/// Configuration for two simplex named pipes.
/// </summary>
public class SimplexNamedPipeTransportConfig : ITransportConfig
public sealed class SimplexNamedPipeTransportConfig : ITransportConfig
{
private const string InPipePrefix = "in";
private const string OutPipePrefix = "out";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -20,8 +20,6 @@ public class NewVSCodeHtmlContentViewCommand : PSCmdlet
{
private HtmlContentViewsFeature _htmlContentViewsFeature;

private ILogger _logger;

private ViewColumn? _showInColumn;

///
Expand All @@ -44,13 +42,8 @@ protected override void BeginProcessing()
{
if (GetVariableValue("psEditor") is EditorObject psEditor)
{
_logger = psEditor.Components.GetService<ILoggerFactory>().CreateLogger("PowerShellEditorServices.VSCode");

_htmlContentViewsFeature = new HtmlContentViewsFeature(
psEditor.Components.GetService<ILanguageServer>(),
_logger);

_logger.LogInformation("PowerShell Editor Services VS Code module loaded.");
psEditor.GetExtensionServiceProvider().LanguageServer);
}
else
{
Expand Down
17 changes: 6 additions & 11 deletions src/PowerShellEditorServices.VSCode/CustomViews/CustomViewBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -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
{
Expand All @@ -50,7 +45,7 @@ await languageServer.SendRequest(

public async Task Show(ViewColumn viewColumn)
{
await languageServer.SendRequest(
await languageServer.SendRequestAsync(
ShowCustomViewRequest.Method,
new ShowCustomViewRequest
{
Expand All @@ -62,7 +57,7 @@ await languageServer.SendRequest(

public async Task Close()
{
await languageServer.SendRequest(
await languageServer.SendRequestAsync(
CloseCustomViewRequest.Method,
new CloseCustomViewRequest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TView>
where TView : ICustomView
{
protected ILanguageServer languageServer;
protected ILanguageServerService languageServer;

protected ILogger logger;
private readonly Dictionary<Guid, TView> viewIndex;

public CustomViewFeatureBase(
ILanguageServer languageServer,
ILogger logger)
ILanguageServerService languageServer)
{
this.viewIndex = new Dictionary<Guid, TView>();
this.languageServer = languageServer;
this.logger = logger;
}

protected void AddView(TView view)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,25 @@
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
{
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
{
Expand All @@ -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
{
Expand All @@ -60,7 +57,7 @@ await languageServer.SendRequest(

public async Task AppendContentAsync(string appendedHtmlBodyContent)
{
await languageServer.SendRequest(
await languageServer.SendRequestAsync(
AppendHtmlContentViewRequest.Method,
new AppendHtmlContentViewRequest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IHtmlContentView>, IHtmlContentViews
{
public HtmlContentViewsFeature(
ILanguageServer languageServer,
ILogger logger)
: base(languageServer, logger)
ILanguageServerService languageServer)
: base(languageServer)
{
}

Expand All @@ -23,8 +21,7 @@ public async Task<IHtmlContentView> CreateHtmlContentViewAsync(string viewTitle)
HtmlContentView htmlView =
new HtmlContentView(
viewTitle,
this.languageServer,
this.logger);
languageServer);

await htmlView.CreateAsync();
this.AddView(htmlView);
Expand Down
Loading

0 comments on commit 945d616

Please sign in to comment.