Skip to content

Make the undefinedVariable setting work, checking only commands that take a varlist - #386

Merged
jbearak merged 2 commits into
mainfrom
undefined-variable-setting
Nov 5, 2026
Merged

jbearak merged 2 commits into
mainfrom
undefined-variable-setting

Conversation

@jbearak

@jbearak jbearak commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Setting diagnostics.severity.undefinedVariable (in sight.toml or VS Code) did nothing. The check ran only in tests: the language server and sight check never turned it on. Turned on as it was, it read every argument of every command as a variable. Over Stata 18's 3,780 base ados it gave 514,800 diagnostics: as and err from di as err, local, scalar, 53k numbers, 71k strings and 153k macro references.

This PR makes the setting work, with a narrow check:

  • Wiring. The document store always runs the check. DiagnosticsProvider already maps this code's severity from the config and drops it while the setting is off, the default, so changing the setting needs no reparse. Default output is unchanged.
  • Which commands. Only commands whose arguments are a varlist of existing variables, matched in exact case with the abbreviations Stata accepts: summarize, tabulate, tab1, tab2, list, codebook, inspect, regress, logit, probit, logistic, poisson, correlate, pwcorr, keep, drop, order, sort, destring, tostring, xtset and tsset. Also the target of replace.
  • Which names. Only plain names that stand alone. It skips macro references, numbers, strings, wildcards and _all, and any name touching another item: factor-variable and time-series terms (i.x, L.x, c.a#c.b), ranges (x1-x3), and names joined to a macro (v`i').
  • Abbreviations. A name that starts a known variable's name counts as that variable (su pri for price). This applies to the file's own variables, declared ones, and variables from included files.

confirm variable now matches its subcommand in exact case, with every abbreviation down to v. Before, it lowercased the word and accepted only variable and var. StataMP 18 runs confirm v x and rejects confirm Variable x with r(198).

The command database has no varlist-position metadata. Checking more commands would mean adding that metadata, which this PR leaves out.

Corpus: sight check over Stata 18's 3,780 base ados

main (0456d2f) this PR
Default config 36,630 36,630 (identical)
UNDEFINED_VARIABLE with undefinedVariable = "information" 0 (setting ignored) 691
The old check, if it had been wired 514,800

Most of the 691 are variables that mi, st and merge create in the dataset (_mi_id, _t, _st, _merge), which the docs say Sight can't see. A few come from text after a top-level exit, which Stata ignores and Sight still analyzes. That's a separate issue, not fixed here.

Proof: StataMP 18 on voyager accepts confirm variable/var/va/v and rejects confirm Variable/VARIABLE (r(198)). 8 of the 11 analyzer/CLI tests fail on main, and the cross-file abbreviation test fails without its fix. All four gates pass. The corpus result is above.

Reviewed with sol-loop: 2 rounds with gpt-6.1-sol. Sol verdict: approved

Created with Claude Opus 5.5 in T3 Code (Claude Code harness), reviewed by gpt-6.1-sol in Codex.

diagnostics.severity.undefinedVariable never reached the analyzer:
only tests turned the check on. Turned on as it was, the check read
every argument of every command as a variable, giving 514,800
diagnostics over Stata's base ados (as and err in di as err, numbers,
strings, macro references).

The document store now runs the check, and DiagnosticsProvider keeps
dropping its results while the setting is off, its default, so a
settings change needs no reparse. The check reads only commands whose
arguments are a varlist of existing variables (summarize, tabulate,
list, regress, keep, drop, sort, ... with their exact-case
abbreviations) and the target of replace, and only plain names that
stand alone, so it skips macros, numbers, strings, wildcards, _all,
factor-variable and time-series terms, ranges and names joined to a
macro. A prefix of a known variable counts, as Stata accepts
abbreviations. Base ados: 691 diagnostics with the setting on.

confirm variable now matches its subcommand in exact case with every
abbreviation down to v (StataMP 18: confirm v x works, confirm
Variable x is r(198)), instead of lowercasing it and accepting only
variable and var.
su pri was reported when an included file defines price, though the
analyzer accepts the abbreviation for a file's own variables. The
cross-file checks now try a prefix after the exact name.
@coderabbitai

coderabbitai Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

Next included review available in 5 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available. Your 60 included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 1fbc9866-c8d2-4fd5-a916-1f0abf95a4b5
Commits

Reviewing files that changed from the base of the PR and between 0456d2f and 75b9326.

Files selected for processing: 5

  • docs/diagnostics.md
  • src/analyzer/index.ts
  • src/document-store.ts
  • src/providers/diagnostics.ts
  • tests/unit/undefined-variable-check.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@jbearak
jbearak merged commit 64b9051 into main Nov 5, 2026
16 checks passed
@jbearak
jbearak deleted the undefined-variable-setting branch November 5, 2026 16:09
jbearak added a commit that referenced this pull request Nov 5, 2026
…riables

Since #386, `summarize _b` reports no undefined variable, because `_b`
is one of Stata's reserved names, not a variable. The severity-settings
property test still drew `_b` as a variable name and failed about one
run in six.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
jbearak added a commit that referenced this pull request Nov 5, 2026
…riables (#388)

Since #386, `summarize _b` reports no undefined variable, because `_b`
is one of Stata's reserved names, not a variable. The severity-settings
property test still drew `_b` as a variable name and failed about one
run in six.

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant