Skip to content

feat: URI Handler #431

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

Merged
merged 2 commits into from
Feb 13, 2025
Merged

Conversation

catskul
Copy link
Contributor

@catskul catskul commented Jan 14, 2025

Putting my code where my mouth is:

#430

This feature will allow us to add links to documents, and tool output which jumps to specific targets, reducing friction and wasted time.

URI handler works such that:

vscode://bazelbuild.vscode-bazel//my/path/to/tests:target

(unfortunately github itself won't link out to non-http urls)

Will jump to said target given vscode is opened to a workspace which contains a bazel workspace with that target as the first workspaceFolder

I imagine we could handle more situations like:

vscode://bazelbuild.vscode-bazel/fspath/to/workspace//my/path/to/tests:target

or

vscode://bazelbuild.vscode-bazel/test//my/path/to/tests:target

But I imagine anything of the sort would be more controversial.

@catskul catskul force-pushed the catskul/uri-handler branch 4 times, most recently from 2fa1f1c to 4d78ea4 Compare January 14, 2025 06:23
vscode.window.registerUriHandler({
async handleUri(uri: vscode.Uri) {
try {
const workspace = vscode.workspace.workspaceFolders[0];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

presume it's in the first workspaceFolder. I suppose something more sophisticated could be done, but not sure it's necessary. Happy to accept suggested change here if someone has a specific suggestion.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without any way of identifying the bazel workspace, I don't think we can do any better than assume the first workspace, so I'm happy with this.

@catskul catskul force-pushed the catskul/uri-handler branch from 4d78ea4 to b222b07 Compare January 25, 2025 04:51
@catskul
Copy link
Contributor Author

catskul commented Jan 25, 2025

formatting fixes pushed.

@cameron-martin
Copy link
Collaborator

What's the use case for this?

@catskul
Copy link
Contributor Author

catskul commented Feb 8, 2025

@cameron-martin When targets fail, esp in cloud CI, notifications are often sent via slack, email, etc.

The use case here is to make it possible to provide clickable links right into vscode.

This is directly analogous to VSCode's more general ability to link to files in vscode:

https://github.com/Microsoft/vscode-docs/blob/main/docs/editor/command-line.md#opening-vs-code-with-urls

Copy link
Collaborator

@cameron-martin cameron-martin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than those minor comments, look good! Seems to work very well.

@@ -19,15 +19,48 @@ import {
Position,
TextDocument,
Uri,
window,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both these extra imports seem to be unused.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

getDefaultBazelExecutablePath(),
Utils.dirname(document.uri).fsPath,
).queryTargets(`kind(rule, "${targetName}") + kind(file, "${targetName}")`);
const location = await targetToUri(targetText, Utils.dirname(document.uri));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this case can ever realistically get hit, but to make this refactor preserve behaviour you should return null here if location is null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed with ternary. Let me know if you'd rather I used some other format.

vscode.window.registerUriHandler({
async handleUri(uri: vscode.Uri) {
try {
const workspace = vscode.workspace.workspaceFolders[0];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without any way of identifying the bazel workspace, I don't think we can do any better than assume the first workspace, so I'm happy with this.

@catskul
Copy link
Contributor Author

catskul commented Feb 12, 2025

Will try to update this tonight.

@catskul catskul force-pushed the catskul/uri-handler branch from 22974ba to 431e319 Compare February 13, 2025 05:54
@catskul
Copy link
Contributor Author

catskul commented Feb 13, 2025

All comments addressed. Happy to make any additional changes if you see any other issues.

@cameron-martin cameron-martin changed the title URI Handler feat: URI Handler Feb 13, 2025
@cameron-martin cameron-martin enabled auto-merge (squash) February 13, 2025 09:32
@cameron-martin cameron-martin merged commit 7e5ee8f into bazel-contrib:master Feb 13, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants