I wanted to confirm whether the following is a bug or expected behaviour, before I submit anything to VS Code on GitHub.
I have a PowerShell script I'm working on thas has a few script level variables. Some of them are Hashtables with several properties each declared in block style:
$Script:VarOne = [ordered]@{
FirstProperty = ""
SecondProperty = ""
}
I noticed that the breadcrumbs section (right under the file name in the editor) will follow correctly when I'm on the line with the variable name. But, when my cursor is on any of the property lines, the variable name disappears from the breadcrumb. I took two screenshots to demonstrate:
In this one, my cursor is on line 99. The breadcrumb shows three folders, the script, and finally the variable.
In this one, my cursor in on line 100. The breadcrumb only shows the three folders and the script.
Has anyone else encountered this?
Thanks in advance.
ETA: Retook the screenshots and highlighted the difference between them. Also added the two-sentence captions above the screenshots.
I can't give you a design rationale, but I can describe the de-facto logic of how the PowerShell extension for Visual Studio Code manages its intra-script breadcrumb display:
Fundamentally, only the following elements are reflected as breadcrumbs:
Variables, on their first assignment in the file (that is, should the same variable be assigned to multiple times, only the first assignment is represented as a breadcrumb).
function
definitions
function
-internal variable does not get its own breadcrumb, even though the two variables are distinct and live in separate scopes.class
definitions as a whole, as well as their properties (member variables) and methods.
When you place the cursor inside (the first instance of) a variable-assignment statement, the breadcrumb for that variable is shown only if the cursor is inside or immediately before or after the variable name.
No breadcrumbs are defined for the value being assigned to a variable, even if that value is an object / hashtable literal with properties, as in your case.
It follows that, in an assignment statement, if you place the cursor anywhere on the RHS, i.e. anywhere from the =
symbol (or preceding whitespace) to the end of the value being assigned, you'll merely see the breadcrumb representing the enclosing scope:
The script's top-level scope is represented as …
, as shown in your screenshot (…
appears once at least one breadcrumb in that scope exists).
A function
scope's breadcrumb representation is function <name>()
A class
scope's breadcrumb representation is class <name>{}
, a property's (member variable's) is [<type-name>] $<name>
, and a method's is <type-name> <name>()
.