- 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>
89 lines
3.2 KiB
Rust
89 lines
3.2 KiB
Rust
//! Workspace state that commands read and change.
|
|
|
|
use std::collections::{BTreeMap, BTreeSet};
|
|
|
|
use serde_json::{Map, Value};
|
|
|
|
use crate::buffers::Buffers;
|
|
use crate::cmd::ui::UiCommand;
|
|
use crate::journal::Journal;
|
|
use crate::settings::Settings;
|
|
use crate::workspace::Workspace;
|
|
use crate::{EngineConfig, Event, NotificationLevel};
|
|
|
|
/// Everything the engine knows about the running session.
|
|
#[derive(Debug, Default)]
|
|
pub struct State {
|
|
/// Number of commands that ran to completion, successful or not.
|
|
pub commands_run: u64,
|
|
/// The open project, if any.
|
|
pub project: Option<Workspace>,
|
|
/// Open buffers. Empty whenever no project is open.
|
|
pub buffers: Buffers,
|
|
/// Settings, saved to the config directory when the engine has one.
|
|
pub settings: Settings,
|
|
/// Whether the OS prefers a dark theme, as the frontend reported it with
|
|
/// `theme.systemPreference`; `None` until then.
|
|
pub system_dark: Option<bool>,
|
|
/// Where the engine stores its files; `None` for an engine without
|
|
/// persistence ([`crate::Engine::new`]).
|
|
pub config: Option<EngineConfig>,
|
|
/// The crash-recovery journal of the open project; `None` without a
|
|
/// project or without persistence.
|
|
pub journal: Option<Journal>,
|
|
/// Ids of the engine's own commands, which UI commands may not take.
|
|
pub engine_commands: BTreeSet<&'static str>,
|
|
/// UI commands the frontend registered (`ui.registerCommands`), by id.
|
|
pub ui_commands: BTreeMap<String, UiCommand>,
|
|
/// Running searches (`search.find`).
|
|
pub searches: crate::cmd::search::Searches,
|
|
/// The symbol index of the open project (`index.status`, `goto.*`).
|
|
pub index: crate::cmd::goto::IndexState,
|
|
/// Syntax trees and outlines of open PHP buffers (`syntax.outline`).
|
|
pub syntax: crate::cmd::syntax::Syntax,
|
|
/// PHP and Phpactor (`toolchain.status`).
|
|
pub toolchain: crate::cmd::toolchain::Toolchain,
|
|
/// Open integrated terminals (`terminal.*`).
|
|
pub terminals: crate::cmd::terminal::Terminals,
|
|
/// The language server session and its diagnostics (M3.3).
|
|
pub lsp: crate::lsp::Lsp,
|
|
/// Number of notifications emitted, for their ids.
|
|
notifications: u64,
|
|
/// Events queued for the host, oldest first.
|
|
events: Vec<Event>,
|
|
}
|
|
|
|
impl State {
|
|
/// Queues an event for the host.
|
|
pub fn emit(&mut self, event: Event) {
|
|
self.events.push(event);
|
|
}
|
|
|
|
/// Queues an [`Event::Notification`] with a fresh id (`n1`, `n2`…).
|
|
pub fn notify(
|
|
&mut self,
|
|
level: NotificationLevel,
|
|
message_key: Option<&str>,
|
|
message: Option<String>,
|
|
params: Option<Map<String, Value>>,
|
|
) {
|
|
self.notifications = self.notifications.saturating_add(1);
|
|
self.emit(Event::Notification {
|
|
id: format!("n{}", self.notifications),
|
|
level,
|
|
message_key: message_key.map(str::to_string),
|
|
message,
|
|
params,
|
|
});
|
|
}
|
|
|
|
/// Takes the queued events, oldest first.
|
|
pub fn take_events(&mut self) -> Vec<Event> {
|
|
std::mem::take(&mut self.events)
|
|
}
|
|
|
|
/// Whether a project is open.
|
|
pub fn has_project(&self) -> bool {
|
|
self.project.is_some()
|
|
}
|
|
}
|