Skip to content

Commit acd8514

Browse files
committed
Simplify passing commands.
Prefer passing array instead of chaining.
1 parent c9f4d25 commit acd8514

File tree

3 files changed

+50
-45
lines changed

3 files changed

+50
-45
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
doc/tags
22
__pycache__
3+
.pytest_cache
34
.idea
45
target
56
rplugin/python3/tests

src/languageclient.rs

+46-44
Original file line numberDiff line numberDiff line change
@@ -216,21 +216,17 @@ impl State {
216216
}
217217

218218
fn define_signs(&mut self) -> Result<()> {
219-
info!("Define signs");
220-
let cmd = self.get(|state| {
221-
let mut cmd = "echo".to_owned();
219+
info!("Defining signs");
222220

223-
for entry in state.diagnosticsDisplay.values() {
224-
cmd += &format!(
225-
" | execute 'sign define LanguageClient{} text={} texthl={}'",
226-
entry.name, entry.signText, entry.signTexthl,
227-
);
228-
}
221+
let mut cmds = vec![];
222+
for entry in self.diagnosticsDisplay.values() {
223+
cmds.push(format!(
224+
"sign define LanguageClient{} text={} texthl={}",
225+
entry.name, entry.signText, entry.signTexthl,
226+
));
227+
}
229228

230-
Ok(cmd)
231-
})?;
232-
self.command(&cmd)?;
233-
info!("Define signs");
229+
self.command(cmds)?;
234230
Ok(())
235231
}
236232

@@ -719,9 +715,11 @@ impl State {
719715
self.text_documents.retain(|f, _| !f.starts_with(&root));
720716
self.roots.remove(languageId);
721717

722-
self.call::<_, u8>(None, "s:ExecuteAutocmd", "LanguageClientStopped")?;
723-
self.command(&format!("let {}=0", VIM__ServerStatus))?;
724-
self.command(&format!("let {}=''", VIM__ServerStatusMessage))?;
718+
self.command(vec![
719+
format!("let {}=0", VIM__ServerStatus),
720+
format!("let {}=''", VIM__ServerStatusMessage),
721+
])?;
722+
self.notify(None, "s:ExecuteAutocmd", "LanguageClientStopped")?;
725723

726724
info!("End cleanup");
727725
Ok(())
@@ -1819,7 +1817,7 @@ impl State {
18191817
}
18201818
self.process_diagnostics(&current_filename, &diagnostics)?;
18211819
self.languageClient_handleCursorMoved(&json!({}).to_params()?)?;
1822-
self.call::<_, u8>(None, "s:ExecuteAutocmd", "LanguageClientDiagnosticsChanged")?;
1820+
self.notify(None, "s:ExecuteAutocmd", "LanguageClientDiagnosticsChanged")?;
18231821

18241822
info!("End {}", lsp::notification::PublishDiagnostics::METHOD);
18251823
Ok(())
@@ -2513,30 +2511,30 @@ impl State {
25132511

25142512
pub fn rust_handleBeginBuild(&mut self, _params: &Option<Params>) -> Result<()> {
25152513
info!("Begin {}", NOTIFICATION__RustBeginBuild);
2516-
self.command(&format!(
2517-
"let {}=1 | let {}='Rust: build begin'",
2518-
VIM__ServerStatus, VIM__ServerStatusMessage
2519-
))?;
2514+
self.command(vec![
2515+
format!("let {}=1", VIM__ServerStatus),
2516+
format!("let {}='Rust: build begin'", VIM__ServerStatusMessage),
2517+
])?;
25202518
info!("End {}", NOTIFICATION__RustBeginBuild);
25212519
Ok(())
25222520
}
25232521

25242522
pub fn rust_handleDiagnosticsBegin(&mut self, _params: &Option<Params>) -> Result<()> {
25252523
info!("Begin {}", NOTIFICATION__RustDiagnosticsBegin);
2526-
self.command(&format!(
2527-
"let {}=1 | let {}='Rust: diagnostics begin'",
2528-
VIM__ServerStatus, VIM__ServerStatusMessage
2529-
))?;
2524+
self.command(vec![
2525+
format!("let {}=1", VIM__ServerStatus),
2526+
format!("let {}='Rust: diagnostics begin'", VIM__ServerStatusMessage),
2527+
])?;
25302528
info!("End {}", NOTIFICATION__RustDiagnosticsBegin);
25312529
Ok(())
25322530
}
25332531

25342532
pub fn rust_handleDiagnosticsEnd(&mut self, _params: &Option<Params>) -> Result<()> {
25352533
info!("Begin {}", NOTIFICATION__RustDiagnosticsEnd);
2536-
self.command(&format!(
2537-
"let {}=0 | let {}='Rust: diagnostics end'",
2538-
VIM__ServerStatus, VIM__ServerStatusMessage
2539-
))?;
2534+
self.command(vec![
2535+
format!("let {}=0", VIM__ServerStatus),
2536+
format!("let {}='Rust: diagnostics end'", VIM__ServerStatusMessage),
2537+
])?;
25402538
info!("End {}", NOTIFICATION__RustDiagnosticsEnd);
25412539
Ok(())
25422540
}
@@ -2569,13 +2567,14 @@ impl State {
25692567
}
25702568
}
25712569

2572-
self.command(&format!(
2573-
"let {}={} | let {}='{}'",
2574-
VIM__ServerStatus,
2575-
if done { 0 } else { 1 },
2576-
VIM__ServerStatusMessage,
2577-
&escape_single_quote(buf)
2578-
))?;
2570+
self.command(vec![
2571+
format!("let {}={}", VIM__ServerStatus, if done { 0 } else { 1 }),
2572+
format!(
2573+
"let {}='{}'",
2574+
VIM__ServerStatusMessage,
2575+
&escape_single_quote(buf)
2576+
),
2577+
])?;
25792578
info!("End {}", NOTIFICATION__WindowProgress);
25802579
Ok(())
25812580
}
@@ -2589,15 +2588,18 @@ impl State {
25892588
+ params.onIdMappedCount
25902589
+ params.onIndexedCount;
25912590
if total != 0 {
2592-
self.command(&format!(
2593-
"let {}=1 | let {}='cquery: indexing ({} jobs)'",
2594-
VIM__ServerStatus, VIM__ServerStatusMessage, params.indexRequestCount
2595-
))?;
2591+
self.command(vec![
2592+
format!("let {}=1", VIM__ServerStatus),
2593+
format!(
2594+
"let {}='cquery: indexing ({} jobs)'",
2595+
VIM__ServerStatusMessage, params.indexRequestCount
2596+
),
2597+
])?;
25962598
} else {
2597-
self.command(&format!(
2598-
"let {}=0 | let {}='cquery: idle'",
2599-
VIM__ServerStatus, VIM__ServerStatusMessage
2600-
))?;
2599+
self.command(vec![
2600+
format!("let {}=0", VIM__ServerStatus),
2601+
format!("let {}='cquery: idle'", VIM__ServerStatusMessage),
2602+
])?;
26012603
}
26022604
info!("End {}", NOTIFICATION__CqueryProgress);
26032605
Ok(())

tests/test.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@ if [[ $ret != 0 ]]; then
2727
cat $LOG
2828
fi
2929

30-
kill $PID
30+
if [[ -n $PID ]]; then
31+
kill $PID
32+
fi
3133
exit $ret

0 commit comments

Comments
 (0)