From 47a359a20c2abcd046020bf62888bfc703cd6bea Mon Sep 17 00:00:00 2001 From: sk82jack Date: Sun, 24 Nov 2019 23:22:05 +0000 Subject: [PATCH 1/2] Fix extension service field name --- .../Commands/Public/Import-EditorCommand.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/PowerShellEditorServices/Commands/Public/Import-EditorCommand.ps1 b/module/PowerShellEditorServices/Commands/Public/Import-EditorCommand.ps1 index e57823a3f..a14d3e7d8 100644 --- a/module/PowerShellEditorServices/Commands/Public/Import-EditorCommand.ps1 +++ b/module/PowerShellEditorServices/Commands/Public/Import-EditorCommand.ps1 @@ -59,7 +59,7 @@ function Import-EditorCommand { } $flags = [Reflection.BindingFlags]'Instance, NonPublic' $extensionService = $psEditor.GetType(). - GetField('extensionService', $flags). + GetField('_extensionService', $flags). GetValue($psEditor) $editorCommands = $extensionService.GetType(). From c1678e368d90ba02efc225e2e17ac3d0699bd16b Mon Sep 17 00:00:00 2001 From: sk82jack Date: Mon, 25 Nov 2019 01:28:23 +0000 Subject: [PATCH 2/2] Get editor commands using API instead of reflection --- .../Commands/Public/Import-EditorCommand.ps1 | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/module/PowerShellEditorServices/Commands/Public/Import-EditorCommand.ps1 b/module/PowerShellEditorServices/Commands/Public/Import-EditorCommand.ps1 index a14d3e7d8..0a60dddeb 100644 --- a/module/PowerShellEditorServices/Commands/Public/Import-EditorCommand.ps1 +++ b/module/PowerShellEditorServices/Commands/Public/Import-EditorCommand.ps1 @@ -57,14 +57,11 @@ function Import-EditorCommand { return $moduleInfo.ExportedFunctions.Values } } - $flags = [Reflection.BindingFlags]'Instance, NonPublic' - $extensionService = $psEditor.GetType(). - GetField('_extensionService', $flags). - GetValue($psEditor) - - $editorCommands = $extensionService.GetType(). - GetField('editorCommands', $flags). - GetValue($extensionService) + $editorCommands = @{} + + foreach ($existingCommand in $psEditor.GetCommands()) { + $editorCommands[$existingCommand.Name] = $existingCommand + } } process { switch ($PSCmdlet.ParameterSetName) {