Skip to content

Fix member completion for assigned and collected Polars queries - #785

Merged
renkun-ken merged 3 commits into
REditorSupport:masterfrom
renkun-ken:codex/fix-polars-query-member-completion
Oct 8, 2026
Merged

renkun-ken merged 3 commits into
REditorSupport:masterfrom
renkun-ken:codex/fix-polars-query-member-completion

Conversation

@renkun-ken

@renkun-ken renkun-ken commented Oct 8, 2026 •

Copy link
Copy Markdown
Member
library(polars)

csv_file <- tempfile(fileext = ".csv")
write.csv(iris, csv_file, row.names = FALSE)

q <- pl$scan_csv(csv_file, infer_schema_files = 10)

q1 <- q$filter(pl$col("Sepal.Length") > 5)
q1

q1 <- q$filter(pl$col("Sepal.Length") > 5)$group_by("Species")$agg(pl$all()$median())$collect()
q1

q2 <- q1$group_by("Species")$agg(pl$all()$sum())
q2

Typing q1$ or q2$ after assigning Polars query chains could fall back to document-word completion. This also affected a reassigned q1 ending in collect() and an eager aggregation assigned to q2: both should expose DataFrame members instead of the earlier LazyFrame members.

Use bindings before the cursor when selecting package metadata, and reduce repeated metadata lookups and clock checks. Prepare compact return-class guarantees for expensive package functions with unknown arguments in the background worker, avoiding costly default and argument traversal during completion. Keep argument matching and ordinary inference for argument-dependent results, and discard prepared returns when loaded definitions change. Document expressions, methods, defaults, and native calls are never executed by inference.

Regression coverage includes the original query assignments, reassignment through collect(), eager group_by()/agg(), and each first LSP dollar trigger after editing without receiver warming or retries. Generic fixtures cover argument-sensitive returns, invalid argument matching, metadata changes, and absence of execution.

Validation: installed-package member-completion, member-provider, S4, S7, completion, and completion-typing suites passed with Polars 1.16.0. Three S7 capability-dependent tests were skipped. Changed lines pass lint checks, and git diff --check passes.

@renkun-ken renkun-ken changed the title Fix member completion for assigned Polars query chains Fix member completion for assigned and collected Polars queries Oct 8, 2026
@renkun-ken
renkun-ken requested a review from eitsupi October 8, 2026 13:30

@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 with ChatGPT against the latest 9fb65b1.

The fix looks sound to me. In particular, restricting package-selection history to bindings before the cursor is a clear correctness improvement, and the prepared return summaries remain generic rather than adding Polars-specific rules. The regression coverage for reassignment, collected DataFrames, argument-dependent returns, invalid matching, and stale metadata is also reassuring.

Two non-blocking architectural notes:

  • member_prepare_returns() is really a semantic inference/summary pass rather than extraction. Keeping it in member-extraction.R creates a somewhat circular responsibility between extraction and inference; I think this boundary is worth cleaning up before more summary passes are added.
  • The per-function inference is bounded, but package-wide return preparation currently has no overall time/node budget. Since this moves work from request time into the metadata worker, a package-level bound may eventually be useful to keep preparation predictable.

Neither point looks like a blocker for this PR. LGTM, approving.

@renkun-ken
renkun-ken merged commit 00d171d into REditorSupport:master Oct 8, 2026
10 checks passed
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