Skip to content

Commit 089c480

Browse files
authored
Refactor lsp module into smaller modules for readability (#1207)
* Refactor lsp module into smaller modules for readability * Fix clippy issues
1 parent 0f0ad73 commit 089c480

22 files changed

+4296
-4207
lines changed

src/config/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod server_command;
33
use crate::{
44
types::{
55
CodeLensDisplay, DiagnosticsDisplay, DiagnosticsList, DocumentHighlightDisplay,
6-
HoverPreviewOption, RootMarkers, SelectionUI, UseVirtualText,
6+
HoverPreviewOption, RootMarkers, SelectionUi, UseVirtualText,
77
},
88
vim::Vim,
99
};
@@ -55,7 +55,7 @@ impl SemanticTokenMapping {
5555
pub struct Config {
5656
pub auto_start: bool,
5757
pub server_commands: HashMap<String, ServerCommand>,
58-
pub selection_ui: SelectionUI,
58+
pub selection_ui: SelectionUi,
5959
pub trace: TraceOption,
6060
pub settings_path: Vec<String>,
6161
pub load_settings: bool,
@@ -105,7 +105,7 @@ impl Default for Config {
105105
Self {
106106
server_commands: HashMap::new(),
107107
auto_start: true,
108-
selection_ui: SelectionUI::LocationList,
108+
selection_ui: SelectionUi::LocationList,
109109
selection_ui_auto_open: true,
110110
trace: TraceOption::default(),
111111
diagnostics_enable: true,
@@ -218,9 +218,9 @@ impl Config {
218218
let res: DeserializableConfig = vim.eval(req.replace("\n", ""))?;
219219
let loaded_fzf = vim.eval::<_, i64>("get(g:, 'loaded_fzf')")? == 1;
220220
let selection_ui = match res.selection_ui {
221-
Some(s) => SelectionUI::from_str(&s)?,
222-
None if loaded_fzf => SelectionUI::Funcref,
223-
None => SelectionUI::default(),
221+
Some(s) => SelectionUi::from_str(&s)?,
222+
None if loaded_fzf => SelectionUi::Funcref,
223+
None => SelectionUi::default(),
224224
};
225225

226226
let diagnostics_list = match res.diagnostics_list {

src/extensions/clangd.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::{language_client::LanguageClient, utils::ToUrl};
1+
use crate::language_client::LanguageClient;
2+
use crate::utils::ToUrl;
23
use anyhow::Result;
34
use jsonrpc_core::Value;
45
use lsp_types::{request::Request, TextDocumentIdentifier};

src/extensions/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub mod clangd;
22
pub mod gopls;
33
pub mod java;
4+
pub mod rls;
45
pub mod rust_analyzer;
56

67
use crate::language_client::LanguageClient;

src/extensions/rls.rs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
use crate::language_client::LanguageClient;
2+
use crate::types::{VIM_SERVER_STATUS, VIM_SERVER_STATUS_MESSAGE};
3+
use crate::utils::escape_single_quote;
4+
use anyhow::Result;
5+
use jsonrpc_core::Value;
6+
use serde::{Deserialize, Serialize};
7+
8+
pub mod notification {
9+
pub const WINDOW_PROGRESS: &str = "window/progress";
10+
pub const RUST_DOCUMENT_BEGIN_BUILD: &str = "rustDocument/beginBuild";
11+
pub const RUST_DOCUMENT_DIAGNOSTICS_BEGIN: &str = "rustDocument/diagnosticsBegin";
12+
pub const RUST_DOCUMENT_DIAGNOSTICS_END: &str = "rustDocument/diagnosticsEnd";
13+
}
14+
15+
#[derive(Debug, Serialize, Deserialize)]
16+
pub struct WindowProgressParams {
17+
pub title: Option<String>,
18+
pub message: Option<String>,
19+
pub percentage: Option<f64>,
20+
pub done: Option<bool>,
21+
}
22+
23+
impl LanguageClient {
24+
#[tracing::instrument(level = "info", skip(self))]
25+
pub fn rls_window_progress(&self, params: &Value) -> Result<()> {
26+
let params = WindowProgressParams::deserialize(params)?;
27+
28+
let done = params.done.unwrap_or(false);
29+
30+
let mut buf = "LS: ".to_owned();
31+
32+
if done {
33+
buf += "Idle";
34+
} else {
35+
// For RLS this can be "Build" or "Diagnostics" or "Indexing".
36+
buf += params.title.as_ref().map(AsRef::as_ref).unwrap_or("Busy");
37+
38+
// For RLS this is the crate name, present only if the progress isn't known.
39+
if let Some(message) = params.message {
40+
buf += &format!(" ({})", &message);
41+
}
42+
// For RLS this is the progress percentage, present only if the it's known.
43+
if let Some(percentage) = params.percentage {
44+
buf += &format!(" ({:.1}% done)", percentage);
45+
}
46+
}
47+
48+
self.vim()?.command(vec![
49+
format!("let {}={}", VIM_SERVER_STATUS, if done { 0 } else { 1 }),
50+
format!(
51+
"let {}='{}'",
52+
VIM_SERVER_STATUS_MESSAGE,
53+
&escape_single_quote(buf)
54+
),
55+
])?;
56+
Ok(())
57+
}
58+
59+
#[tracing::instrument(level = "info", skip(self))]
60+
pub fn rls_handle_begin_build(&self, _params: &Value) -> Result<()> {
61+
self.vim()?.command(vec![
62+
format!("let {}=1", VIM_SERVER_STATUS),
63+
format!("let {}='Rust: build begin'", VIM_SERVER_STATUS_MESSAGE),
64+
])?;
65+
Ok(())
66+
}
67+
68+
#[tracing::instrument(level = "info", skip(self))]
69+
pub fn rls_handle_diagnostics_begin(&self, _params: &Value) -> Result<()> {
70+
self.vim()?.command(vec![
71+
format!("let {}=1", VIM_SERVER_STATUS),
72+
format!(
73+
"let {}='Rust: diagnostics begin'",
74+
VIM_SERVER_STATUS_MESSAGE
75+
),
76+
])?;
77+
Ok(())
78+
}
79+
80+
#[tracing::instrument(level = "info", skip(self))]
81+
pub fn rls_handle_diagnostics_end(&self, _params: &Value) -> Result<()> {
82+
self.vim()?.command(vec![
83+
format!("let {}=0", VIM_SERVER_STATUS),
84+
format!("let {}='Rust: diagnostics end'", VIM_SERVER_STATUS_MESSAGE),
85+
])?;
86+
Ok(())
87+
}
88+
}

src/extensions/rust_analyzer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ pub struct InlayHint {
6161
pub label: String,
6262
}
6363

64-
impl Into<types::InlayHint> for InlayHint {
65-
fn into(self) -> types::InlayHint {
64+
impl From<InlayHint> for types::InlayHint {
65+
fn from(hint: InlayHint) -> Self {
6666
types::InlayHint {
67-
range: self.range,
68-
label: self.label,
67+
range: hint.range,
68+
label: hint.label,
6969
}
7070
}
7171
}

0 commit comments

Comments
 (0)