vscode-terraform
vscode-terraform copied to clipboard
Clickable links in terraform plan output
Problem Statement
If you run any command in a VS Code terminal window that outputs text with a link in it, VS Code renders the text as a clickable link. This works for web links as well as file paths.
A terraform plan output contains output that has the names/ids of the resources, which are directly related to the definitions in the configuration files being parsed.
Expected User Experience
If you run terraform plan
in a VS Code terminal window and hover over a resource definition, it should indicate that it is a clickable link. Clicking the link opens the relevant file where the declaration is defined.
This is similar to the 'Go to Definition' experience.
Proposal
We can register a new terminal link handler that implements the vscode.TerminalLinkProvider interface using the vscode.window.registerTerminalLinkProvider method that will trigger when a user hovers over a line in the terminal. After detecting a resource statement, a call to terraform-ls can return location information where the statement is defined. If nothing is found, the line is left unmodified.
I like the idea! 👍🏻
After detecting a resource statement, ...
Is the assumption that we'd just treat any space-separated word in the terminal output as something that could be a resource address, or is there any way to detect what process generated the output and hook only into Terraform output?
At the risk of thinking outside the box (box being the extension)... This could theoretically be a Core feature where the rendered plan/apply includes links such as file.tf:Line:Col
.
Downsides?
- We'd need buy in from the Core team
- Core would need to detect terminals accurately enough as to not render escape characters to terminals which don't support it.
- I am not sure what's the real support today in commonly used terminals. There's some info in https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda This could potentially be significant enough downside causing this whole idea to fall apart. 😅
Upsides?
- This could cover potentially any IDE (subject to terminal support as mentioned above)
- It would help avoid false positives where we'd end up linking to resource from some random string in output from non-Terraform program just because it looks like a resource address.
Related:
- Docs on Terminal links: https://code.visualstudio.com/docs/terminal/basics#_links
- LinkProvider for Git: https://github.com/gitkraken/vscode-gitlens/blob/33bc5845d92e22f8e920a3b3f22308c702bfb702/src/terminal/linkProvider.ts
I love this as I am currently importing a lot of resources and going back and forth is a chore
This would be amazing to have in core actually. Is there a way where we can connect with core team and send a feature request and/or pull request?