Skip to content

Commit

Permalink
[WIP]: Wed Nov 29 12:37:22 PM EST 2023
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdevries committed Nov 29, 2023
1 parent 4137856 commit ac20412
Show file tree
Hide file tree
Showing 18 changed files with 3,480 additions and 995 deletions.
1,558 changes: 1,253 additions & 305 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ sg-gql = { path = "crates/sg-gql" }
sg-types = { path = "crates/sg-types" }
jsonrpc = { path = "crates/jsonrpc" }
gix = "0.52.0"
secret-service = { version = "3.0.1", features = ["rt-tokio-crypto-rust"] }
tiny_http = "0.12.0"

[workspace.dependencies]
anyhow = "1"
Expand All @@ -40,7 +42,6 @@ serde_json = "1.0"

graphql_client = { version = "0.13.0", features = ["reqwest", "reqwest-blocking"] }
reqwest = { version = "0.11", features = ["native-tls-vendored"] }
openssl = { version = "0.10", features = ["vendored"] }

lsp-types = "0.94.0"
url = "2.4.0"
Expand Down
21 changes: 10 additions & 11 deletions crates/jsonrpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
use serde::Deserialize;

use {
anyhow::Result,
serde::{de::DeserializeOwned, Serialize},
serde::{de::DeserializeOwned, Deserialize, Serialize},
std::io,
tokio::sync::Mutex,
};

type MessageReader = dyn tokio::io::AsyncBufRead + Unpin + Send;

pub async fn write_msg(
mut out: impl tokio::io::AsyncWrite + Unpin,
req: impl Serialize,
) -> Result<()> {
pub async fn write_msg(out: &Mutex<tokio::io::Stdout>, req: impl Serialize) -> Result<()> {
use tokio::io::AsyncWriteExt;

let msg = serde_json::to_string(&req)?;

let header = format!("Content-Length: {}\r\n\r\n", msg.len());

let out = &mut *out.lock().await;
out.write_all(header.as_bytes()).await?;
out.write_all(msg.as_bytes()).await?;
out.flush().await?;
Expand All @@ -30,12 +26,13 @@ pub struct RPCErr {
pub message: String,
}

pub async fn write_err(mut out: impl tokio::io::AsyncWrite + Unpin, err: RPCErr) -> Result<()> {
pub async fn write_err(out: &Mutex<tokio::io::Stdout>, err: RPCErr) -> Result<()> {
use tokio::io::AsyncWriteExt;

let msg = serde_json::to_string(&err)?;

let header = format!("Content-Length: {}\r\n\r\n", msg.len());

let out = &mut *out.lock().await;
out.write_all(header.as_bytes()).await?;
out.write_all(msg.as_bytes()).await?;
out.flush().await?;
Expand All @@ -47,6 +44,8 @@ pub async fn read_msg<T>(r: &mut MessageReader) -> Result<Option<T>>
where
T: DeserializeOwned,
{
eprintln!("Hello... reading a message...");

let text = match read_msg_text(r).await? {
None => return Ok(None),
Some(text) => text,
Expand Down
Loading

0 comments on commit ac20412

Please sign in to comment.