4 Commits

Author SHA1 Message Date
Teknium
52271332db refactor(agent/lsp): table-driven lsp argparse tree, compact install/eventlog/protocol helpers 2026-09-02 18:56:15 -07:00
Teknium
09b84b96b2 refactor(agent/lsp): compact client/manager/servers/install/cli; dict-dispatch installers; shared warn-once + await-push helpers 2026-09-02 18:22:13 -07:00
Teknium
b6e1037730 refactor(agent/lsp): table-driven server registry, shared client/manager helpers, compact docs
- servers.py: per-language _root_*/_spawn_* functions collapsed into declarative
  ServerDef entries built by _make_spec/_simple_spawn/_markers_root (-707 LOC)
- client.py: _write/_send_reply/_cancel_task helpers replace repeated
  try/except blocks; handler dispatch tables for server->client requests
- manager.py: _broken_key unifies the (server_id, root) key derivation
- install.py/cli.py/eventlog.py/workspace.py/protocol.py/range_shift.py/
  reporter.py: dedupe helpers (_find_binary, _link_into_bin, _run_installer,
  _emit_once, _walk_up), drop dead log_no_server_configured, compact docs
2026-09-02 13:53:27 -07:00
Teknium
19071529f6 fix(lsp): shift baseline diagnostics into post-edit coordinates (#25978)
Pre-existing diagnostics below an edit point used to surface as 'LSP
diagnostics introduced by this edit' whenever the edit deleted or
inserted lines.  The delta-filter key included the diagnostic's
range, so the same logical error reported at a different line in
the post-edit snapshot looked like a brand new diagnostic.

Concrete case: deleting 14 lines in cli.py caused Pyright errors at
lines 9873, 10590, 12413, 13004 (unrelated to the edit) to be
reported as introduced by it.

Fix: build a piecewise-linear line-shift map (via difflib's
SequenceMatcher) from pre and post content, and remap baseline
diagnostics into post-edit coordinates before the set-difference.
Diagnostics in deleted regions drop out cleanly; diagnostics below
the edit shift by the right amount; diagnostics above are untouched.
The strict (range-aware) equality key stays — so a genuinely new
instance of an identical error class at a different line still
surfaces as new.

Pieces:
- agent/lsp/range_shift.py — build_line_shift, shift_diagnostic_range,
  shift_baseline.  Pure functions, no LSP state.
- agent/lsp/manager.py — LSPService.get_diagnostics_sync gains an
  optional line_shift kwarg; baseline is shift_baseline'd before
  computing the seen-set.  _diag_key keeps the strict range key.
- tools/file_operations.py — write_file captures pre_content for any
  LSP-handled extension (not just LINTERS_INPROC) and passes pre/post
  to _maybe_lsp_diagnostics, which builds the shift map.
- New _lsp_handles_extension helper guards the pre_content read.

Trade-offs preserved:
- Genuinely new same-class errors at different lines still surface
  (content-only key would have swallowed them).
- Pre-existing errors at unshifted positions still get filtered
  (covered by the strict-key path with no shift).
- Best-effort: when pre_content can't be captured (file didn't
  exist, permissions), the unshifted comparison still catches
  most pre-existing errors; the edge case it misses is a new file
  with a non-empty baseline, which is structurally impossible.
2026-05-14 15:56:07 -07:00