From e048e0e10c06fb7f81eb7e10504a6cddf83592a7 Mon Sep 17 00:00:00 2001 From: Leo Dev Date: Mon, 3 Jun 2024 13:23:20 +0200 Subject: [PATCH] lsp server test --- Cargo.toml | 5 +++- src/main.rs | 76 ++++++++++++++++++++++++++++++----------------------- 2 files changed, 47 insertions(+), 34 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c953b13..2ddaf24 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,7 @@ edition = "2021" [dependencies] regex = "1.10.4" once_cell = "1.19.0" -clap = { version = "4.0", features = ["derive"] } \ No newline at end of file +clap = { version = "4.0", features = ["derive"] } +lspower = "1.5.0" +tokio = { version = "1.38.0", features = ["full"] } +tokio-macros = "2.3.0" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 90a15a6..80d0db9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,58 +1,68 @@ mod transpiler; mod parser; mod lexer; -mod compile; +mod compile; +mod lsp; use std::{fs, path::Path}; use clap::Parser; use lexer::LexerState; use transpiler::Options; +use crate::lsp::run_lsp_server; + // Arguments for Wyst (short and long version) #[derive(Parser)] struct Args { - #[clap()] - file: std::path::PathBuf, - #[clap(short, long)] rust: Option, #[clap(short, long)] compile: Option, + + #[clap(long)] + stdio: bool, } fn main() { let args = Args::parse(); - let file_content = fs::read_to_string(&args.file) - .expect("Error reading file"); - if Path::new("build").exists() { - fs::remove_dir_all("build").expect("err rm build"); - } - fs::create_dir("build").expect("error making build"); - let transpiled_code = transpiler::transpile(file_content, 0, LexerState { line: 1, column: 0 }, &mut Options::default()); + match args.stdio { + true => { + run_lsp_server(); + }, + false => { + let file_content = fs::read_to_string("main.wt") + .expect("Error reading file"); + if Path::new("build").exists() { + fs::remove_dir_all("build").expect("err rm build"); + } + fs::create_dir("build").expect("error making build"); + let transpiled_code = transpiler::transpile(file_content, 0, LexerState { line: 1, column: 0 }, &mut Options::default()); - match args.rust { - Some(ref rust_file_name) => { - // Write transpiled code to Rust file - compile::write_to_rust_file(&transpiled_code, ("build/".to_string()+rust_file_name).as_str()) - .expect("Error writing to Rust file"); - println!("Transpiled code written to {}", rust_file_name); - } - None => { - // No Rust file specified, print transpiled code - if !args.compile.is_some() { - println!("{}", transpiled_code); + match args.rust { + Some(ref rust_file_name) => { + // Write transpiled code to Rust file + compile::write_to_rust_file(&transpiled_code, ("build/".to_string()+rust_file_name).as_str()) + .expect("Error writing to Rust file"); + println!("Transpiled code written to {}", rust_file_name); + } + None => { + // No Rust file specified, print transpiled code + if !args.compile.is_some() { + println!("{}", transpiled_code); + } + } + } + + match args.compile { + Some(ref exe_name) => { + compile::write_to_rust_file(&transpiled_code, "build/temp.rs") + .expect("Error writing to temporary Rust file"); + compile::compile_to_executable("build/temp.rs", exe_name) + .expect("Error compiling to executable"); + fs::remove_dir_all("build").expect("err rm build"); + } + None => {} } } } - - match args.compile { - Some(ref exe_name) => { - compile::write_to_rust_file(&transpiled_code, "build/temp.rs") - .expect("Error writing to temporary Rust file"); - compile::compile_to_executable("build/temp.rs", exe_name) - .expect("Error compiling to executable"); - fs::remove_dir_all("build").expect("err rm build"); - } - None => {} - } }