Skip to content

feat(check): PyrightFactsAdapter — pyright-langserver LSP hover oracle - #126

Merged
devin-ai-integration[bot] merged 4 commits into
masterfrom
work/pyright-facts-adapter
Oct 18, 2026
Merged

devin-ai-integration[bot] merged 4 commits into
masterfrom
work/pyright-facts-adapter

Conversation

@espetro

@espetro espetro commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implements PyrightFactsAdapter in src/pyscriptc/typefacts.py — the second FactsProvider, backed by pyright-langserver over stdio LSP rather than a new pyright CLI surface. facts_provider("pyright") now returns it (wired through the existing --checker pyright convention; default unchanged).

  • Long-lived subprocess, lazy-spawned and reused: initialize → didOpen (+ publishDiagnostics wait) → textDocument/hover per query, with a per-(uri, line, char) cache and clean shutdown/exit. Binary resolution: PYRIGHT_LANGSERVER_BIN env (shlex) or constructor command, default pyright-langserver --stdio.
  • Parses pyright's hover plaintext back into the existing dataclasses — (function) def f(a: int) -> str, (variable) x: list[int], (parameter) p: T, (method), class Box(), Name@Scope typevars, Literal[...], (+N overloads) tails. Tolerant: unexpected shapes degrade to "no fact".
  • Semantics match MypyFactsAdapter's contract: AnnAssign targets record the declared type (hover reports narrowed types), Call nodes record the callee's return type, each @overload def-name hover contributes an overload choice, __main__.-prefixed qualnames.
  • Tests: parser unit tests over fixture strings + a skip-marked smoke test that spawns the real langserver when PYRIGHT_LANGSERVER_BIN/pyright-langserver is available. No network.

Preceding fix commit (drop-able): fix(compat2) restores parens in cache.py's except (OSError, ValueError) — ruff format under target-version = "py314" had stripped them. The file is on CI's format --exclude list so both forms are legal, but only the parenthesized form parses on Python <3.14. Note examples/gates_probe.py has the same corruption but is NOT format-excluded — CI's py314 ruff format --check requires the stripped form, so it stays; on <3.14 boxes it simply doesn't parse (an environment gap, not a code bug — CI/dev should run 3.14).

Self-census ballpark bumped +139 fences for the new stdio/threading plumbing.

Known gaps

  • Hover only answers on symbol positions; non-symbol expressions (operators, literals) get no fact — by design.
  • Callable[...] hover types can't express positional-only/keyword-only markers — those come from def signatures only.
  • Local suite needs a CPython 3.14 venv (UV_PYTHON=3.14, as CI sets) — under 3.13 the py314-normalized except A, B: sources and PEP-649 forward-ref tests fail. Verified green on 3.14.8.

Link to Devin session: https://app.devin.ai/sessions/7c91c4c693244acdb1bf765f5bc55deb
Open in Devin Desktop: https://app.devin.ai/desktop/session/7c91c4c693244acdb1bf765f5bc55deb?variant=devin
Requested by: @espetro

ruff format under target-version py314 strips except-tuple parens into
'except A, B:', which is only valid on Python 3.14+ and breaks import on
the 3.13 dev venv — pytest collection failed on tests/compat2. Restores
the intended (OSError, ValueError) handler; no semantic change.
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Deploying pyscriptc with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6825fb4
Status:⚡️  Build in progress...

View logs

Implements FactsProvider against a long-lived pyright-langserver
subprocess over stdio JSON-RPC: lazy spawn, hover + didOpen with
publishDiagnostics wait, per-(uri,line,char) cache, clean shutdown.
Hover plaintext is parsed back into the existing TypeFacts/CallableFacts
dataclasses; unexpected shapes degrade to 'no fact'.

- Binary resolution: PYRIGHT_LANGSERVER_BIN env (shlex) or constructor
  command, default 'pyright-langserver --stdio'
- facts_provider('pyright') now dispatches to the adapter
- AnnAssign targets take the declared annotation type (hover reports
  narrowed types); Call expressions record the callee's return type;
  each @overload def name hover contributes an overload choice
- tests: hover-text parser units + skip-marked langserver smoke test
- self-census ballpark +139 fences for the stdio/threading plumbing
@devin-ai-integration
devin-ai-integration Bot force-pushed the work/pyright-facts-adapter branch from 1c39302 to bf7634b Compare October 18, 2026 19:56
@devin-ai-integration
devin-ai-integration Bot merged commit e77c303 into master Oct 18, 2026
8 of 9 checks passed
@devin-ai-integration
devin-ai-integration Bot deleted the work/pyright-facts-adapter branch October 18, 2026 20:05
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