Skip to content

Propagate explicit roxygen types through calls and S3 dispatch - #896

Merged
renkun-ken merged 8 commits into
masterfrom
codex/roxygen-explicit-dispatch
Nov 30, 2026
Merged

renkun-ken merged 8 commits into
masterfrom
codex/roxygen-explicit-dispatch

Conversation

@renkun-ken

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

Copy link
Copy Markdown
Member

Part 2 of the review split. The base and review order are in #894.

This builds on the explicit member-completion PR. It follows annotated values through wrappers, reassignment and return paths, resolves package-qualified classes, and supports unions of possible receivers. S3 providers choose a method when all alternatives agree. Static analysis keeps more specific evidence from the actual argument or body.

format_score <- function(x, ...) UseMethod("format_score")
format_score.score <- function(x, digits = 1L, ...) sprintf("%.*f", digits, unclass(x))

#' @param x (`score`) A numeric score.
display_score <- function(x) format_score(x, digits = 2L)

display_score(structure(7.5, class = "score"))  # "7.50"

Signature help inside display_score() uses format_score.score. A parenthesized marker can describe a nominal S3 class with no generator. The built-in hint (`numeric`) covers both integer and double values. If both dispatch to format_score.numeric, the server can show that method's signature. If they select different methods, the server can identify the integer method when the argument is a concrete 1L.

The same member analysis supports Polars method chains.

library(polars)

#' @param data (`polars::polars_data_frame`) Team measurements.
team_means <- function(data) {
  data$group_by("team")$agg(pl$col("value")$mean())
}
team_means(pl$DataFrame(team = c("a", "a", "b"), value = c(1, 3, 8)))

A wrapper that returns its argument can get its entire return type from a qualified @param. A regression test requests completion before the package metadata arrives and checks that the original request receives the inferred members exactly once.

The native traversal attaches hints to the relevant function literals, including those in deeply nested expressions. The syntax-name index then includes classes referenced only by those hints so providers can find their metadata. The independent CLI test fix is in #911.

Local R CMD check on R 4.6.1 passed with 24,723 assertions on this PR (171a383) and 25,514 on the combined stack (4218dd1). The four intermediate branches passed their focused suites. A separate fresh-process LSP check on both heads returned the fixture's status member on the first completion request.

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

No blocking issues found. I have three non-blocking suggestions:

  • The numeric type hint currently resolves to double, but numeric vectors in R can be either integer or double. Treating numeric as equivalent to integer | double would better reflect common R documentation conventions and avoid incorrectly selecting an S3 method.
  • Please consider adding a regression test for the initial completion request when a wrapper's return type is inferred solely from a package-qualified parameter hint, as noted in #894.
  • The unrelated backend CLI test fix would be better handled in a separate PR. The native code optimizations could also be separated if they are independently useful.

Base automatically changed from codex/roxygen-type-hints to master November 30, 2026 23:21
@renkun-ken
renkun-ken merged commit f04632d into master Nov 30, 2026
16 checks passed
@renkun-ken
renkun-ken deleted the codex/roxygen-explicit-dispatch branch November 30, 2026 23:22
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