Skip to content

Use class links and roxygen prose as advisory member-completion hints - #901

Open
renkun-ken wants to merge 7 commits into
codex/roxygen-class-member-typesfrom
codex/roxygen-advisory-completion
Open

renkun-ken wants to merge 7 commits into
codex/roxygen-class-member-typesfrom
codex/roxygen-advisory-completion

Conversation

@renkun-ken

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

Copy link
Copy Markdown
Member

Part 7 of the review split for #894. The base is #900.

This distinguishes an explicit type contract from an ordinary documentation topic. Advisory hints are off by default. To use verified Markdown class links and class phrases for member suggestions, enable r.lsp.roxygen_advisory_type_hints or set these R options before starting the server:

options(
  languageserver.roxygen_type_hints = TRUE,
  languageserver.roxygen_advisory_type_hints = TRUE
)

Advisory hints supply member suggestions after class verification. They cannot supply the dispatch class for S3 or a class-reference edit for Rename. Known concrete receiver information and explicit contracts remain eligible.

Box <- R6::R6Class("Box", public = list(value = 1L))
#' @param x,y [`Box`] Boxes to compare.
same_value <- function(x, y) identical(x$value, y$value)
same_value(Box$new(), Box$new())  # TRUE

For identity-sensitive uses, an explicit @param x (`Box`) or an unambiguous leading Rd marker [\code{Box}] supplies the declared instance. A phrase such as An object of class [`Box`]. remains advisory. Mixed or unresolved alternatives never silently narrow to the first class. The roxygen_type_hints setting disables documentation-derived inference for both forms.

Tests cover overlapping class and topic names, origin lookup, mixed annotations, ordinary S3 evidence, indirect calls and warm caches. The benchmark exercises leading-marker scans and completion on source and package fixtures.

@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 distinction between explicit annotations and advisory documentation-derived hints addresses the previous concerns regarding dispatch and Rename. The additional handling of advisory evidence across numeric union alternatives also appears appropriate.

I suggest providing a separate setting for advisory type inference, disabled by default, for example:

options(
    languageserver.roxygen_type_hints = TRUE,
    languageserver.roxygen_advisory_type_hints = FALSE
)

Explicit type annotations are intentionally supplied type information, whereas Markdown links and natural-language descriptions are fundamentally documentation rather than type declarations. Users should be able to enable the former without accepting the heuristics of the latter.

The propagation of advisory evidence also introduces additional complexity throughout the inference engine. This maintenance cost should be considered before expanding the supported documentation patterns further.

No blocking implementation issues found. Approved with the above suggestion.

@renkun-ken
renkun-ken requested a review from eitsupi December 1, 2026 15:58
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