-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathserver.rs
57 lines (50 loc) · 1.59 KB
/
server.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use async_lsp::{
ClientSocket, LanguageClient,
lsp_types::{NumberOrString, ProgressParams, ProgressParamsValue},
router::Router,
};
use std::{
ops::ControlFlow,
path::PathBuf,
sync::{mpsc, mpsc::Sender},
thread,
};
use crate::{config::workspace::WorkspaceProtoConfigs, state::ProtoLanguageState};
pub struct TickEvent;
pub struct ProtoLanguageServer {
pub client: ClientSocket,
pub counter: i32,
pub state: ProtoLanguageState,
pub configs: WorkspaceProtoConfigs,
}
impl ProtoLanguageServer {
pub fn new_router(client: ClientSocket, cli_include_paths: Vec<PathBuf>) -> Router<Self> {
let mut router = Router::from_language_server(Self {
client,
counter: 0,
state: ProtoLanguageState::new(),
configs: WorkspaceProtoConfigs::new(cli_include_paths),
});
router.event(Self::on_tick);
router
}
fn on_tick(&mut self, _: TickEvent) -> ControlFlow<async_lsp::Result<()>> {
self.counter += 1;
ControlFlow::Continue(())
}
pub fn with_report_progress(&self, token: NumberOrString) -> Sender<ProgressParamsValue> {
let (tx, rx) = mpsc::channel();
let mut socket = self.client.clone();
thread::spawn(move || {
while let Ok(value) = rx.recv() {
if let Err(e) = socket.progress(ProgressParams {
token: token.clone(),
value,
}) {
tracing::error!(error=%e, "failed to report parse progress");
}
}
});
tx
}
}