Skip to content
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

Treat dot sourced files as links #5046

Open
2 tasks done
JensGJ opened this issue Sep 18, 2024 · 7 comments
Open
2 tasks done

Treat dot sourced files as links #5046

JensGJ opened this issue Sep 18, 2024 · 7 comments
Labels
Area-Symbols & References Issue-Enhancement A feature request (enhancement). Up for Grabs Will shepherd PRs.

Comments

@JensGJ
Copy link

JensGJ commented Sep 18, 2024

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.

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 supported

Proposed 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.

@JensGJ JensGJ added Issue-Enhancement A feature request (enhancement). Needs: Triage Maintainer attention needed! labels Sep 18, 2024
@JustinGrote JustinGrote added Area-Symbols & References Up for Grabs Will shepherd PRs. and removed Needs: Triage Maintainer attention needed! labels Sep 18, 2024
@JustinGrote
Copy link
Collaborator

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.

@andyleejordan
Copy link
Member

Do other extensions do this? If so we should look at their implementation.

@JustinGrote
Copy link
Collaborator

I've only ever seen it in the logs, doing simple pattern matching.

@JensGJ
Copy link
Author

JensGJ commented Sep 19, 2024

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).

@JustinGrote
Copy link
Collaborator

JustinGrote commented Sep 20, 2024

@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.

@JustinGrote
Copy link
Collaborator

Related: microsoft/vscode#108527

@ArieHein
Copy link
Contributor

ArieHein commented Oct 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Symbols & References Issue-Enhancement A feature request (enhancement). Up for Grabs Will shepherd PRs.
Projects
None yet
Development

No branches or pull requests

4 participants