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

Revert "Use proper ids for server->client messages" on branch rustfmt-42492 #403

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ rls-analysis = "0.4"
rls-data = "0.7"
rls-span = { version = "0.4" , features = ["serialize-serde"] }
rls-vfs = { version = "0.4", features = ["racer-impls"] }
rustfmt-nightly = "0.1"
rustfmt-nightly = { git = "https://github.com/rust-lang-nursery/rustfmt", branch = "rustfmt-42492" }
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
Expand Down
12 changes: 4 additions & 8 deletions src/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,7 @@ impl ActionHandler {
trace!("apply_suggestion {:?} {}", location, new_text);
// FIXME should handle the response
let output = serde_json::to_string(
&RequestMessage::new(out.provide_id(),
"workspace/applyEdit".to_owned(),
&RequestMessage::new("workspace/applyEdit".to_owned(),
ApplyWorkspaceEditParams { edit: make_workspace_edit(location, new_text) })
).unwrap();
out.response(output);
Expand Down Expand Up @@ -564,8 +563,7 @@ impl ActionHandler {
// Send a workspace edit to make the actual change.
// FIXME should handle the response
let output = serde_json::to_string(
&RequestMessage::new(out.provide_id(),
"workspace/applyEdit".to_owned(),
&RequestMessage::new("workspace/applyEdit".to_owned(),
ApplyWorkspaceEditParams { edit: make_workspace_edit(location, deglob_str) })
).unwrap();
out.response(output);
Expand Down Expand Up @@ -660,16 +658,14 @@ impl ActionHandler {
// FIXME should handle the response
if unstable_features {
let output = serde_json::to_string(
&RequestMessage::new(out.provide_id(),
NOTIFICATION__RegisterCapability.to_owned(),
&RequestMessage::new(NOTIFICATION__RegisterCapability.to_owned(),
RegistrationParams { registrations: vec![Registration { id: RANGE_FORMATTING_ID.to_owned(), method: REQUEST__RangeFormatting.to_owned(), register_options: serde_json::Value::Null },
Registration { id: RENAME_ID.to_owned(), method: REQUEST__Rename.to_owned(), register_options: serde_json::Value::Null }] })
).unwrap();
out.response(output);
} else {
let output = serde_json::to_string(
&RequestMessage::new(out.provide_id(),
NOTIFICATION__UnregisterCapability.to_owned(),
&RequestMessage::new(NOTIFICATION__UnregisterCapability.to_owned(),
UnregistrationParams { unregisterations: vec![Unregistration { id: RANGE_FORMATTING_ID.to_owned(), method: REQUEST__RangeFormatting.to_owned() },
Unregistration { id: RENAME_ID.to_owned(), method: REQUEST__Rename.to_owned() }] })
).unwrap();
Expand Down
4 changes: 0 additions & 4 deletions src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,6 @@ impl server::Output for PrintlnOutput {
println!("{}", output);
}

fn provide_id(&self) -> u64 {
0
}

fn success(&self, id: usize, data: ResponseData) {
println!("{}: {:#?}", id, data);
}
Expand Down
6 changes: 3 additions & 3 deletions src/lsp_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,16 @@ pub struct RequestMessage<T>
where T: Debug + Serialize
{
jsonrpc: &'static str,
pub id: u64,
pub id: String,
pub method: String,
pub params: T,
}

impl <T> RequestMessage<T> where T: Debug + Serialize {
pub fn new(id: u64, method: String, params: T) -> Self {
pub fn new(method: String, params: T) -> Self {
RequestMessage {
jsonrpc: "2.0",
id,
id: "FIXME".to_owned(),
method: method,
params: params
}
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#![feature(rustc_private)]
#![feature(concat_idents)]
#![feature(type_ascription)]
#![feature(integer_atomics)]

extern crate cargo;
#[macro_use]
Expand Down
21 changes: 3 additions & 18 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use actions::ActionHandler;
use std::fmt;
use std::io::{self, Read, Write, ErrorKind};
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering, AtomicU64};
use std::sync::atomic::{AtomicBool, Ordering};
use std::path::PathBuf;

#[cfg(test)]
Expand Down Expand Up @@ -547,7 +547,6 @@ impl MessageReader for StdioMsgReader {

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

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

#[derive(Clone)]
struct StdioOutput {
next_id: Arc<AtomicU64>,
}

impl StdioOutput {
pub fn new() -> StdioOutput {
StdioOutput {
next_id: Arc::new(AtomicU64::new(1)),
}
}
}
struct StdioOutput;

impl Output for StdioOutput {
fn response(&self, output: String) {
Expand All @@ -623,18 +612,14 @@ impl Output for StdioOutput {
print!("{}", o);
io::stdout().flush().unwrap();
}

fn provide_id(&self) -> u64 {
self.next_id.fetch_add(1, Ordering::SeqCst)
}
}

pub fn run_server(analysis: Arc<AnalysisHost>, vfs: Arc<Vfs>) {
debug!("Language Server Starting up");
let service = LsService::new(analysis,
vfs,
Box::new(StdioMsgReader),
StdioOutput::new());
StdioOutput);
LsService::run(service);
debug!("Server shutting down");
}
Expand Down
4 changes: 0 additions & 4 deletions src/test/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ impl ls_server::Output for RecordOutput {
let mut records = self.output.lock().unwrap();
records.push(output);
}

fn provide_id(&self) -> u64 {
0
}
}

#[derive(Clone, Debug)]
Expand Down