lsp tool: offer to install a missing language server
This commit is contained in:
1 parent
ee167ce6ed
commit
ee0714d271
10 files changed
+378
-5
No files matched your search
@@ -59,6 +59,7 @@ pub type LspStatus = Box<
|
||||
|
||||
enum Ui {
|
||||
Ev(Event),
|
||||
Ask(String, tokio::sync::oneshot::Sender<bool>),
|
||||
Done(Result<(), String>),
|
||||
Compacted(Result<bool, String>),
|
||||
}
|
||||
@@ -88,6 +89,8 @@ struct App {
|
||||
ctx_tokens: usize,
|
||||
quit: bool,
|
||||
hint: String,
|
||||
/// pending yes/no question from a tool
|
||||
ask: Option<(String, tokio::sync::oneshot::Sender<bool>)>,
|
||||
}
|
||||
|
||||
const HELP: &str = "enter send · alt-enter/ctrl-j newline · esc/ctrl-c abort · ctrl-o expand tools · pgup/pgdn scroll · tab @file · \
|
||||
@@ -135,6 +138,18 @@ pub async fn run(setup: Setup) -> std::io::Result<()> {
|
||||
} = setup;
|
||||
let (tx, mut rx) = mpsc::unbounded_channel();
|
||||
agent.bus.add(Forward(tx.clone()));
|
||||
{
|
||||
let tx = tx.clone();
|
||||
let _ = agent
|
||||
.cx
|
||||
.state
|
||||
.ask
|
||||
.set(std::sync::Arc::new(move |q: String| {
|
||||
let (otx, orx) = tokio::sync::oneshot::channel();
|
||||
let _ = tx.send(Ui::Ask(q, otx));
|
||||
Box::pin(async move { orx.await.unwrap_or(false) })
|
||||
}));
|
||||
}
|
||||
let abort: AbortHandle = agent.abort_handle();
|
||||
let cwd = agent.cx.cwd.clone();
|
||||
let mut app = App {
|
||||
@@ -151,6 +166,7 @@ pub async fn run(setup: Setup) -> std::io::Result<()> {
|
||||
ctx_tokens: hx_core::agent::estimate_tokens(&agent.session.messages()),
|
||||
quit: false,
|
||||
hint: String::new(),
|
||||
ask: None,
|
||||
};
|
||||
// show resumed history
|
||||
for m in agent.session.messages() {
|
||||
@@ -194,6 +210,19 @@ pub async fn run(setup: Setup) -> std::io::Result<()> {
|
||||
let Some(Ok(ev)) = k else { break };
|
||||
dirty = true;
|
||||
match ev {
|
||||
TEvent::Key(k) if k.kind != KeyEventKind::Release && app.ask.is_some() => {
|
||||
let yes = match k.code {
|
||||
KeyCode::Char('y' | 'Y') => Some(true),
|
||||
KeyCode::Char('n' | 'N') | KeyCode::Esc => Some(false),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(yes) = yes
|
||||
&& let Some((q, reply)) = app.ask.take()
|
||||
{
|
||||
app.t.push(Item::Info(format!("{q} {}", if yes { "yes" } else { "no" })));
|
||||
let _ = reply.send(yes);
|
||||
}
|
||||
}
|
||||
TEvent::Key(k) if k.kind != KeyEventKind::Release => {
|
||||
if let Some(line) = on_key(&mut app, k, &abort) {
|
||||
submit(&mut app, line, &ctx).await;
|
||||
@@ -206,6 +235,7 @@ pub async fn run(setup: Setup) -> std::io::Result<()> {
|
||||
Some(u) = rx.recv() => {
|
||||
dirty = true;
|
||||
match u {
|
||||
Ui::Ask(q, reply) => app.ask = Some((q, reply)),
|
||||
Ui::Ev(e) => {
|
||||
if let Event::Stream(hx_ai::StreamEvent::Done { usage, .. }) = &e {
|
||||
app.usage.add(usage);
|
||||
@@ -487,7 +517,9 @@ fn draw(f: &mut ratatui::Frame, app: &mut App) {
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
let st = if app.hint.is_empty() {
|
||||
let st = if let Some((q, _)) = &app.ask {
|
||||
format!("[y/n] {q}")
|
||||
} else if app.hint.is_empty() {
|
||||
format!(
|
||||
"{spin} {:?} · {} · ctx {}k · {}↑ {}↓{q}{up}",
|
||||
app.kind,
|
||||
@@ -545,6 +577,7 @@ mod tests {
|
||||
ctx_tokens: 12_000,
|
||||
quit: false,
|
||||
hint: String::new(),
|
||||
ask: None,
|
||||
};
|
||||
app.t.push(Item::User("hello".into()));
|
||||
app.t.push(Item::Assistant("hi **there**".into()));
|
||||
|
||||
Reference in new issue
Block a user