-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c55782
commit ec78647
Showing
14 changed files
with
500 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "son_of_anton" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
tracing = { workspace = true } | ||
tracing-subscriber = { workspace = true } | ||
anyhow = { workspace = true } | ||
serde = { version = "1.0.204", features = ["derive"] } | ||
serde_json = "1.0.122" | ||
tracing-appender = "0.2.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod logging; | ||
pub mod lsp; | ||
pub mod rpc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use anyhow::Result; | ||
use tracing_appender::non_blocking::WorkerGuard; | ||
use tracing_subscriber::FmtSubscriber; | ||
|
||
pub fn setup_logging() -> Result<WorkerGuard> { | ||
let file_appender = tracing_appender::rolling::never("/tmp", "anton_log"); | ||
let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender); | ||
|
||
let subscriber = FmtSubscriber::builder() | ||
.with_writer(non_blocking) | ||
.with_env_filter("debug") | ||
.finish(); | ||
|
||
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed"); | ||
|
||
Ok(_guard) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
pub mod initialize; | ||
|
||
use std::io::{Stdout, Write}; | ||
|
||
use anyhow::Result; | ||
use initialize::{InitalizeParams, InitializeResponse}; | ||
use serde::{de::DeserializeOwned, Serialize}; | ||
use serde_json::from_str; | ||
use tracing::{event, Level}; | ||
|
||
use crate::rpc::{self, LspRequest, Request, Response}; | ||
|
||
pub struct SonOfAnton { | ||
writer: Stdout, | ||
} | ||
|
||
impl SonOfAnton { | ||
pub fn from(writer: Stdout) -> Self { | ||
Self { writer } | ||
} | ||
|
||
pub fn handle_message(&mut self, lsp_request: LspRequest) -> Result<()> { | ||
match lsp_request.request.method.as_str() { | ||
"initialize" => { | ||
let _ = fun_name::<InitalizeParams>(&lsp_request)?; | ||
|
||
let resp: InitializeResponse = initialize::handle_initialize(); | ||
self.send_response(lsp_request, resp)?; | ||
} | ||
_ => { | ||
event!(Level::DEBUG, "Received unknown request from server",); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn send_response<T: Serialize>( | ||
&mut self, | ||
lsp_request: LspRequest, | ||
resp: T, | ||
) -> Result<(), anyhow::Error> { | ||
let resp = Response { | ||
message: lsp_request.request.message, | ||
result: Some(resp), | ||
}; | ||
let resp = rpc::encode_response(resp)?; | ||
event!( | ||
Level::DEBUG, | ||
"Sending initialize response to server: {:?}", | ||
resp | ||
); | ||
self.writer.write_all(resp.as_bytes())?; | ||
self.writer.flush()?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
fn fun_name<T>(lsp_request: &LspRequest) -> Result<Option<T>> | ||
where | ||
T: DeserializeOwned + std::fmt::Debug, | ||
{ | ||
let deserialized_request: Request<T> = from_str(&lsp_request.content)?; | ||
event!( | ||
Level::DEBUG, | ||
"Received request from server: {:?}", | ||
deserialized_request | ||
); | ||
Ok(deserialized_request.params) | ||
} |
Oops, something went wrong.