Skip to content

Follow-up for attached packages fix - #1403

Merged
lionel- merged 8 commits into
mainfrom
oak/attached-packages-follow-up
Sep 16, 2026
Merged

lionel- merged 8 commits into
mainfrom
oak/attached-packages-follow-up

Conversation

@lionel-

@lionel- lionel- commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Follow-up for #1393:

  1. Extend test coverage for cycles
  2. Mention file loader in user-surfaced diagnostics
  3. Remove the implicit R/ folder collation load. This addresses R scripts that source() a sibling in R/ lose their attached packages positron#15665.

I decided to go for 3 because of two undesirable consequences when the implicit collation conflicts with an explicit source() call written by the user:

  • The recovery handler reports empty results and makes language analysis incorrect.
  • When experimental diagnostics are enabled, the user gets an incorrect and unactionable lint:
Screenshot 2026-09-08 at 14 39 59

I think that pretty much kills the approach. Potentially we could disable the implicit folder loader for files that have an explicit source, but that behaviour would we hard to understand and predict for users. So I think we're better off modelling explicit source effects, like we did with the Shiny and testthat file loaders, or with targets::tar_source().

Here is an example of the improved lint when an explicit loader conflicts with a user Source effect. Compared to the problematic lint above, this one is both correct and actionable:

Screenshot 2026-09-08 at 14 49 59

Positron Release Notes

Let me know if you'd like a release note item here. It seemed to me mentioning this change would more likely confuse users.

New Features

  • N/A

Bug Fixes

  • N/A

@lionel-
lionel- requested a review from juliasilge September 11, 2026 15:07

@juliasilge juliasilge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is working well for me in various workspace configurations!

Image

I have one requested change before you merge, to update one of the user facing messages; I think it will be wrong/confusing to folks as is.

Comment thread crates/oak_db/src/diagnostic.rs Outdated
fn lower_source_cycle(loader: Option<LoaderInfo>) -> Diagnostic {
let cause = match loader {
Some(LoaderInfo { name, loads }) => {
format!("{name} already loads {loads}, so a `source()` call between them is redundant.")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This sentence tells the reader to remove a source() call that a Shiny app actually needs to work, right? An alternative would be to just state the fact and stop:

format!("{name} already loads {loads}. A `source()` call into a file that the loader loads later creates this cycle.")

Let me know if I am misunderstanding!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also related to the message here, loader(db, file) reads the diagnosed file only and IIUC nothing makes sure that the other files in the cycle have the same loader. The message still makes a claim about the relationship between them: "a source() call between them is redundant".

SemanticDiagnostic::SourceCycle is a unit variant, so the participants are not available here. A gate on the shared loader would be pretty hard and needs the participant list in the variant. I think the cheaper, better option is to keep this sentence more descriptive.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That makes sense! I made it:

This Shiny app already loads its `global.R` and `R/` files through `shiny::loadSupport()`.
A `source()` call into a file that the loader also loads creates this cycle.

@lionel-
lionel- force-pushed the oak/attached-packages-follow-up branch from 2070d2d to 895245f Compare September 16, 2026 10:58
@lionel-
lionel- merged commit bc7c15c into main Sep 16, 2026
17 checks passed
@lionel-
lionel- deleted the oak/attached-packages-follow-up branch September 16, 2026 11:08
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 16, 2026
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