use reqwest::Method;
use serde::{Deserialize, Serialize};
use crate::client::Client;
use crate::error::BoxxkiteError;
#[derive(Debug, Clone, Deserialize)]
pub struct LspStartResult {
pub lsp_id: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct LspOpenResult {
pub status: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct LspCompletionResult {
#[serde(default)]
pub items: Vec<serde_json::Value>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct LspStopResult {
pub status: String,
}
impl Client {
pub async fn lsp_start(
&self,
session_id: &str,
language: &str,
) -> Result<LspStartResult, BoxxkiteError> {
#[derive(Serialize)]
struct Body<'a> {
language: &'a str,
}
let builder = self
.request(
Method::POST,
&format!("/v1/sandboxes/{session_id}/lsp/start"),
)
.json(&Body { language });
self.send(builder).await
}
pub async fn lsp_open(
&self,
session_id: &str,
lsp_id: &str,
path: &str,
content: &str,
) -> Result<LspOpenResult, BoxxkiteError> {
#[derive(Serialize)]
struct Body<'a> {
path: &'a str,
content: &'a str,
}
let builder = self
.request(
Method::POST,
&format!("/v1/sandboxes/{session_id}/lsp/{lsp_id}/open"),
)
.json(&Body { path, content });
self.send(builder).await
}
pub async fn lsp_completion(
&self,
session_id: &str,
lsp_id: &str,
path: &str,
line: u32,
character: u32,
) -> Result<LspCompletionResult, BoxxkiteError> {
#[derive(Serialize)]
struct Body<'a> {
path: &'a str,
line: u32,
character: u32,
}
let builder = self
.request(
Method::POST,
&format!("/v1/sandboxes/{session_id}/lsp/{lsp_id}/completion"),
)
.json(&Body {
path,
line,
character,
});
self.send(builder).await
}
pub async fn lsp_stop(
&self,
session_id: &str,
lsp_id: &str,
) -> Result<LspStopResult, BoxxkiteError> {
let builder = self.request(
Method::POST,
&format!("/v1/sandboxes/{session_id}/lsp/{lsp_id}/stop"),
);
self.send(builder).await
}
}