Skip to main content

swls_core/
client.rs

1use std::{collections::HashMap, fmt::Display, pin::Pin};
2
3use crate::lsp_types::request::Request;
4use crate::lsp_types::{Diagnostic, MessageType, Url};
5
6#[derive(Debug)]
7pub struct Resp {
8    pub headers: Vec<(String, String)>,
9    pub body: String,
10    pub status: u16,
11}
12
13#[tower_lsp::async_trait]
14pub trait Client: Clone + ClientSync {
15    async fn log_message<M: Display + Sync + Send + 'static>(&self, ty: MessageType, msg: M) -> ();
16    async fn publish_diagnostics(
17        &self,
18        uri: Url,
19        diags: Vec<Diagnostic>,
20        version: Option<i32>,
21    ) -> ();
22    async fn send_request<R: Request + Sync + Send + 'static>(
23        &self,
24        params: R::Params,
25    ) -> Option<R::Result>
26    where
27        R::Params: Sync + Send + 'static,
28        R::Result: Sync + Send + 'static;
29}
30
31pub trait ClientSync {
32    fn spawn<F: std::future::Future<Output = ()> + Send + 'static>(&self, fut: F);
33    fn spawn_local<F, Fut>(&self, f: F)
34    where
35        F: FnOnce() -> Fut + Send + 'static,
36        Fut: std::future::Future<Output = ()> + 'static;
37    fn fetch(
38        &self,
39        url: &str,
40        headers: &HashMap<String, String>,
41    ) -> Pin<Box<dyn Send + std::future::Future<Output = Result<Resp, String>>>>;
42}