PowerShell / PowerShell/vscode-powershell
Please support programmatic open-file at custom line number/position (for programmatic go-to-definition scenario)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.9k
- Forks
- 547
- PR merge metrics
- No merged PRs in 30d
Description
Prerequisites
- I have written a descriptive issue title.
- I have searched all issues to ensure it has not already been reported.
Summary
I am migrating from the old powershell_ISE to powershell 7. One thing I used to do a LOT in the ps ISE world is a non-IDE-initiated Go-To-Definition. This was implemented as a command (i.e. Def MyFunction, if inside ISE, then it just opens there and sets the cursor to the position; if outside the ISE then it would open the ISE and set the cursor position there)
In the VSCode plugin, there is F12/Go-to-Definition in the UI, but I seem to be blocked from implementing it in command form (or I can’t find it). I did find “Open-EditorFile” which is close, but it does not allow me to point to a specific line, the way I could with the powershell_ise. In particular, $psise.CurrentFile.Editor.SetCaretPosition could be used to fine-tune where the cursor is pointing, but the $psEditor object seems to be highly restricted.
Would it be possible to get a feature to $psEditor.Workspace to have a function to open / jump to a given file+line? E.g. OpenFile(string filePath, uint32 lineNumber, uint32 columnNumber)? Allowing the user to 'pop' any file and line number they want is always going to be the most capable option, allowing people to jump to code that may be too obscurely done for the mainstream ISE to ever track.
(optionally, also add a psEditor.WorkSpace.GoToDefinition which more directly mirrors the existing UI option)
Proposed Design
Please add a new overload for $psEditor.Workspace.OpenFile, such as OpenFile(string filePath, uint32 **lineNumber**, uint32 columnNumber)
(Also expose this overload in the CmdletInterface.ps1 file.)
Optionally, also add psEditor.WorkSpace.GoToDefinition(string identifier) and expose that in the CmdletInterface.ps1 as well.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by inspecting the existing $psEditor.Workspace.OpenFile API and the CmdletInterface.ps1 exposure mentioned in the issue. Determine how an overload accepting filePath, lineNumber, and columnNumber should fit the current interface; done means callers can open a file at the requested position, with the optional GoToDefinition API treated separately.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vscode
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100