Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 7029815

Browse files
committed
Use proper ids for server->client messages
1 parent 75e466f commit 7029815

File tree

6 files changed

+38
-10
lines changed

6 files changed

+38
-10
lines changed

src/actions/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,8 @@ impl ActionHandler {
471471
trace!("apply_suggestion {:?} {}", location, new_text);
472472
// FIXME should handle the response
473473
let output = serde_json::to_string(
474-
&RequestMessage::new("workspace/applyEdit".to_owned(),
474+
&RequestMessage::new(out.provide_id(),
475+
"workspace/applyEdit".to_owned(),
475476
ApplyWorkspaceEditParams { edit: make_workspace_edit(location, new_text) })
476477
).unwrap();
477478
out.response(output);
@@ -563,7 +564,8 @@ impl ActionHandler {
563564
// Send a workspace edit to make the actual change.
564565
// FIXME should handle the response
565566
let output = serde_json::to_string(
566-
&RequestMessage::new("workspace/applyEdit".to_owned(),
567+
&RequestMessage::new(out.provide_id(),
568+
"workspace/applyEdit".to_owned(),
567569
ApplyWorkspaceEditParams { edit: make_workspace_edit(location, deglob_str) })
568570
).unwrap();
569571
out.response(output);
@@ -658,14 +660,16 @@ impl ActionHandler {
658660
// FIXME should handle the response
659661
if unstable_features {
660662
let output = serde_json::to_string(
661-
&RequestMessage::new(NOTIFICATION__RegisterCapability.to_owned(),
663+
&RequestMessage::new(out.provide_id(),
664+
NOTIFICATION__RegisterCapability.to_owned(),
662665
RegistrationParams { registrations: vec![Registration { id: RANGE_FORMATTING_ID.to_owned(), method: REQUEST__RangeFormatting.to_owned(), register_options: serde_json::Value::Null },
663666
Registration { id: RENAME_ID.to_owned(), method: REQUEST__Rename.to_owned(), register_options: serde_json::Value::Null }] })
664667
).unwrap();
665668
out.response(output);
666669
} else {
667670
let output = serde_json::to_string(
668-
&RequestMessage::new(NOTIFICATION__UnregisterCapability.to_owned(),
671+
&RequestMessage::new(out.provide_id(),
672+
NOTIFICATION__UnregisterCapability.to_owned(),
669673
UnregistrationParams { unregisterations: vec![Unregistration { id: RANGE_FORMATTING_ID.to_owned(), method: REQUEST__RangeFormatting.to_owned() },
670674
Unregistration { id: RENAME_ID.to_owned(), method: REQUEST__Rename.to_owned() }] })
671675
).unwrap();

src/cmd.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ impl server::Output for PrintlnOutput {
193193
println!("{}", output);
194194
}
195195

196+
fn provide_id(&self) -> u64 {
197+
0
198+
}
199+
196200
fn success(&self, id: usize, data: ResponseData) {
197201
println!("{}: {:#?}", id, data);
198202
}

src/lsp_data.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,16 @@ pub struct RequestMessage<T>
200200
where T: Debug + Serialize
201201
{
202202
jsonrpc: &'static str,
203-
pub id: String,
203+
pub id: u64,
204204
pub method: String,
205205
pub params: T,
206206
}
207207

208208
impl <T> RequestMessage<T> where T: Debug + Serialize {
209-
pub fn new(method: String, params: T) -> Self {
209+
pub fn new(id: u64, method: String, params: T) -> Self {
210210
RequestMessage {
211211
jsonrpc: "2.0",
212-
id: "FIXME".to_owned(),
212+
id,
213213
method: method,
214214
params: params
215215
}

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#![feature(rustc_private)]
1212
#![feature(concat_idents)]
1313
#![feature(type_ascription)]
14+
#![feature(integer_atomics)]
1415

1516
extern crate cargo;
1617
#[macro_use]

src/server.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use actions::ActionHandler;
1818
use std::fmt;
1919
use std::io::{self, Read, Write, ErrorKind};
2020
use std::sync::Arc;
21-
use std::sync::atomic::{AtomicBool, Ordering};
21+
use std::sync::atomic::{AtomicBool, Ordering, AtomicU64};
2222
use std::path::PathBuf;
2323

2424
#[cfg(test)]
@@ -547,6 +547,7 @@ impl MessageReader for StdioMsgReader {
547547

548548
pub trait Output: Sync + Send + Clone + 'static {
549549
fn response(&self, output: String);
550+
fn provide_id(&self) -> u64;
550551

551552
fn parse_error(&self) {
552553
self.response(r#"{"jsonrpc": "2.0", "error": {"code": -32700, "message": "Parse error"}, "id": null}"#.to_owned());
@@ -601,7 +602,17 @@ pub trait Output: Sync + Send + Clone + 'static {
601602
}
602603

603604
#[derive(Clone)]
604-
struct StdioOutput;
605+
struct StdioOutput {
606+
next_id: Arc<AtomicU64>,
607+
}
608+
609+
impl StdioOutput {
610+
pub fn new() -> StdioOutput {
611+
StdioOutput {
612+
next_id: Arc::new(AtomicU64::new(1)),
613+
}
614+
}
615+
}
605616

606617
impl Output for StdioOutput {
607618
fn response(&self, output: String) {
@@ -612,14 +623,18 @@ impl Output for StdioOutput {
612623
print!("{}", o);
613624
io::stdout().flush().unwrap();
614625
}
626+
627+
fn provide_id(&self) -> u64 {
628+
self.next_id.fetch_add(1, Ordering::SeqCst)
629+
}
615630
}
616631

617632
pub fn run_server(analysis: Arc<AnalysisHost>, vfs: Arc<Vfs>) {
618633
debug!("Language Server Starting up");
619634
let service = LsService::new(analysis,
620635
vfs,
621636
Box::new(StdioMsgReader),
622-
StdioOutput);
637+
StdioOutput::new());
623638
LsService::run(service);
624639
debug!("Server shutting down");
625640
}

src/test/harness.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ impl ls_server::Output for RecordOutput {
8989
let mut records = self.output.lock().unwrap();
9090
records.push(output);
9191
}
92+
93+
fn provide_id(&self) -> u64 {
94+
0
95+
}
9296
}
9397

9498
#[derive(Clone, Debug)]

0 commit comments

Comments
 (0)