Skip to content

support $psEditor #1006

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 12 additions & 31 deletions PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,46 +51,27 @@ Schema is:
#>
$script:RequiredBuildAssets = @{
$script:ModuleBinPath = @{
'PowerShellEditorServices' = @(
'publish/Serilog.dll',
'publish/Serilog.Sinks.Async.dll',
'publish/Serilog.Sinks.Console.dll',
'publish/Serilog.Sinks.File.dll',
'publish/Microsoft.Extensions.FileSystemGlobbing.dll',
'Microsoft.PowerShell.EditorServices.dll',
'Microsoft.PowerShell.EditorServices.pdb'
)

'PowerShellEditorServices.Host' = @(
'publish/UnixConsoleEcho.dll',
'publish/runtimes/osx-64/native/libdisablekeyecho.dylib',
'publish/runtimes/linux-64/native/libdisablekeyecho.so',
'publish/Newtonsoft.Json.dll',
'Microsoft.PowerShell.EditorServices.Host.dll',
'Microsoft.PowerShell.EditorServices.Host.pdb'
)

'PowerShellEditorServices.Protocol' = @(
'Microsoft.PowerShell.EditorServices.Protocol.dll',
'Microsoft.PowerShell.EditorServices.Protocol.pdb'
)

'PowerShellEditorServices.Engine' = @(
'publish/Microsoft.Extensions.DependencyInjection.Abstractions.dll',
'publish/Microsoft.Extensions.DependencyInjection.dll',
'publish/Microsoft.Extensions.FileSystemGlobbing.dll',
'publish/Microsoft.Extensions.Logging.Abstractions.dll',
'publish/Microsoft.Extensions.Logging.dll',
'publish/Microsoft.Extensions.Options.dll',
'publish/Microsoft.Extensions.Primitives.dll',
'publish/Microsoft.PowerShell.EditorServices.Engine.dll',
'publish/Microsoft.PowerShell.EditorServices.Engine.pdb',
'publish/Newtonsoft.Json.dll',
'publish/OmniSharp.Extensions.JsonRpc.dll',
'publish/OmniSharp.Extensions.LanguageProtocol.dll',
'publish/OmniSharp.Extensions.LanguageServer.dll',
'publish/runtimes/linux-64/native/libdisablekeyecho.so',
'publish/runtimes/osx-64/native/libdisablekeyecho.dylib',
'publish/Serilog.dll',
'publish/Serilog.Extensions.Logging.dll',
'publish/Serilog.Sinks.File.dll',
'publish/Microsoft.Extensions.DependencyInjection.Abstractions.dll',
'publish/Microsoft.Extensions.DependencyInjection.dll',
'publish/Microsoft.Extensions.Logging.Abstractions.dll',
'publish/Microsoft.Extensions.Logging.dll',
'publish/Microsoft.Extensions.Options.dll',
'publish/Microsoft.Extensions.Primitives.dll',
'publish/System.Reactive.dll'
'publish/System.Reactive.dll',
'publish/UnixConsoleEcho.dll'
)
}

Expand Down
3 changes: 0 additions & 3 deletions module/PowerShellEditorServices/PowerShellEditorServices.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ if ($PSEdition -eq 'Desktop') {
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Desktop/System.Security.Principal.Windows.dll"
}

Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Microsoft.PowerShell.EditorServices.dll"
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Microsoft.PowerShell.EditorServices.Host.dll"
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Microsoft.PowerShell.EditorServices.Protocol.dll"
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Microsoft.PowerShell.EditorServices.Engine.dll"

function Start-EditorServicesHost {
Expand Down
93 changes: 55 additions & 38 deletions src/PowerShellEditorServices.Engine/Hosting/EditorServicesHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.PowerShell.EditorServices.Extensions;
using Serilog;

namespace Microsoft.PowerShell.EditorServices.Engine
Expand Down Expand Up @@ -233,6 +234,56 @@ public void StartLanguageService(

_logger.LogInformation($"LSP NamedPipe: {config.InOutPipeName}\nLSP OutPipe: {config.OutPipeName}");

var powerShellContext = GetFullyInitializedPowerShellContext(profilePaths);

_serviceCollection
.AddSingleton<WorkspaceService>()
.AddSingleton<SymbolsService>()
.AddSingleton<ConfigurationService>()
.AddSingleton<PowerShellContextService>(powerShellContext)
.AddSingleton<EditorOperationsService>()
.AddSingleton<ExtensionService>(
(provider) =>
{
var extensionService = new ExtensionService(
provider.GetService<PowerShellContextService>(),
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>());
extensionService.InitializeAsync(
serviceProvider: provider,
editorOperations: provider.GetService<EditorOperationsService>())
.Wait();
return extensionService;
})
.AddSingleton<AnalysisService>(
(provider) =>
{
return AnalysisService.Create(
provider.GetService<ConfigurationService>(),
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>(),
_factory.CreateLogger<AnalysisService>());
});

_languageServer = new OmnisharpLanguageServerBuilder(_serviceCollection)
{
NamedPipeName = config.InOutPipeName ?? config.InPipeName,
OutNamedPipeName = config.OutPipeName,
LoggerFactory = _factory,
MinimumLogLevel = LogLevel.Trace,
}
.BuildLanguageServer();

_logger.LogInformation("Starting language server");

Task.Run(_languageServer.StartAsync);

_logger.LogInformation(
string.Format(
"Language service started, type = {0}, endpoint = {1}",
config.TransportType, config.Endpoint));
}

private PowerShellContextService GetFullyInitializedPowerShellContext(ProfilePaths profilePaths)
{
var logger = _factory.CreateLogger<PowerShellContextService>();
var powerShellContext = new PowerShellContextService(
logger,
Expand All @@ -244,7 +295,7 @@ public void StartLanguageService(
// ? (EditorServicesPSHostUserInterface)new TerminalPSHostUserInterface(powerShellContext, logger, _internalHost)
// : new ProtocolPSHostUserInterface(powerShellContext, messageSender, logger);
EditorServicesPSHostUserInterface hostUserInterface =
(EditorServicesPSHostUserInterface)new TerminalPSHostUserInterface(powerShellContext, logger, _internalHost);
new TerminalPSHostUserInterface(powerShellContext, logger, _internalHost);


EditorServicesPSHost psHost =
Expand All @@ -267,51 +318,17 @@ public void StartLanguageService(
foreach (string module in this._additionalModules)
{
var command =
new System.Management.Automation.PSCommand()
new PSCommand()
.AddCommand("Microsoft.PowerShell.Core\\Import-Module")
.AddParameter("Name", module);

powerShellContext.ExecuteCommandAsync<System.Management.Automation.PSObject>(
powerShellContext.ExecuteCommandAsync<PSObject>(
command,
sendOutputToHost: false,
sendErrorToHost: true);
}

_serviceCollection
.AddSingleton<WorkspaceService>()
.AddSingleton<SymbolsService>()
.AddSingleton<ConfigurationService>()
.AddSingleton<PowerShellContextService>(powerShellContext)
.AddSingleton<AnalysisService>(
(provider) => {
return AnalysisService.Create(
provider.GetService<ConfigurationService>(),
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>(),
_factory.CreateLogger<AnalysisService>());
}
);

_languageServer = new OmnisharpLanguageServerBuilder(_serviceCollection)
{
NamedPipeName = config.InOutPipeName ?? config.InPipeName,
OutNamedPipeName = config.OutPipeName,
LoggerFactory = _factory,
MinimumLogLevel = LogLevel.Trace,
}
.BuildLanguageServer();

_logger.LogInformation("Starting language server");

Task.Run(_languageServer.StartAsync);
//Task.Factory.StartNew(() => _languageServer.StartAsync(),
// CancellationToken.None,
// TaskCreationOptions.LongRunning,
// TaskScheduler.Default);

_logger.LogInformation(
string.Format(
"Language service started, type = {0}, endpoint = {1}",
config.TransportType, config.Endpoint));
return powerShellContext;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using OmniSharp.Extensions.LanguageServer.Server;
using PowerShellEditorServices.Engine.Services.Handlers;
using Microsoft.PowerShell.EditorServices.TextDocument;
using System.IO;

namespace Microsoft.PowerShell.EditorServices.Engine
{
Expand Down Expand Up @@ -95,7 +96,26 @@ public async Task StartAsync()
.WithHandler<DocumentHighlightHandler>()
.WithHandler<PSHostProcessAndRunspaceHandlers>()
.WithHandler<CodeLensHandlers>()
.WithHandler<CodeActionHandler>();
.WithHandler<CodeActionHandler>()
.WithHandler<InvokeExtensionCommandHandler>()
.OnInitialize(
async (languageServer, request) =>
{
var serviceProvider = languageServer.Services;
var workspaceService = serviceProvider.GetService<WorkspaceService>();

// Grab the workspace path from the parameters
workspaceService.WorkspacePath = request.RootPath;

// Set the working directory of the PowerShell session to the workspace path
if (workspaceService.WorkspacePath != null
&& Directory.Exists(workspaceService.WorkspacePath))
{
await serviceProvider.GetService<PowerShellContextService>().SetWorkingDirectoryAsync(
workspaceService.WorkspacePath,
isPathAlreadyEscaped: false);
}
});

logger.LogInformation("Handlers added");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,7 @@
<PackageReference Include="System.IO.Pipes.AccessControl" Version="4.5.1" />
<PackageReference Include="System.Security.Principal" Version="4.3.0" />
<PackageReference Include="System.Security.Principal.Windows" Version="4.5.1" />
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="4.9.0" />
<PackageReference Include="UnixConsoleEcho" Version="0.1.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="Services\PowerShellContext\Session\" />
<Folder Include="Services\PowerShellContext\Console\" />
<Folder Include="Services\PowerShellContext\Extensions\" />
<Folder Include="Services\PowerShellContext\Components\" />
</ItemGroup>
</Project>

This file was deleted.

This file was deleted.

Loading