Skip to content

Commit 6aef7a2

Browse files
committed
Expose IComponentRegistry on the $psEditor object
This change exposes a property called Components on the $psEditor object which enables access to the PowerShell Editor Service framework interface implementations used in the current session.
1 parent 5f0a237 commit 6aef7a2

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ public void Start()
132132
// Initialize the extension service
133133
// TODO: This should be made awaited once Initialize is async!
134134
this.editorSession.ExtensionService.Initialize(
135-
this.editorOperations).Wait();
135+
this.editorOperations,
136+
this.editorSession.Components).Wait();
136137
}
137138

138139
protected Task Stop()

src/PowerShellEditorServices/Extensions/EditorObject.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
//
55

6+
using Microsoft.PowerShell.EditorServices.Components;
67
using System;
78
using System.Management.Automation;
89
using System.Reflection;
@@ -42,19 +43,28 @@ public Version EditorServicesVersion
4243
/// </summary>
4344
public EditorWindow Window { get; private set; }
4445

46+
/// <summary>
47+
/// Gets the component registry for the session.
48+
/// </summary>
49+
/// <returns></returns>
50+
public IComponentRegistry Components { get; private set; }
51+
4552
#endregion
4653

4754
/// <summary>
4855
/// Creates a new instance of the EditorObject class.
4956
/// </summary>
5057
/// <param name="extensionService">An ExtensionService which handles command registration.</param>
5158
/// <param name="editorOperations">An IEditorOperations implementation which handles operations in the host editor.</param>
59+
/// <param name="componentRegistry">An IComponentRegistry instance which provides components in the session.</param>
5260
public EditorObject(
5361
ExtensionService extensionService,
54-
IEditorOperations editorOperations)
62+
IEditorOperations editorOperations,
63+
IComponentRegistry componentRegistry)
5564
{
5665
this.extensionService = extensionService;
5766
this.editorOperations = editorOperations;
67+
this.Components = componentRegistry;
5868

5969
// Create API area objects
6070
this.Workspace = new EditorWorkspace(this.editorOperations);

src/PowerShellEditorServices/Extensions/ExtensionService.cs

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
//
55

6+
using Microsoft.PowerShell.EditorServices.Components;
67
using Microsoft.PowerShell.EditorServices.Utility;
78
using System;
89
using System.Collections.Generic;
@@ -68,10 +69,17 @@ public ExtensionService(PowerShellContext powerShellContext)
6869
/// implementation for future interaction with the host editor.
6970
/// </summary>
7071
/// <param name="editorOperations">An IEditorOperations implementation.</param>
72+
/// <param name="componentRegistry">An IComponentRegistry instance which provides components in the session.</param>
7173
/// <returns>A Task that can be awaited for completion.</returns>
72-
public async Task Initialize(IEditorOperations editorOperations)
74+
public async Task Initialize(
75+
IEditorOperations editorOperations,
76+
IComponentRegistry componentRegistry)
7377
{
74-
this.EditorObject = new EditorObject(this, editorOperations);
78+
this.EditorObject =
79+
new EditorObject(
80+
this,
81+
editorOperations,
82+
componentRegistry);
7583

7684
// Register the editor object in the runspace
7785
PSCommand variableCommand = new PSCommand();

test/PowerShellEditorServices.Test/Extensions/ExtensionServiceTests.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
//
55

6+
using Microsoft.PowerShell.EditorServices.Components;
67
using Microsoft.PowerShell.EditorServices.Extensions;
78
using Microsoft.PowerShell.EditorServices.Utility;
89
using System;
@@ -46,7 +47,9 @@ public async Task InitializeAsync()
4647
this.extensionService.CommandUpdated += ExtensionService_ExtensionUpdated;
4748
this.extensionService.CommandRemoved += ExtensionService_ExtensionRemoved;
4849

49-
await this.extensionService.Initialize(this.editorOperations);
50+
await this.extensionService.Initialize(
51+
this.editorOperations,
52+
new ComponentRegistry());
5053

5154
var filePath = @"c:\Test\Test.ps1";
5255
this.currentFile = new ScriptFile(filePath, filePath, "This is a test file", new Version("5.0"));

0 commit comments

Comments
 (0)