Skip to content

Commit

Permalink
lsp: fix main loop so it blocks while waiting for messages
Browse files Browse the repository at this point in the history
  • Loading branch information
oysandvik94 committed Aug 6, 2024
1 parent ec78647 commit c2dd64c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/son_of_anton/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
interpreter = { path = "../interpreter/" }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
anyhow = { workspace = true }
Expand Down
10 changes: 9 additions & 1 deletion crates/son_of_anton/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut anton = SonOfAnton::from(io::stdout());

loop {
match process_message(&mut reader, &mut anton) {
// Block until there is input to read
let mut buffer = String::new();
reader.read_line(&mut buffer)?;

if buffer.trim().is_empty() {
continue;
}

match process_message(&mut buffer.as_bytes(), &mut anton) {
Ok(()) => {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/son_of_anton/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tracing::{event, Level};

#[derive(Serialize, Deserialize, Debug)]
pub struct BaseMessage {
id: u64,
id: Option<u64>,
jsonrpc: String,
}

Expand Down Expand Up @@ -63,7 +63,7 @@ mod tests {
"Content-Length: 40\r\n\r\n{\"id\":1,\"jsonrpc\":\"2.0\",\"result\":\"test\"}";
let actual = encode_response(Response {
message: BaseMessage {
id: 1,
id: Some(1),
jsonrpc: "2.0".to_string(),
},
result: Some("test".to_string()),
Expand Down

0 comments on commit c2dd64c

Please sign in to comment.