Skip to content

Support functions in View() #8262

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 6 commits into from
Jun 25, 2025
Merged

Support functions in View() #8262

merged 6 commits into from
Jun 25, 2025

Conversation

lionel-
Copy link
Contributor

@lionel- lionel- commented Jun 24, 2025

Addresses #2945.
Companion PR for posit-dev/ark#848.

The main change needed on the frontend side is to detect non-file schemes in the OpenEditor event handler of the UI comm. This way we preserve ark: URIs, which allows Ark to request the frontend to open documents via its own vdoc provider.

I also improved vdoc provider errors to be more user friendly. The error is mentioned in the virtual editor and the error message is logged.

Release Notes

New Features

  • View() now supports function objects (Ark: View() should support function objects #2945). It takes you directly to the original source, if the function has source references, or to a virtual document containing the deparsed function code otherwise.

  • Functions are now also viewable from the Variables pane. Click on the "view" button on the right hand side of a variable entry to view its source definition in an editor.

Bug Fixes

  • N/A

QA Notes

See companion PR: posit-dev/ark#848.

@:variables

Copy link

github-actions bot commented Jun 24, 2025

E2E Tests 🚀
This PR will run tests tagged with: @:critical @:variables

readme  valid tags

});
const documentData = await this.documents.ensureDocumentData(uri);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just a small cleanup to use await syntax that I did while I was planning to do more changes here. I didn't end up modifying this handler, but I thought we might keep the cleanup. It causes the handler to only resolve when showTextDocument() has resolved, which I think is probably best in terms of assumptions made by the requester.

@lionel- lionel- changed the title Feature/view function Support functions in View() Jun 24, 2025
@lionel- lionel- requested a review from jmcphers June 24, 2025 16:15
jmcphers
jmcphers previously approved these changes Jun 24, 2025
Copy link
Collaborator

@jmcphers jmcphers left a comment

Choose a reason for hiding this comment

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

Tested with ark changes & things work well!

return await this._client.sendRequest(VIRTUAL_DOCUMENT_REQUEST_TYPE, params, token);
} catch (err) {
LOGGER.warn(`Failed to provide document for URI '${uri}': ${err}`);
return 'Error: This document does not exist';
Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you think about including the URI and error in the document body, or showing it in a notification, so it's easier to diagnose without digging into logs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about that but I worried about making this less user friendly. The main question is whether this should be considered a regular UI message or an exceptional one that warrants presenting debug info to the user.

It would probably be fine to do the latter for now, but if we ever have vdocs representing transient objects with good lifecycle management (vdoc goes out of scope with the object they represent), then this error message would be a normal part of the user experience.

I plan to reuse this mechanism for the fallback vdocs of the debugger. Currently they are managed via DAP and a big downside is that the names of these editors don't have a .R extension and Positron doesn't activate R language support in these editors. By using ark: URIs pointing to documents fully managed by Ark, we'll have better control. Unlike the documents created by View(), these documents will be cleaned up, when the debugging session ends. So users might start seeing this message more regularly (not entirely sure, maybe that will only be the case if we notify the frontend provider that the document has been updated).

@lionel- lionel- force-pushed the feature/view-function branch from 543d63c to 9e4e5b1 Compare June 25, 2025 09:39
lionel- added 2 commits June 25, 2025 13:19
In case it's not managed by a comm
@lionel- lionel- force-pushed the feature/view-function branch from 7514a39 to 6264530 Compare June 25, 2025 11:19
@lionel- lionel- merged commit cb41a6b into main Jun 25, 2025
8 checks passed
@lionel- lionel- deleted the feature/view-function branch June 25, 2025 15:03
@github-actions github-actions bot locked and limited conversation to collaborators Jun 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants