-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
feat: URI Handler #431
Conversation
2fa1f1c
to
4d78ea4
Compare
vscode.window.registerUriHandler({ | ||
async handleUri(uri: vscode.Uri) { | ||
try { | ||
const workspace = vscode.workspace.workspaceFolders[0]; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
4d78ea4
to
b222b07
Compare
formatting fixes pushed. |
What's the use case for this? |
@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: |
There was a problem hiding this 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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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.
Will try to update this tonight. |
22974ba
to
431e319
Compare
All comments addressed. Happy to make any additional changes if you see any other issues. |
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.