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
The Find-Ast function can be used to easily find a specific AST within a script file. All ASTs following the inital starting ast will be searched, including those that are not part of the same tree.
30
+
The Find-Ast function can be used to easily find a specific AST within a script file. All ASTs following the initial starting AST will be searched, including those that are not part of the same tree.
31
31
32
32
The behavior of the search (such as direction and criteria) can be changed with parameters.
33
33
34
-
Additionally, you can find the Ast closest to the cursor with the "AtCursor" switch parameter.
34
+
Additionally, you can find the AST closest to the cursor with the "AtCursor" switch parameter.
35
35
36
36
## EXAMPLES
37
37
@@ -41,23 +41,23 @@ Additionally, you can find the Ast closest to the cursor with the "AtCursor" swi
41
41
Find-Ast
42
42
```
43
43
44
-
Returns all asts in the currently open file in the editor.
44
+
Returns all ASTs in the currently open file in the editor.
45
45
46
46
### -------------------------- EXAMPLE 2 --------------------------
47
47
48
48
```powershell
49
49
Find-Ast -First -IncludeStartingAst
50
50
```
51
51
52
-
Returns the top level ast in the currently open file in the editor.
52
+
Returns the top level AST in the currently open file in the editor.
53
53
54
54
### -------------------------- EXAMPLE 3 --------------------------
55
55
56
56
```powershell
57
57
Find-Ast { $PSItem -is [FunctionDefinitionAst] }
58
58
```
59
59
60
-
Returns all function definition asts in the ast of file currently open in the editor.
60
+
Returns all function definition ASTs in the AST of file currently open in the editor.
61
61
62
62
### -------------------------- EXAMPLE 4 --------------------------
63
63
@@ -73,7 +73,7 @@ Returns all member expressions in the file currently open in the editor.
This example sets the required PowerShell version in a module manifest to 4.0.
87
87
88
-
First it finds the AST of the PowerShellVersion manifest field, then finds the first AST directly after it and changes the text to '4.0'. This will not work as is if the field is commented.
88
+
First it finds the AST of the PowerShellVersion manifest field, then finds the first AST directly after it and changes the text to '4.0'. This will not work if the field is commented.
89
89
90
90
### -------------------------- EXAMPLE 7 --------------------------
This example gets a list of all parameters that belong to the parameter set 'ByPosition'. First it uses the ArgumentName and Argument properties of NamedAttributeArgumentAst to find the ASTs of arguments to the Parameter attribute that declare the the parameter set 'ByPosition'. It then finds the closest parent ParameterAst and retrieves the name from it.
98
+
This example gets a list of all parameters that belong to the 'ByPosition' parameter set. First it uses the ArgumentName and Argument properties of NamedAttributeArgumentAst to find the ASTs of arguments to the Parameter attribute that declare the 'ByPosition' parameter set. It then finds the closest parent ParameterAst and retrieves the name from it.
99
99
100
100
### -------------------------- EXAMPLE 8 --------------------------
101
101
@@ -121,7 +121,7 @@ This example shows off ways you can combine the position functions together to g
121
121
122
122
### -FilterScript
123
123
124
-
Specifies a ScriptBlock that returns $true if an AST should be returned. Uses $PSItem and $_ like Where-Object. If not specified all ASTs will be returned.
124
+
Specifies a script block that returns $true if an AST should be returned. Uses $PSItem and $_ like Where-Object. If not specified all ASTs will be returned.
If specified will only search ancestors of the starting AST. This is a convenience parameter that acts the same as the "Family" and "Before" parameters when used together.
220
+
Searches only ancestors of the starting AST. This is a convenience parameter that acts the same as the "Family" and "Before" parameters when used together.
0 commit comments