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
You can pipe IScriptExtent objects to be converted.
134
+
You can pass ScriptExtent objects to this function. You can also pass objects with a property named "Extent" such as ASTs from Find-Ast or tokens from Get-Token.
Converts position and range objects from PowerShellEditorServices to ScriptExtent objects.
44
+
The ConvertTo-ScriptExtent function can be used to convert any object with position related properties to a ScriptExtent object. You can also specify the parameters directly to manually create ScriptExtent objects.
45
45
46
46
## EXAMPLES
47
47
@@ -51,17 +51,25 @@ Converts position and range objects from PowerShellEditorServices to ScriptExten
Returns a ScriptExtent object from a start and end offset.
55
63
56
64
## PARAMETERS
57
65
58
-
### -InputObject
66
+
### -Extent
59
67
60
-
This is here so we can pass script extent objects through without any processing.
68
+
Specifies a ScriptExtent object to use as a base to create a new editor context aware ScriptExtent object.
61
69
62
70
```yaml
63
71
Type: IScriptExtent
64
-
Parameter Sets: ByObject
72
+
Parameter Sets: ByExtent
65
73
Aliases:
66
74
67
75
Required: False
@@ -223,29 +231,23 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
223
231
224
232
### System.Object
225
233
226
-
You can pass any object with any of the following properties.
234
+
You can pass any object with properties that have position related names. Below is a list of all the property names that can be bound as parameters through the pipeline.
The Find-Ast function can be used to easily find a specific ast from a starting ast. By default children asts will be searched, but ancestor asts can also be searched by specifying the "Ancestor" switch parameter.
30
+
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.
31
+
32
+
The behavior of the search (such as direction and criteria) can be changed with parameters.
31
33
32
34
Additionally, you can find the Ast closest to the cursor with the "AtCursor" switch parameter.
33
35
@@ -76,16 +78,50 @@ Returns all variable expressions used in a dot source expression.
76
78
### -------------------------- EXAMPLE 6 --------------------------
This example sets the required PowerShell version in a module manifest to 4.0.
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.
89
+
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.
99
+
100
+
### -------------------------- EXAMPLE 8 --------------------------
First finds the ast of the PowerShellVersion manifest tag, then finds the first ast after it and changes the text to '4.0'. This will not work as is if the field is commented.
118
+
This example shows off ways you can combine the position functions together to get very specific portions of a script file. The result of this example is a ScriptExtent that includes a manifest field, value, and all comments above it.
83
119
84
120
## PARAMETERS
85
121
86
122
### -FilterScript
87
123
88
-
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 ScriptBlock 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
+
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.
@@ -30,6 +30,8 @@ The Import-EditorCommand function will search the specified module for functions
30
30
31
31
Alternatively, you can specify command info objects (like those from the Get-Command cmdlet) to be processed directly.
32
32
33
+
To tag a command as an editor command, attach the attribute 'Microsoft.PowerShell.EditorServices.Extensions.EditorCommandAttribute' to the function like you would with 'CmdletBindingAttribute'. The attribute accepts the named parameters 'Name', 'DisplayName', and 'SuppressOutput'.
34
+
33
35
## EXAMPLES
34
36
35
37
### -------------------------- EXAMPLE 1 --------------------------
0 commit comments