Repository navigation
Complete members from explicit roxygen parameter and return hints - #894
Conversation
eitsupi
left a comment
There was a problem hiding this comment.
Reviewed by ChatGPT. I support the general idea of using roxygen type hints, but I have several concerns about correctness and maintainability.
1. Rename can break @inheritParams references.
Box <- R6::R6Class("Box")
#' @param x (`Box`) A box.
donor <- function(x) x
#' @inheritParams donor
consumer <- function(x) xRenaming donor appears to leave @inheritParams donor unchanged, breaking both documentation inheritance and the newly introduced type inference. Now that the language server explicitly models these dependencies, Rename should either update verified references or decline unsafe edits.
2. Explicit type annotations and ordinary documentation should be distinguished.
Markdown links in roxygen are fundamentally references to documentation topics, not type declarations. Similarly, a class name in a phrase such as "An object of class ..." does not necessarily identify the variable holding its class generator.
Using these conventions as heuristic evidence for completion seems reasonable, but using them for S3 dispatch inference and Rename requires stronger justification. I would recommend distinguishing explicit annotations from heuristic documentation-derived hints, and providing a setting to disable roxygen-based type inference independently.
3. The scope of this PR is too broad.
This PR adds over 7,600 lines across 69 files, covering annotation parsing, parameter and return inference, unions, multiple object systems, documentation inheritance, S3 dispatch, References, Rename, source resolution, caching, and asynchronous request management.
Although individual responsibilities are separated into files, the number of interactions between subsystems makes correctness difficult to establish and increases the long-term maintenance burden.
I would strongly recommend splitting this into smaller PRs, starting with explicit parameter and return type hints for member completion. Documentation inheritance, heuristic interpretation of existing documentation, and Rename integration could follow independently. General improvements to source binding resolution should also be reviewed separately where possible.
The feature is valuable, but I think a more incremental approach would make it substantially easier to review and maintain.
eitsupi
left a comment
There was a problem hiding this comment.
Reviewed by ChatGPT.
The reduced scope of this PR is appropriate. Limiting the initial implementation to explicit type hints for member completion, providing an independent setting, and prioritizing concrete inference results address the previous review concerns.
One minor concern is that member_hint_packages() may not wait for package metadata when a wrapper's return type is inferred from an annotated parameter rather than an explicit return annotation. Since #896 reworks dependency tracking, this case should be covered by a regression test there.
The remaining PRs should be reviewed independently, particularly the broader inference changes in #896 and the documentation inheritance mechanism in #899.
No blocking issues found. Approved.
This is the first part of the roxygen type-hint series. An explicit marker at the beginning of a parameter or return description supplies a fallback receiver type for member completion.
Typing
box$insideread_box()or selecting a member afterrestore_box(bytes)$offersvalue. Concrete arguments and return values take precedence. Setr.lsp.roxygen_type_hintstofalseto disable documentation-derived inference independently. No roxygen2 installation is required.The current diff is against the latest merged package-reference and data-mask work on
master. This PR preserves its earlier review history. The additional provider, inheritance, Rename and documentation-compatibility changes from the previous revision are in the linked follow-ups.Review order
@inheritParamspropagation together with safe donor RenameEach follow-up targets the preceding PR so its Files changed tab shows only that step. Repository CI targets PRs against
master. Local package checks exercise the dependent branches.Review concerns addressed
@name, and declines when it cannot make a safe edit. This also works with inference disabled....takes the callee's default, as it does in R. Passing a missing formal to the callee as an expression preserves its missing-argument state.Verification
All 16 GitHub checks passed on
9975665. The focused PR and the combined stack (64a94b2) passed localR CMD checkon R 4.6.1 with 24,395 and 25,481 assertions, respectively, and no warnings or skips. Each of the five intermediate heads passed its roxygen, member, S3 and Rename regression suites.All 537 cache decisions agreed. In a paired test on the longest Polars chain, completion, hover and signature help saved 3, 4 and 2 ms. Across the unannotated fixture, with 72 requests per provider per revision, median completion was 31.0 ms on
masterand 32.5 ms on the revised stack. Median hover was 15.0 ms and signature help was 16.5 ms on both. The 105-file parse benchmark produced the same result hash.This first implementation resolves local generators visible at the documented function. A generator declared only later in the file does not currently supply body completions in this layer.