From a11ca49c352be22234c564c5c0ee2d041a17794a Mon Sep 17 00:00:00 2001 From: Leo dev Date: Thu, 6 Jun 2024 04:23:24 +0200 Subject: [PATCH] lsp progress --- src/lsp.rs | 34 +++++++++++++++++++++++----------- src/main.rs | 1 - 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/lsp.rs b/src/lsp.rs index ae6eee4..b916594 100644 --- a/src/lsp.rs +++ b/src/lsp.rs @@ -1,24 +1,36 @@ -use lsp_types; use once_cell::sync::Lazy; use regex::Regex; -use std::io::{stdin, stdout, Read}; +use serde_json::{self, Value}; +use std::{ + fs::{self, File}, + io::{stdin, Read, Write}, + path::Path, +}; pub fn run_lsp_server() { - let clpattern = Lazy::new(|| Regex::new(r"Content-Length: (\d+)\n").unwrap()); - let mut sin = stdin(); - let mut sout = stdout(); + if Path::new("/Users/klestiselimaj/work/wyst/log.txt").exists() { + fs::remove_file("/Users/klestiselimaj/work/wyst/log.txt"); + } + let mut file = File::create("/Users/klestiselimaj/work/wyst/log.txt").expect("err_log"); + let clpattern = Lazy::new(|| Regex::new(r"^Content-Length: (\d+)").unwrap()); + let mut reader = stdin(); + // let mut sout = stdout(); - println!("ok"); + writeln!(file, "It's running!"); loop { let mut input = String::new(); - let _ = sin.read_line(&mut input); + let _ = reader.read_line(&mut input); + writeln!(file, "{}", &input); if let Some(caps) = clpattern.captures(&input) { - let conent_len = *(&caps[1].parse::().unwrap()); + let conent_len = *(&caps[1].parse::().unwrap()) + 2; + writeln!(file, "ok {}", conent_len); let mut buf = vec![0u8; conent_len]; - sin.read_exact(&mut buf); + let _ = reader.read_exact(&mut buf); let json_string = String::from_utf8(buf).expect("Our bytes should be valid utf8"); - + writeln!(file, "{}", &json_string); + let client_json: Value = serde_json::from_str(&json_string).expect("err_json"); + writeln!(file, "bruh {}", &client_json["method"].as_str().unwrap()); } } -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index b498778..da92d62 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,6 @@ use clap::Parser; use parser::new_vars; use std::{fs, path::Path}; use transpiler::Transpiler; -mod lspcom; use crate::lsp::run_lsp_server;