Skip to content

Remove virtualDocUri() as a footgun #713

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

Conversation

DavisVaughan
Copy link
Collaborator

@DavisVaughan DavisVaughan commented May 19, 2025

There were 3 remaining places where we used virtualDocUri() instead of withVirtualDocUri(). The ad hoc usage of this is scary because it requires us to carefully analyze the call to ensure we call the cleanup() hook (#708). withVirtualDocUri() always handles this, so this PR removes virtualDocUri() as a footgun altogether by routing everything through withVirtualDocUri() and then unexporting virtualDocUri().

await vdocUri.cleanup();
return await withVirtualDocUri(vdoc, document.uri, "hover", async (uri: Uri) => {
try {
return await getHover(uri, vdoc.language, position);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We did not await before but I'm guessing it's probably better to?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you are correct on this; I occasionally would observe slight glitchy-ness with the embedded help in Quarto files and I can't get it to happen now with this PR.

await vdocUri.cleanup();
return await withVirtualDocUri(vdoc, document.uri, "signature", async (uri: Uri) => {
try {
return await getSignatureHelpHover(uri, vdoc.language, position, context.triggerCharacter);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We did not await before but I'm guessing it's probably better to?

@@ -280,64 +272,61 @@ function embeddedGoToDefinitionProvider(engine: MarkdownEngine) {
): Promise<Definition | LocationLink[] | null | undefined> => {
const vdoc = await virtualDoc(document, position, engine);
if (vdoc) {
const vdocUri = await virtualDocUri(vdoc, document.uri, "definition");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This diff looks ugly but I didn't change anything in the try or catch block. It's just switching to withVirtualDocUri() and removing the finally block

@DavisVaughan DavisVaughan requested a review from cscheid May 19, 2025 17:53
Copy link
Collaborator

@juliasilge juliasilge left a comment

Choose a reason for hiding this comment

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

Thank you for working on this! Super happy to see those virtualDocUri uses cleaned up 🙌

await vdocUri.cleanup();
return await withVirtualDocUri(vdoc, document.uri, "hover", async (uri: Uri) => {
try {
return await getHover(uri, vdoc.language, position);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you are correct on this; I occasionally would observe slight glitchy-ness with the embedded help in Quarto files and I can't get it to happen now with this PR.

@DavisVaughan DavisVaughan merged commit 0447832 into quarto-dev:main May 22, 2025
1 check passed
@DavisVaughan DavisVaughan deleted the feature/remove-vdoc-footgun branch May 22, 2025 15:29
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