Skip to main content

lux_lib/progress/
mod.rs

1use crate::{
2    config::Config,
3    progress::client::{LspClient, CLIENT},
4    workspace::Workspace,
5};
6use std::{path::PathBuf, sync::Arc};
7
8pub mod client;
9pub mod layer;
10
11const LUX_LSP_PORT_FILE: &str = "LUX_LSP_PORT_FILE";
12
13pub fn lsp_port_path(workspace: &Workspace) -> PathBuf {
14    match std::env::var(LUX_LSP_PORT_FILE) {
15        Ok(path) => PathBuf::from(path),
16        Err(_) => {
17            tracing::debug!("{LUX_LSP_PORT_FILE} not set.");
18            match Config::project_dirs()
19                .ok()
20                .and_then(|p| p.runtime_dir().map(|p| p.to_path_buf()))
21            {
22                // On Linux & BSD, this is /run/user/<uid>/lux/lsp-port
23                Some(runtime_dir) => runtime_dir.join("lsp-port"),
24                None => {
25                    tracing::debug!("No runtime directory. Falling back to workspace root");
26                    workspace.root().join(".lux").join("lsp-port")
27                }
28            }
29        }
30    }
31}
32
33pub fn set_connection(workspace: &Workspace) {
34    match LspClient::connect(workspace) {
35        Ok(client) => {
36            if let Ok(mut guard) = CLIENT.write() {
37                *guard = Some(Arc::new(client));
38            }
39        }
40        Err(err) => {
41            tracing::debug!(
42                "no lx-lsp server found, LSP progress forwarding remains disabled: {err}"
43            );
44        }
45    }
46}