Add eval command

This commit is contained in:
Dmitry Sharshakov 2021-08-22 14:44:16 +03:00
parent 838f69929d
commit 3197c2536e
No known key found for this signature in database
GPG key ID: 471FD32E15FD8473
3 changed files with 67 additions and 0 deletions

View file

@ -352,4 +352,19 @@ impl Client {
self.request::<requests::Pause>(args).await self.request::<requests::Pause>(args).await
} }
pub async fn eval(
&mut self,
expression: String,
frame_id: Option<usize>,
) -> Result<requests::EvaluateResponse> {
let args = requests::EvaluateArguments {
expression,
frame_id,
context: None,
format: None,
};
self.request::<requests::Evaluate>(args).await
}
} }

View file

@ -484,6 +484,37 @@ pub mod requests {
type Result = (); type Result = ();
const COMMAND: &'static str = "pause"; const COMMAND: &'static str = "pause";
} }
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct EvaluateArguments {
pub expression: String,
pub frame_id: Option<usize>,
pub context: Option<String>,
pub format: Option<ValueFormat>,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct EvaluateResponse {
pub result: String,
#[serde(rename = "type")]
pub data_type: Option<String>,
pub presentation_hint: Option<VariablePresentationHint>,
pub variables_reference: usize,
pub named_variables: Option<usize>,
pub indexed_variables: Option<usize>,
pub memory_reference: Option<String>,
}
#[derive(Debug)]
pub enum Evaluate {}
impl Request for Evaluate {
type Arguments = EvaluateArguments;
type Result = EvaluateResponse;
const COMMAND: &'static str = "evaluate";
}
} }
// Events // Events

View file

@ -1910,6 +1910,20 @@ mod cmd {
Ok(()) Ok(())
} }
fn debug_eval(
cx: &mut compositor::Context,
args: &[&str],
_event: PromptEvent,
) -> anyhow::Result<()> {
use helix_lsp::block_on;
if let Some(debugger) = cx.editor.debugger.as_mut() {
let id = debugger.stack_pointer.clone().map(|x| x.id);
let response = block_on(debugger.eval(args.join(" "), id))?;
cx.editor.set_status(response.result);
}
Ok(())
}
pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
TypableCommand { TypableCommand {
name: "quit", name: "quit",
@ -2148,6 +2162,13 @@ mod cmd {
doc: "Display tree sitter scopes, primarily for theming and development.", doc: "Display tree sitter scopes, primarily for theming and development.",
fun: tree_sitter_scopes, fun: tree_sitter_scopes,
completer: None, completer: None,
},
TypableCommand {
name: "debug-eval",
alias: None,
doc: "Evaluate expression in current debug context.",
fun: debug_eval,
completer: None,
} }
]; ];