lsp_core/
client.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use std::{collections::HashMap, fmt::Display, pin::Pin};

use lsp_types::{Diagnostic, MessageType, Url};

#[derive(Debug)]
pub struct Resp {
    pub headers: Vec<(String, String)>,
    pub body: String,
    pub status: u16,
}

#[tower_lsp::async_trait]
pub trait Client: Clone + ClientSync {
    async fn log_message<M: Display + Sync + Send + 'static>(&self, ty: MessageType, msg: M) -> ();
    async fn publish_diagnostics(
        &self,
        uri: Url,
        diags: Vec<Diagnostic>,
        version: Option<i32>,
    ) -> ();

    // async fn fetch(
    //     &self,
    //     url: &str,
    //     headers: HeaderMap<String, String>,
    // ) -> std::result::Result<Resp, String>;
}

pub trait ClientSync {
    fn spawn<F: std::future::Future<Output = ()> + Send + 'static>(&self, fut: F);
    fn fetch(
        &self,
        url: &str,
        headers: &HashMap<String, String>,
    ) -> Pin<Box<dyn Send + std::future::Future<Output = Result<Resp, String>>>>;
}