Repository navigation
Fix Import-EditorCommand bug - #1114
Conversation
| GetField('_extensionService', $flags). | ||
| GetValue($psEditor) | ||
|
|
||
| $editorCommands = $extensionService.GetType(). |
There was a problem hiding this comment.
Actually you can replace all of these with $editorCommands = $psEditor.GetCommands(). That API didn't exist at the time, but now that it does that should definitely be used instead.
There was a problem hiding this comment.
Ah yeah that looks a lot nicer. I can change it to that but I'm not sure about the correct procedure in terms of not cluttering up the commit history - should I do an interactive rebase to clean up or leave it up to the maintainer to squash & merge?
There was a problem hiding this comment.
leave it up to the maintainer to squash & merge?
That one :)
Also taking a closer look you'll probably want to do something like:
$editorCommands = [System.Collections.Generic.Dictionary[string, Microsoft.PowerShell.EditorServices.Services.PowerShellContext.EditorCommand]]::new(
[System.StringComparer]::OrdinalIgnoreCase)
foreach ($existingCommand in $psEditor.GetCommands()) {
$editorCommands.Add($existingCommand.Name, $existingCommand)
}Optionally add some using namespace statements to clean it up a bit.
There was a problem hiding this comment.
Thanks for the pointers - will get that implemented and confirm it all still works
Out of interest why do you suggest a strongly typed dictionary over a regular hashtable? Performance or just clearer intent/more control or something?
There was a problem hiding this comment.
Actually I was just matching the type of the field, hashtable will probably work just fine and be a bit more clean. Good call :)
There was a problem hiding this comment.
Awesome. Just pushed new version 🙂
TylerLeonhardt
left a comment
There was a problem hiding this comment.
No more reflection 🎉 LGTM
It appears that PR #1056 involved renaming the
extensionServicefield to_extensionServicebut this wasn't changed in theImport-EditorCommandfunction causing an error when trying to use it.Following a discussion with TylerLeonhardt on the PowerShell Discord server I've submitted this PR to fix the error by updating the field name in
Import-EditorCommand.I didn't see any tests or anything that needed to be changed but let me know if you need me to do anything else in order for this to be accepted 🙂