Skip to content

Display variable's type name #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rkeithhill opened this issue Dec 12, 2015 · 3 comments
Closed

Display variable's type name #72

rkeithhill opened this issue Dec 12, 2015 · 3 comments
Labels
Issue-Enhancement A feature request (enhancement).

Comments

@rkeithhill
Copy link
Contributor

Visual Studio uses a three column grid to display a variable's name, value and type name. In VSCode we have a tree view and the tool window it is in is typically narrow. It is common to display variable name followed by its value. However PowerShell quite often has objects (composite variables) where the current variables display shows no value for objects.

I propose is that for expandable objects, we take advantage of the opportunity to display something. One option is the variable's short type name e.g.:

vscodevariabletypenames1

Of course since we've chosen to prefix variables with $ then perhaps we display type names using PowerShell syntax:
vscodevariabletypenames2

Another variation is to test the expandable object's ToString() return and if it is different than the type name, then display that instead. Here's an example of where this is useful. I can see the useful value of $pwd without having to open the node:
vscodevariabletypenames3
In this case, I think seeing the path (ToString() value) is more useful than seeing [PathInfo].

What are your thoughts on this? The implementation is a trivial change to VariableDetails.cs. Personally, I'm leaning towards the last example of using either the type name or ToString() if it is different.

@daviwil
Copy link
Contributor

daviwil commented Dec 12, 2015

I think this will be really useful, and I'd go with the "type name or ToString() if different" option as well. Thanks Keith!

@rkeithhill
Copy link
Contributor Author

Just about ready to check this in with a few additional goodies. We now display string types in double quotes. This helps you see empty strings easier and VSCode has nice syntax coloring for strings which also makes them stand out better.
vscodevariabletypenames4
Also note that we are looking specifically at one dimensional arrays and object's that implement ICollection and for those, we display the Length/Count of the array/collection. See the $args object array above contains 2 items.

Some collections like HashTable and ArrayList don't use [] in their type name, for those I'm using this approach ArrayList: 1 e.g. see the $PSVersionTable below:
vscodevariabletypenames5
Note that in the case of $pwd above, the path is displayed not as a string because the object is actually of type PathInfo so this helps distinguish true strings from objects with their own ToString representation.

I'll be submitting the PR shortly.

@rkeithhill rkeithhill added the Issue-Enhancement A feature request (enhancement). label Dec 12, 2015
rkeithhill added a commit to rkeithhill/PowerShellEditorServices that referenced this issue Dec 12, 2015
…mething useful. This is typically the short type name. However, for rank 1 arrays and objects implementing ICollection we now also display the number of items in the array/collection. Also changed objects of type string to display their value in double quotes.
@daviwil
Copy link
Contributor

daviwil commented Dec 12, 2015

Looks fantastic man! Checking out the PR now

daviwil added a commit that referenced this issue Dec 12, 2015
Addresses proposal #72 - for expandable objects, display something us…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement A feature request (enhancement).
Projects
None yet
Development

No branches or pull requests

2 participants