You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In VSCode, when attempting to use the cmdlets Register-VSCodeTreeView and New-VSCodeTreeViewItem, unexpected behavior occurs. The parent TreeView will usually be created, but it will often show up blank (see screenshots). However, any child items, whether created dynamically i.e. using the pipeline and automatic variables $_ or $PSItem, or with static values, I've never had them show up. If they do, they're almost always blank, only visible thanks to the last item having a visible collapse control (>) if -HasChildren was used. No other icon, description, or tooltip appears, however.
I realize the product has been sunsetted, and Universal is receiving more support at the moment, but the documentation around this feature is sorely lacking in explanation, only containing two example uses and a short video. Worse still, the examples provided, copied verbatim, don't work as shown. However, if support is to continue for a year, I'd very much like this fixed, as PowerShell Pro Tools is basically the best PowerShell value-add for VSCode beyond the official extension (echoing Justin Grote's comments in issue #43 ).
I really love the idea of a custom treeview, as I've wanted to create a better in-app help system for cmdlets, so short of learning Typescript and creating my own extension (a tall ask as I'm more scripter than actual programmer), this seemed like the perfect middle ground to iterate commands by module and verb, and then invoke the online link or Get-Help -ShowWindow, or possibly display the associated markdown from the PS Github in the case of about_ topics. Alas, I've gotten the same results across three devices (see below for version details).
Of course, it's entirely possible I don't really understand how these cmdlets and their associated types work, but when the examples fail, something must be wrong.
Expected behavior
Essentially, exactly what is pictured in the video at the feature's documentation page. I'm only trying to get the samples working at this point before doing anything more involved.
Actual behavior
Either a single parent item is created with no visible children (see screenshot) — sometimes with no visible text — or with blank child items, where only the last TreeItem in the list is selectable/expandable, but still blank otherwise. Clicking Refresh, or directly calling [PowerShellToolsPro.VSCode.TreeViewService]::Instance.RefreshTreeView(treeViewId) will often do nothing, and sometimes on the second attempt it clears all items from the view and will not accept further additions, rendering it unusable until the extension is restarted. This is beyond aggravating, especially because I can call [PowerShellToolsPro.VSCode.TreeViewService]::Instance.GetTreeViews() and see the view(s) I created with their correct properties listed.
Even more strangely, despite seeing the TreeView items exist as mentioned above, the log output often produces an exception on refresh, mentioning "Sequence contains no elements". Calling the same method directly produces an InvalidOperation exception:
InvalidOperation: An error occurred while enumerating through a collection: Object reference not set to an instance of an object..
Output Log when Refreshing the Custom View
[20:11:41.912] Scheduling command for main runspace: [PowerShellToolsPro.VSCode.TreeViewService]::Instance.GetTreeViews() | ConvertTo-Json -WarningAction SilentlyContinue
[20:11:41.925] Scheduling command for main runspace: [PowerShellToolsPro.VSCode.TreeViewService]::Instance.LoadChildren('TreeView1', '') | ConvertTo-Json -WarningAction SilentlyContinue
[20:11:42.249] Exception running command: $LoadChildren System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.InvalidOperationException: Sequence contains no elements
at System.Linq.ThrowHelper.ThrowNoElementsException()
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
at PowerShellToolsPro.PoshToolsServer.LoadChildren(String treeViewId, String path) in D:\a\powershell-pro-tools\powershell-pro-tools\HostInjection\PoshToolsServer.cs:line 768
at InvokeStub_PoshToolsServer.LoadChildren(Object, Span`1)
at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
--- End of inner exception stack trace ---
at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at PowerShellToolsPro.PoshToolsServer.Start(String pipeName) in D:\a\powershell-pro-tools\powershell-pro-tools\HostInjection\PoshToolsServer.cs:line 130
The output I was able to get once with the following code is also pictured, which is the closest I've gotten to anything usable. However, after running it once, even after refreshing, I could no longer get it to work. Only the initial TreeView would show with no child TreeItems.
Describe the bug
In VSCode, when attempting to use the cmdlets Register-VSCodeTreeView and New-VSCodeTreeViewItem, unexpected behavior occurs. The parent TreeView will usually be created, but it will often show up blank (see screenshots). However, any child items, whether created dynamically i.e. using the pipeline and automatic variables
$_
or$PSItem
, or with static values, I've never had them show up. If they do, they're almost always blank, only visible thanks to the last item having a visible collapse control (>) if-HasChildren
was used. No other icon, description, or tooltip appears, however.I realize the product has been sunsetted, and Universal is receiving more support at the moment, but the documentation around this feature is sorely lacking in explanation, only containing two example uses and a short video. Worse still, the examples provided, copied verbatim, don't work as shown. However, if support is to continue for a year, I'd very much like this fixed, as PowerShell Pro Tools is basically the best PowerShell value-add for VSCode beyond the official extension (echoing Justin Grote's comments in issue #43 ).
I really love the idea of a custom treeview, as I've wanted to create a better in-app help system for cmdlets, so short of learning Typescript and creating my own extension (a tall ask as I'm more scripter than actual programmer), this seemed like the perfect middle ground to iterate commands by module and verb, and then invoke the online link or
Get-Help -ShowWindow
, or possibly display the associated markdown from the PS Github in the case of about_ topics. Alas, I've gotten the same results across three devices (see below for version details).Of course, it's entirely possible I don't really understand how these cmdlets and their associated types work, but when the examples fail, something must be wrong.
Expected behavior
Essentially, exactly what is pictured in the video at the feature's documentation page. I'm only trying to get the samples working at this point before doing anything more involved.
Actual behavior
Either a single parent item is created with no visible children (see screenshot) — sometimes with no visible text — or with blank child items, where only the last TreeItem in the list is selectable/expandable, but still blank otherwise. Clicking Refresh, or directly calling
[PowerShellToolsPro.VSCode.TreeViewService]::Instance.RefreshTreeView(treeViewId)
will often do nothing, and sometimes on the second attempt it clears all items from the view and will not accept further additions, rendering it unusable until the extension is restarted. This is beyond aggravating, especially because I can call[PowerShellToolsPro.VSCode.TreeViewService]::Instance.GetTreeViews()
and see the view(s) I created with their correct properties listed.Even more strangely, despite seeing the TreeView items exist as mentioned above, the log output often produces an exception on refresh, mentioning "Sequence contains no elements". Calling the same method directly produces an InvalidOperation exception:
Output Log when Refreshing the Custom View
Version
Personal Tablet
Personal Desktop
Work VM
Steps to Reproduce
Steps to reproduce the behavior:
The output I was able to get once with the following code is also pictured, which is the closest I've gotten to anything usable. However, after running it once, even after refreshing, I could no longer get it to work. Only the initial TreeView would show with no child TreeItems.
Screenshots
The typical result when trying to add a TreeView
The one time I was able to get visible, invokable child TreeItems
The text was updated successfully, but these errors were encountered: