-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,10 @@ import { | |
} from "../buildifier"; | ||
import { BazelBuildCodeLensProvider } from "../codelens"; | ||
import { BazelCompletionItemProvider } from "../completion-provider"; | ||
import { BazelGotoDefinitionProvider } from "../definition/bazel_goto_definition_provider"; | ||
import { | ||
BazelGotoDefinitionProvider, | ||
targetToUri, | ||
} from "../definition/bazel_goto_definition_provider"; | ||
import { BazelTargetSymbolProvider } from "../symbols"; | ||
import { BazelWorkspaceTreeProvider } from "../workspace-tree"; | ||
import { activateCommandVariables } from "./command_variables"; | ||
|
@@ -105,6 +108,33 @@ export async function activate(context: vscode.ExtensionContext) { | |
"bazel.copyTargetToClipboard", | ||
bazelCopyTargetToClipboard, | ||
), | ||
// URI handler | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. presume it's in the first There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
const quotedUriPath = `"${uri.path}"`; | ||
const location = await targetToUri(quotedUriPath, workspace.uri); | ||
|
||
vscode.commands | ||
.executeCommand( | ||
"vscode.open", | ||
vscode.Uri.file(location.path).with({ | ||
fragment: `${location.line}:${location.column}`, | ||
}), | ||
) | ||
.then(undefined, (err) => { | ||
void vscode.window.showErrorMessage( | ||
`Could not open file: ${location.path} Error: ${err}`, | ||
); | ||
}); | ||
} catch (err: any) { | ||
void vscode.window.showErrorMessage( | ||
`While handling URI: ${JSON.stringify(uri)} Error: ${err}`, | ||
); | ||
} | ||
}, | ||
}), | ||
// CodeLens provider for BUILD files | ||
vscode.languages.registerCodeLensProvider( | ||
[{ pattern: "**/BUILD" }, { pattern: "**/BUILD.bazel" }], | ||
|
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.