Discussion: Different method of passing $Context to Editor Commands
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 20/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Da chiarire
- Stato di attività
- Ferma
- Stack tecnologico
- powershell
- Ambito
- developer-experience
Direzione di ricerca
Inizia tracciando i percorsi di Register-EditorCommand, Function e ScriptBlock e confrontando EditorContext con $psEditor; l’issue non indica file né test. Prima dell’implementazione è necessaria una decisione del maintainer, documentando il comportamento desiderato e i controlli di completamento.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
I wanted to start a discussion on how PSES could improve the way it passes $Context to Editor Commands.
The way $Context is made accessible to an Editor Command currently, is it is passed as a parameter to the Command. This is not immediately evident and I can see this causing confusion.
In a scriptblock, this can be handled by adding a context param.
Register-EditorCommand `
-Name "Teamviewer.ConnectDevice" `
-DisplayName "Connect to Teamviewer Device" `
-SuppressOutput `
-ScriptBlock {
param([Microsoft.PowerShell.EditorServices.Extensions.EditorContext]$context)
Connect-Teamviewer
}
However, if you were to just specify the function you may get some results you didn't expect.
Register-EditorCommand `
-Name "Teamviewer.ConnectDevice" `
-DisplayName "Connect to Teamviewer Device" `
-SuppressOutput `
-Function Connect-Teamviewer
In the above example, Connect-Teamviewer will be passed $context as a parameter when executed as an Editor Command.
function Connect-Teamviewer
{
[Cmdletbinding()]
param
(
[parameter(Mandatory=$true)]
[string]$ComputerName
)
If your function looks something like the above code the command will actually error. $context will be passed to the $CompuerName parameter. Meaning you would need to write your functions with this in mind.
function Connect-Teamviewer
{
[Cmdletbinding()]
param
(
[parameter(Mandatory=$false)]
[[Microsoft.PowerShell.EditorServices.Extensions.EditorContext]]$Context,
[parameter(Mandatory=$true)]
[string]$ComputerName
)
This is likely not a good solution ether. It is going to be confusing to those writing their first commands, and there could potentially be some unwanted results. I have not tested it, but I wonder of the potential issues of a parameter not checking for a type and being passed context to do something like delete something.
function Delete-Stuff
{
[Cmdletbinding()]
param
(
$Stuff
)
Process
{
foreach ($item in $Stuff)
{
Delete-AllTheThings $item
}
}
}
One question I wanted to ask, could the information in $Context, be added to $psEditor? Is there a reason it has to be passed to the function @daviwil ?
$psEditor.context.cursorposition
Something along the lines of that. When I was first learning the Editor commands, this is sort of what I thought $psEditor was doing. I didn't realize there was a difference between $Context and $psEditor. @daviwil can you better explain the exact differences between the 2? I'd like to get a better grasp of exactly how each differ.
- Lingua principale
- C#
- Stelle
- 767
- Fork
- 266
- Merge medio
- 3g 16h
- PR unite (30g)
- 1
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di PowerShell/PowerShellEditorServices
-
[Bug] None of the string overloads of `EditorExtensionServiceProvider.GetService()` work on .NET. Aperta
PowerShell/PowerShellEditorServices#2331 · 1 reazione · 2 assegnatari ·
-
Area-Language Server Issue-Enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
PowerShell/PowerShellEditorServices#2315 · 1 commento ·
-
Area-Debugging Issue-Enhancement
PowerShell/PowerShellEditorServices#2294 · 1 reazione · 2 assegnatari ·
-
Issue-Bug Needs: Triage
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
PowerShell/PowerShellEditorServices#2293 · 1 commento ·
-
PowerShell/PowerShellEditorServices#2282 · 1 commento · 1 reazione · 2 assegnatari ·
Tutte le issue di PowerShell/PowerShellEditorServices
Issue simili
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
sillsdev/languageforge-lexbox#2665 ·
-
C: Syntax
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
bug documentation frontend
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
azurenoops/spin_agent#975 ·
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficoltà 2/5 1-3 ore Idoneità per principianti 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
SubtitleEdit/subtitleedit#15108 · 1 commento ·