Code completion doesn't work as expected

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
chbwien
Posts: 5
Joined: Wed Apr 22, 2020 11:28 pm

Code completion doesn't work as expected

Post by chbwien »

If I use the following simple demo code:
  1. [xml]$xml = Get-Content 'inventory.xml'
  2.  
  3. foreach ($node in $xml.DocumentElement.Childnodes)
  4.  
  5. {
  6.  
  7.     $myjuhu = $xml.CreateElement('juhu')
  8.  
  9.     $myjuhu.innerText = 'juhu'
  10.  
  11.     [void]$node.appendchild($myjuhu)
  12.  
  13.     $node.removechild($myjuhu)
  14.  
  15. }
  16.  
  17. $xml.Save('inventory_out.xml')
I have no chance to get any help if I type $node.

If I do the same with the standard ISE, after the first run ISE knows the type of $node and it will offer me methods for $node.
2020-07-29 12_43_52-Windows PowerShell ISE.png
2020-07-29 12_43_52-Windows PowerShell ISE.png (65.65 KiB) Viewed 232 times
So what do I have to do, to get at least the same help from Powershell Studio?

User avatar
brittneyr
Site Admin
Posts: 540
Joined: Thu Jun 01, 2017 7:20 am

Re: Code completion doesn't work as expected

Post by brittneyr »

This is because it does not know what the type of $node is, therefore the editor does not know what information to provide via intellisense. As you casted the the result of Get-Content to xml, it was then recognized as xml and intellisense information was able to be provided. PowerShell Studio doesn't store information about the script after its run.

You may find the following helpful:
https://adamtheautomator.com/powershell-cast-object/
Brittney Ryn
SAPIEN Technologies, Inc.