1use std::str::FromStr;
2use std::{collections::HashMap, path::PathBuf};
3
4use anyhow::Result;
5use liwe::model::config::Configuration;
6use lsp_server::Connection;
7
8use liwe::fs::{new_for_path, new_from_hashmap};
9use router::{LspClient, Router, ServerConfig};
10
11pub mod router;
12
13#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq, Default)]
14pub struct ServerParams {
15 pub state: Option<HashMap<String, String>>,
16 pub sequential_ids: Option<bool>,
17 pub client_name: Option<String>,
18 pub configuration: Configuration,
19 pub base_path: String,
20}
21
22pub fn main_loop(connection: Connection, params: ServerParams) -> Result<()> {
23 let client = params
24 .clone()
25 .client_name
26 .filter(|name| name.eq("helix"))
27 .map(|_| LspClient::Helix)
28 .unwrap_or(LspClient::Unknown);
29
30 let router = if let Some(state) = params.state {
31 Router::new(
32 connection.sender,
33 ServerConfig {
34 base_path: params.base_path.clone(),
35 state: new_from_hashmap(state),
36 sequential_ids: Some(true),
37 lsp_client: client,
38 configuration: params.configuration,
39 },
40 )
41 } else {
42 Router::new(
43 connection.sender,
44 ServerConfig {
45 base_path: params.base_path.clone(),
46 state: new_for_path(&PathBuf::from_str(¶ms.base_path).expect("to work")),
47 sequential_ids: None,
48 lsp_client: client,
49 configuration: params.configuration,
50 },
51 )
52 };
53
54 router.run(connection.receiver)
55}