M3: lens LSP diagnostics + lsp tool
ci / check (push) Canceled after 0s

- seq log: monotonic project/file seq with change source
- minimal LSP JSON-RPC client (no lsp-types): framing, requests with timeout, server->client requests,
  publishDiagnostics with versions, $/progress + rust-analyzer serverStatus busy tracking
- manager: built-in table (rust-analyzer, tsserver, pyright, gopls, clangd), outermost-root detection,
  lazy spawn, idle eviction, crash restart with 2-failure breaker, degradation notes, ContentModified retry,
  session-start warmup, config overrides/disable
- turn-end hook: diagnostics for files changed this turn, errors first, per-file cap, total cap,
  unchanged findings not repeated, one 'no problems' after a fix; agent_end/off modes
- lsp tool: diagnostics, definition, references, hover, symbols
- tests: real rust-analyzer + pyright (skipped if absent); tests/lens_e2e.sh proves an introduced type error
  is surfaced and fixed without prompting

Closes #21, closes #22, closes #23, closes #24, closes #25, closes #26
This commit is contained in:
hermes committed 2026-09-30 10:48:37 +00:00
1 parent 89c9833e43
commit 9b8cf48e21
13 files changed
+1522 -17

No files matched your search

+63
View File
@@ -52,6 +52,18 @@ struct Config {
max_tokens: Option<u32>,
/// Replaces the built-in system prompt (AGENTS.md etc. are still appended).
system_prompt: Option<String>,
lsp: Option<LspCfg>,
}
#[derive(Default, Clone, serde::Deserialize)]
#[serde(default, deny_unknown_fields)]
struct LspCfg {
/// turn_end (default) | agent_end | off
mode: Option<hx_lens::Mode>,
/// extra or overriding servers (same `id` replaces a built-in)
servers: Vec<hx_lens::manager::ServerCfg>,
/// built-in server ids to disable
disable: Vec<String>,
}
impl Config {
@@ -74,6 +86,7 @@ impl Config {
compact_at: o.compact_at.or(c.compact_at),
max_tokens: o.max_tokens.or(c.max_tokens),
system_prompt: o.system_prompt.or(c.system_prompt),
lsp: o.lsp.or(c.lsp),
};
}
Ok(c)
@@ -218,6 +231,39 @@ async fn main() -> Result<()> {
if let Some(n) = cfg.max_tokens {
agent.max_tokens = n;
}
let lcfg = cfg.lsp.clone().unwrap_or_default();
let mut servers = hx_lens::manager::default_servers();
servers.retain(|s| !lcfg.disable.contains(&s.id) && !lcfg.servers.iter().any(|o| o.id == s.id));
servers.extend(lcfg.servers);
let mgr = Arc::new(hx_lens::manager::Manager::new(cwd.clone(), servers));
let mode = lcfg.mode.unwrap_or(hx_lens::Mode::TurnEnd);
if mode != hx_lens::Mode::Off {
agent
.bus
.add(hx_lens::Lens::new(mgr.clone(), Default::default(), mode));
agent.tools.add(hx_lens::LspTool { mgr: mgr.clone() });
// rust-analyzer & co are slow to index: start servers for languages present at the top level now
let probe: Vec<_> = std::fs::read_dir(&cwd)
.into_iter()
.flatten()
.flatten()
.map(|e| e.path())
.chain(
std::fs::read_dir(cwd.join("src"))
.into_iter()
.flatten()
.flatten()
.map(|e| e.path()),
)
.filter(|p| p.is_file() && mgr.server_for(p).is_some())
.collect();
let mut seen = std::collections::HashSet::new();
let probe = probe
.into_iter()
.filter(|p| seen.insert(mgr.server_for(p).map(|s| s.id.clone())))
.collect();
mgr.warm(probe).await;
}
let Some(prompt) = cli.print else {
hx_tui::run(hx_tui::Setup {
agent,
@@ -225,8 +271,16 @@ async fn main() -> Result<()> {
make_provider: Box::new(provider),
default_model,
pricing,
lsp_status: {
let m = mgr.clone();
Box::new(move || {
let m = m.clone();
Box::pin(async move { m.status().await })
})
},
})
.await?;
mgr.shutdown().await;
return Ok(());
};
agent.bus.add(Printer);
@@ -246,6 +300,15 @@ async fn main() -> Result<()> {
u.output_tokens,
path.display()
);
for n in mgr
.status()
.await
.iter()
.filter(|s| !s.contains(": running") && !s.contains(": stopped"))
{
eprintln!("[lsp] {n}");
}
mgr.shutdown().await;
r?;
Ok(())
}