Skip to content

Complete members from explicit roxygen parameter and return hints - #894

Merged
renkun-ken merged 14 commits into
masterfrom
codex/roxygen-type-hints
Nov 30, 2026
Merged

renkun-ken merged 14 commits into
masterfrom
codex/roxygen-type-hints

Conversation

@renkun-ken

@renkun-ken renkun-ken commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

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.

Box <- R6::R6Class("Box", public = list(value = 1L))

#' @param box (`Box`) The box to inspect.
read_box <- function(box) box$value

#' @return (`Box`) A restored box.
restore_box <- function(bytes) unserialize(bytes)

read_box(Box$new())                          # 1L
restore_box(serialize(Box$new(), NULL))$value # 1L

Typing box$ inside read_box() or selecting a member after restore_box(bytes)$ offers value. Concrete arguments and return values take precedence. Set r.lsp.roxygen_type_hints to false to 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

PR Scope
#894 Explicit parameter and return markers for member completion, and the independent setting
#896 Unions, call and return propagation, package lookup and S3 dispatch from explicit hints
#897 Source-binding ownership for ordinary References and Rename, including glue
#898 References and Rename for verified class generators in explicit annotations
#899 @inheritParams propagation together with safe donor Rename
#900 Explicit R6 fields, S4 slots, S7 properties and method hints
#901 Resolved Markdown links and prose as advisory member-completion hints

Each 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

  • The scope of this PR went from 69 changed files and 7,671 insertions to 17 files and 423 insertions. The source-ownership work has its own PR.
  • The inheritance PR includes the reviewer’s donor/consumer case. Rename updates a verified implicit donor reference, preserves an independent @name, and declines when it cannot make a safe edit. This also works with inference disabled.
  • The compatibility PR keeps ordinary documentation links separate from explicit annotations. They can supply verified member suggestions. S3 dispatch and class-generator Rename require explicit or independently established evidence.
  • Wrappers match exact argument names before partial names. An empty argument forwarded through ... 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.
  • The dispatch layer resolves documented formals when they are read. The filtered package list also reaches metadata workers after both complete and partial parses.
  • Source and annotation Rename check which declaration was visible at the read or tag. Rename declines an edit when two entry scripts give a shared reader different bindings, or when an edit would damage grouped or inherited parameter documentation.
  • Grouped R6 fields and methods with quoted names retain their annotations. An advisory class link cannot select an S7 method or hide a concrete S3 result when a function ignores that argument.

Verification

All 16 GitHub checks passed on 9975665. The focused PR and the combined stack (64a94b2) passed local R CMD check on 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.

Local workload Before review After review
Index 14,000 annotated functions in the dispatch layer 4.48 s 1.77 s
Attach annotations to 1,024 class declarations in one expression ~500 ms ~30 ms
Check summary-cache eligibility for 537 captured Polars arguments 31.9 ms 20.5 ms

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 master and 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.

@eitsupi eitsupi 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.

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) x

Renaming 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.

@renkun-ken
renkun-ken added this pull request to stack #909 November 30, 2026 02:07

@eitsupi eitsupi 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.

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.

@renkun-ken
renkun-ken merged commit 7eabc04 into master Nov 30, 2026
16 checks passed
@renkun-ken
renkun-ken deleted the codex/roxygen-type-hints branch November 30, 2026 23:21
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