Open JensGJ opened 1 month ago
Thanks for the submission!
This may be doable, the tricky part is identifying a PowerShell file path in all potential contexts, and supporting both Linux and Windows paths. I don't think PowerShell itself has an API for determining a "file path" symbol, but it certainly might be possible. Marking this as "Up for Grabs", I'd be willing to review an attempted PR, but it would need to be pretty explicit and have very few if no edge cases otherwise it could lead to very frustrating behavior of some links clickable and others not.
Do other extensions do this? If so we should look at their implementation.
I've only ever seen it in the logs, doing simple pattern matching.
I don't think PowerShell itself has an API for determining a "file path" symbol, but it certainly might be possible.
I am not familiar with VS Code development, but I would expect that the task of identifying a dot sourced file name would be a simple pattern (a line-starting dot+whitespace followed by a coherent string).
In terms of resolving the file I would hope that PowerShell's own "Resolve-Path" might be an option (as far as I know it is also available on Linux).
@JensGJ everything seems simple till you get down to the nitty gritty of it :)
For instance, what about this:
. $PSScriptRoot/$(myfilepath)
where $(myfilepath) is not specified in the scope.
Or for a relative path, how do we know what the root path is unless $PSScriptRoot is specified? We have no way of knowing what context it is being dot sourced from or what the local terminal relative path is.
For the simple scenarios like . Absolute/path/to/my/thing we can support, but almost nobody codes absolute paths.
We can probably introduce initial limited support, but it's not going to be on my personal to-do anytime soon which is why I flagged it up-for-grabs.
There is also the option to use macros via extensions if you are looking for a solution meanwhile.
By the way, was this available via ISE ? I mean you can always execute that specific line to make it open the file, if the path is correct.
Prerequisites
Summary
I would like to have an easy way of opening a dot sourced file when I edit a powershell file. If I edit a ps1 file with a line like this:
. C:\powershell\myimport.ps1
I would expect that VS Code would provide me with a simple way of opening the file. It would be nice if both relative and absolute paths were supportedProposed Design
It could be handled as a link - like the autogenerated links that are created if you write a URL anywhere in an editor window. Or it could be handled by expanding "Go to definition" to handle dot sourced files by opening them. Or just an extra option when right clicking a dot source line.