use std::path::PathBuf;
use crate::state::SemanticEditTools;
use anyhow::Result;
use mcplease::{
traits::{Tool, WithExamples},
types::Example,
};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, schemars::JsonSchema)]
#[serde(rename = "set_context")]
pub struct SetContext {
path: String,
}
impl WithExamples for SetContext {
fn examples() -> Vec<Example<Self>> {
vec![Example {
description: "setting context to a development project",
item: Self {
path: "/usr/local/projects/cobol".into(),
},
}]
}
}
impl Tool<SemanticEditTools> for SetContext {
fn execute(self, state: &mut SemanticEditTools) -> Result<String> {
let Self { path } = self;
let path = PathBuf::from(&*shellexpand::tilde(&path));
let response = format!(
"Set context to {path} for session.\n",
path = path.display()
);
state.set_context(None, path)?;
Ok(response)
}
}