forked from PowerShell/PowerShellEditorServices
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-Token.ps1
More file actions
39 lines (36 loc) · 1.25 KB
/
Copy pathGet-Token.ps1
File metadata and controls
39 lines (36 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
function Get-Token {
<#
.EXTERNALHELP ..\PowerShellEditorServices.Commands-help.xml
#>
[CmdletBinding()]
[OutputType([System.Management.Automation.Language.Token])]
[System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseOutputTypeCorrectly', '', Justification='Issue #676')]
param(
[Parameter(Position=0, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.Language.IScriptExtent]
$Extent
)
process {
if (-not $Extent) {
if (-not $PSCmdlet.MyInvocation.ExpectingInput) {
# yield
$psEditor.GetEditorContext().CurrentFile.Tokens
}
return
}
$tokens = $psEditor.GetEditorContext().CurrentFile.Tokens
$predicate = [Func[System.Management.Automation.Language.Token, bool]]{
param($Token)
($Token.Extent.StartOffset -ge $Extent.StartOffset -and
$Token.Extent.EndOffset -le $Extent.EndOffset)
}
if ($tokens){
$result = [Linq.Enumerable]::Where($tokens, $predicate)
}
# yield
$result
}
}