-
Notifications
You must be signed in to change notification settings - Fork 234
Add position function set to Commands #496
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
Merged
daviwil
merged 9 commits into
PowerShell:master
from
SeeminglyScience:add-commands-functions
Jun 8, 2017
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8eeecc2
Add position classes for new functions
SeeminglyScience a17fca9
Add EditorCommandAttribute class
SeeminglyScience 4322fe1
Add functions ported from PSESHL
SeeminglyScience 5bc6c29
Fix module loading process
SeeminglyScience 7c6743e
Add markdown help
SeeminglyScience 34b5764
A few minor fixes
SeeminglyScience 48abc14
Help and manifest fixes
SeeminglyScience e1e629e
Add platyPS to appveyor
SeeminglyScience cadc4bd
Add platyPS to travis
SeeminglyScience File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 6 additions & 2 deletions
8
module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psm1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
Import-LocalizedData -BindingVariable Strings -FileName Strings | ||
|
||
# TODO: Use a better script loading process here | ||
. $PSScriptRoot\Public\CmdletInterface.ps1 | ||
Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 | ForEach-Object { | ||
. $PSItem.FullName | ||
} | ||
|
||
Export-ModuleMember -Function *-* |
28 changes: 28 additions & 0 deletions
28
module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.types.ps1xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<Types> | ||
<Type> | ||
<Name>Microsoft.PowerShell.EditorServices.FullScriptExtent</Name> | ||
<Members> | ||
<MemberSet> | ||
<Name>PSStandardMembers</Name> | ||
<Members> | ||
<PropertySet> | ||
<Name>DefaultDisplayPropertySet</Name> | ||
<ReferencedProperties> | ||
<Name>File</Name> | ||
<Name>StartScriptPosition</Name> | ||
<Name>EndScriptPosition</Name> | ||
<Name>StartLineNumber</Name> | ||
<Name>StartColumnNumber</Name> | ||
<Name>EndLineNumber</Name> | ||
<Name>EndColumnNumber</Name> | ||
<Name>StartOffset</Name> | ||
<Name>EndOffset</Name> | ||
<Name>Text</Name> | ||
</ReferencedProperties> | ||
</PropertySet> | ||
</Members> | ||
</MemberSet> | ||
</Members> | ||
</Type> | ||
</Types> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
module/PowerShellEditorServices/Commands/Public/ConvertFrom-ScriptExtent.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
function ConvertFrom-ScriptExtent { | ||
<# | ||
.EXTERNALHELP ..\PowerShellEditorServices.Commands-help.xml | ||
#> | ||
[CmdletBinding()] | ||
[OutputType([Microsoft.PowerShell.EditorServices.BufferRange], ParameterSetName='BufferRange')] | ||
[OutputType([Microsoft.PowerShell.EditorServices.BufferPosition], ParameterSetName='BufferPosition')] | ||
param( | ||
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] | ||
[ValidateNotNullOrEmpty()] | ||
[System.Management.Automation.Language.IScriptExtent[]] | ||
$Extent, | ||
|
||
[Parameter(ParameterSetName='BufferRange')] | ||
[switch] | ||
$BufferRange, | ||
|
||
[Parameter(ParameterSetName='BufferPosition')] | ||
[switch] | ||
$BufferPosition, | ||
|
||
[Parameter(ParameterSetName='BufferPosition')] | ||
[switch] | ||
$Start, | ||
|
||
[Parameter(ParameterSetName='BufferPosition')] | ||
[switch] | ||
$End | ||
) | ||
process { | ||
foreach ($aExtent in $Extent) { | ||
switch ($PSCmdlet.ParameterSetName) { | ||
BufferRange { | ||
# yield | ||
New-Object Microsoft.PowerShell.EditorServices.BufferRange @( | ||
$aExtent.StartLineNumber, | ||
$aExtent.StartColumnNumber, | ||
$aExtent.EndLineNumber, | ||
$aExtent.EndColumnNumber) | ||
} | ||
BufferPosition { | ||
if ($End) { | ||
$line = $aExtent.EndLineNumber | ||
$column = $aExtent.EndLineNumber | ||
} else { | ||
$line = $aExtent.StartLineNumber | ||
$column = $aExtent.StartLineNumber | ||
} | ||
# yield | ||
New-Object Microsoft.PowerShell.EditorServices.BufferPosition @( | ||
$line, | ||
$column) | ||
} | ||
} | ||
} | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
module/PowerShellEditorServices/Commands/Public/ConvertTo-ScriptExtent.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
function ConvertTo-ScriptExtent { | ||
<# | ||
.EXTERNALHELP ..\PowerShellEditorServices.Commands-help.xml | ||
#> | ||
[CmdletBinding()] | ||
[OutputType([System.Management.Automation.Language.IScriptExtent])] | ||
param( | ||
[Parameter(Mandatory, ValueFromPipelineByPropertyName, ParameterSetName='ByOffset')] | ||
[Alias('StartOffset', 'Offset')] | ||
[int] | ||
$StartOffsetNumber, | ||
|
||
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName='ByOffset')] | ||
[Alias('EndOffset')] | ||
[int] | ||
$EndOffsetNumber, | ||
|
||
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName='ByPosition')] | ||
[Alias('StartLine', 'Line')] | ||
[int] | ||
$StartLineNumber, | ||
|
||
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName='ByPosition')] | ||
[Alias('StartColumn', 'Column')] | ||
[int] | ||
$StartColumnNumber, | ||
|
||
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName='ByPosition')] | ||
[Alias('EndLine')] | ||
[int] | ||
$EndLineNumber, | ||
|
||
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName='ByPosition')] | ||
[Alias('EndColumn')] | ||
[int] | ||
$EndColumnNumber, | ||
|
||
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName='ByPosition')] | ||
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName='ByOffset')] | ||
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName='ByBuffer')] | ||
[Alias('File', 'FileName')] | ||
[string] | ||
$FilePath = $psEditor.GetEditorContext().CurrentFile.Path, | ||
|
||
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName='ByBuffer')] | ||
[Alias('Start')] | ||
[Microsoft.PowerShell.EditorServices.BufferPosition] | ||
$StartBuffer, | ||
|
||
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName='ByBuffer')] | ||
[Alias('End')] | ||
[Microsoft.PowerShell.EditorServices.BufferPosition] | ||
$EndBuffer, | ||
|
||
[Parameter(Mandatory, | ||
ValueFromPipeline, | ||
ValueFromPipelineByPropertyName, | ||
ParameterSetName='ByExtent')] | ||
[System.Management.Automation.Language.IScriptExtent] | ||
$Extent | ||
) | ||
begin { | ||
$fileContext = $psEditor.GetEditorContext().CurrentFile | ||
$emptyExtent = New-Object Microsoft.PowerShell.EditorServices.FullScriptExtent @( | ||
<# filecontext: #> $fileContext, | ||
<# startOffset: #> 0, | ||
<# endOffset: #> 0) | ||
} | ||
process { | ||
# Already a InternalScriptExtent, FullScriptExtent or is empty. | ||
$returnAsIs = $Extent -and | ||
(0 -ne $Extent.StartOffset -or | ||
0 -ne $Extent.EndOffset -or | ||
$Extent -eq $emptyExtent) | ||
|
||
if ($returnAsIs) { return $Extent } | ||
|
||
if ($StartOffsetNumber) { | ||
$startOffset = $StartOffsetNumber | ||
$endOffset = $EndOffsetNumber | ||
|
||
# Allow creating a single position extent with just the offset parameter. | ||
if (-not $EndOffsetNumber) { | ||
$endOffset = $startOffset | ||
} | ||
return New-Object Microsoft.PowerShell.EditorServices.FullScriptExtent @( | ||
$fileContext, | ||
$startOffset, | ||
$endOffset) | ||
} | ||
if (-not $StartBuffer) { | ||
if (-not $StartColumnNumber) { $StartColumnNumber = 1 } | ||
if (-not $StartLineNumber) { $StartLineNumber = 1 } | ||
$StartBuffer = New-Object Microsoft.PowerShell.EditorServices.BufferPosition @( | ||
$StartColumnNumber, | ||
$StartLineNumber) | ||
|
||
if ($EndLineNumber -and $EndColumnNumber) { | ||
$EndBuffer = New-Object Microsoft.PowerShell.EditorServices.BufferPosition @( | ||
$EndLineNumber, | ||
$EndColumnNumber) | ||
} | ||
} | ||
if (-not $EndBuffer) { $EndBuffer = $StartBuffer } | ||
|
||
$bufferRange = New-Object Microsoft.PowerShell.EditorServices.BufferRange @( | ||
$StartBuffer, | ||
$EndBuffer) | ||
|
||
return New-Object Microsoft.PowerShell.EditorServices.FullScriptExtent @( | ||
$fileContext, | ||
$bufferRange) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I realized I screwed that up after I merged the PR ;)