Skip to content

Commit

Permalink
add son of anton skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
oysandvik94 committed Aug 5, 2024
1 parent 0c55782 commit ec78647
Show file tree
Hide file tree
Showing 14 changed files with 500 additions and 13 deletions.
155 changes: 155 additions & 0 deletions Cargo.lock

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

11 changes: 9 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ resolver = "2"
members = [
"crates/interpreter",
"crates/repl",
"crates/piper" ,
"crates/piper",
"crates/filerunner",
"crates/piperfmt"]
"crates/piperfmt",
"crates/son_of_anton",
]

[workspace.dependencies]
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
anyhow = "1.0.42"
4 changes: 2 additions & 2 deletions crates/interpreter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tracing = "0.1.40"
tracing-subscriber = {version = "0.3.18", features =[ "env-filter"]}
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
1 change: 1 addition & 0 deletions crates/interpreter/src/eval/expression_evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ mod tests {
"one": 10 - 9,
two: 1 + 1,
"thr" + "ee": 6 / 2,
}
"#;

let object = test_util::expect_evaled_program(input);
Expand Down
9 changes: 4 additions & 5 deletions crates/piper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ version = "0.1.0"
edition = "2021"

[dependencies]
repl = { path = "../repl/" }
filerunner = { path = "../filerunner/" }
tracing = "0.1.40"
tracing-subscriber = {version = "0.3.18", features =[ "env-filter"]}
repl = { path = "../repl/" }
filerunner = { path = "../filerunner/" }
clap = { version = "4.5.11", features = ["derive"] }

tracing = { workspace = true }
tracing-subscriber = { workspace = true }
4 changes: 2 additions & 2 deletions crates/piperfmt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ version = "0.1.0"
edition = "2021"

[dependencies]
interpreter = { path = "../interpreter"}
anyhow = "1.0.42"
interpreter = { path = "../interpreter" }
anyhow = { workspace = true }
4 changes: 2 additions & 2 deletions crates/repl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ edition = "2021"

[dependencies]
interpreter = { path = "../interpreter" }
tracing = "0.1.40"
tracing-subscriber = {version = "0.3.18", features =[ "env-filter"]}
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
12 changes: 12 additions & 0 deletions crates/son_of_anton/Cargo.toml
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"
3 changes: 3 additions & 0 deletions crates/son_of_anton/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod logging;
pub mod lsp;
pub mod rpc;
17 changes: 17 additions & 0 deletions crates/son_of_anton/src/logging.rs
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)
}
70 changes: 70 additions & 0 deletions crates/son_of_anton/src/lsp.rs
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)
}
Loading

0 comments on commit ec78647

Please sign in to comment.