M3.3: engine wiring for Phpactor and diagnostics

- One Phpactor per open project on its own session thread, started when
  the toolchain is ready; ordered document sync from buffer.edit and the
  pump; lspStatus, diagnosticsChanged, diagnostics.list, lsp.status,
  lsp.restart; app.quit stops the server synchronously.
- Phpactor 2026.06.25.0 on Windows: keep-alive $/lutra/tick (its event
  loop only runs on stdin input), in-process diagnostics and a polling
  watcher through initializationOptions (amphp subprocesses fail), 500 ms
  shutdown timeout.
- Editor lint extension (underlines, gutter dots, hover; tokens only) and
  a Problems tab in the bottom panel; problems.open Mod+Alt+P.
- Tests: engine tests against the fake server (incl. sync proptest), an
  ignored real-Phpactor test, a TCP test, Vitest for lint and Problems.
- Docs: architecture, gaps G6, parity (Inspections 4% est.), ui-parity,
  roadmap, ROADMAP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-21 18:58:32 +02:00
parent 65c6966588
commit 13c76d3046
34 changed files with 3562 additions and 37 deletions

View file

@ -49,6 +49,7 @@ impl Command for Quit {
fn run(&self, state: &mut State, _params: Value) -> Result<Outcome, EngineError> {
crate::cmd::terminal::close_all(state);
crate::lsp::shutdown_now(state);
Ok(Outcome::effect(Effect::Quit))
}
}

View file

@ -167,6 +167,7 @@ impl Command for Edit {
let (version, dirty) = (open.version, open.dirty());
let now = std::time::Instant::now();
journal::mark_edited(state, p.id, now);
crate::lsp::record_edits(state, p.id, p.base_version, &edits);
super::syntax::record_edits(state, p.id, p.base_version, edits, now);
state.emit(Event::BufferChanged { id: p.id, version });
if dirty != was_dirty {

View file

@ -0,0 +1,110 @@
//! Language server commands of M3.3: `diagnostics.list`, `lsp.status` and
//! `lsp.restart`. The wiring itself lives in [`crate::lsp`].
use serde::Deserialize;
use serde_json::{Value, json};
use super::params::{parse, project_path};
use crate::workspace::path_string;
use crate::{Command, CommandSpec, EngineError, Outcome, Registry, State};
/// Registers the commands of this module.
///
/// # Errors
/// [`EngineError::Internal`] if an id is already taken.
pub fn register(registry: &mut Registry) -> Result<(), EngineError> {
registry.register(Box::new(List))?;
registry.register(Box::new(Status))?;
registry.register(Box::new(Restart))?;
Ok(())
}
/// Params of `diagnostics.list`.
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct ListParams {
/// Only this file (project-relative or absolute inside the project).
#[serde(default)]
path: Option<String>,
}
/// `diagnostics.list`: the language server's current diagnostics.
pub struct List;
impl Command for List {
fn spec(&self) -> &CommandSpec {
&CommandSpec {
id: "diagnostics.list",
label: "List Diagnostics",
menu_path: None,
default_shortcut: None,
params: "{ path?: string }; returns { files: [{ path, items: [{ range: { start: { line, column }, end }, severity: error|warning|info|hint, message, source?, code? }] }] } sorted by path, only files with diagnostics; columns are UTF-16; empty without a project or language server",
}
}
fn run(&self, state: &mut State, params: Value) -> Result<Outcome, EngineError> {
let command = self.spec().id;
let p: ListParams = parse(command, params)?;
let path = match p.path {
Some(path) if state.has_project() => {
Some(path_string(&project_path(state, command, &path)?))
}
Some(_) => return Ok(Outcome::value(json!({ "files": [] }))),
None => None,
};
let files = state.lsp.diagnostics(path.as_deref());
let files =
serde_json::to_value(files).map_err(|e| EngineError::Internal(e.to_string()))?;
Ok(Outcome::value(json!({ "files": files })))
}
}
/// `lsp.status`: the language server's state, as `lspStatus` last reported
/// it.
pub struct Status;
impl Command for Status {
fn spec(&self) -> &CommandSpec {
&CommandSpec {
id: "lsp.status",
label: "Language Server Status",
menu_path: None,
default_shortcut: None,
params: "none; returns { state: starting|ready|restarting|failed|stopped, message?, startupMs? } (startupMs: from start to the first ready)",
}
}
fn run(&self, state: &mut State, _params: Value) -> Result<Outcome, EngineError> {
let mut value = serde_json::to_value(state.lsp.status())
.map_err(|e| EngineError::Internal(e.to_string()))?;
if let (Some(ms), Some(object)) = (state.lsp.startup_ms(), value.as_object_mut()) {
object.insert("startupMs".into(), Value::from(ms));
}
Ok(Outcome::value(value))
}
}
/// `lsp.restart`: stops the language server; the next pump starts a fresh
/// one when the project and toolchain allow it.
pub struct Restart;
impl Command for Restart {
fn spec(&self) -> &CommandSpec {
&CommandSpec {
id: "lsp.restart",
label: "Restart PHP Language Server",
menu_path: Some("Tools/Restart PHP Language Server"),
default_shortcut: None,
params: "none; returns null; lspStatus reports stopped, then starting and ready",
}
}
fn enabled(&self, state: &State) -> bool {
state.has_project()
}
fn run(&self, state: &mut State, _params: Value) -> Result<Outcome, EngineError> {
crate::lsp::restart(state);
Ok(Outcome::value(Value::Null))
}
}

View file

@ -4,6 +4,7 @@ mod app;
mod buffer;
mod file;
pub mod goto;
mod lsp_diagnostics;
mod params;
mod project;
mod recovery;
@ -58,5 +59,6 @@ pub fn register_builtins(registry: &mut Registry) -> Result<(), EngineError> {
registry.register(Box::new(terminal::Input))?;
registry.register(Box::new(terminal::Resize))?;
registry.register(Box::new(terminal::Close))?;
lsp_diagnostics::register(registry)?;
Ok(())
}