lsp server test

This commit is contained in:
2024-06-03 13:23:20 +02:00
parent 5fafd054b1
commit e048e0e10c
2 changed files with 47 additions and 34 deletions
+4 -1
View File
@@ -8,4 +8,7 @@ edition = "2021"
[dependencies] [dependencies]
regex = "1.10.4" regex = "1.10.4"
once_cell = "1.19.0" once_cell = "1.19.0"
clap = { version = "4.0", features = ["derive"] } clap = { version = "4.0", features = ["derive"] }
lspower = "1.5.0"
tokio = { version = "1.38.0", features = ["full"] }
tokio-macros = "2.3.0"
+43 -33
View File
@@ -1,58 +1,68 @@
mod transpiler; mod transpiler;
mod parser; mod parser;
mod lexer; mod lexer;
mod compile; mod compile;
mod lsp;
use std::{fs, path::Path}; use std::{fs, path::Path};
use clap::Parser; use clap::Parser;
use lexer::LexerState; use lexer::LexerState;
use transpiler::Options; use transpiler::Options;
use crate::lsp::run_lsp_server;
// Arguments for Wyst (short and long version) // Arguments for Wyst (short and long version)
#[derive(Parser)] #[derive(Parser)]
struct Args { struct Args {
#[clap()]
file: std::path::PathBuf,
#[clap(short, long)] #[clap(short, long)]
rust: Option<String>, rust: Option<String>,
#[clap(short, long)] #[clap(short, long)]
compile: Option<String>, compile: Option<String>,
#[clap(long)]
stdio: bool,
} }
fn main() { fn main() {
let args = Args::parse(); let args = Args::parse();
let file_content = fs::read_to_string(&args.file) match args.stdio {
.expect("Error reading file"); true => {
if Path::new("build").exists() { run_lsp_server();
fs::remove_dir_all("build").expect("err rm build"); },
} false => {
fs::create_dir("build").expect("error making build"); let file_content = fs::read_to_string("main.wt")
let transpiled_code = transpiler::transpile(file_content, 0, LexerState { line: 1, column: 0 }, &mut Options::default()); .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 { match args.rust {
Some(ref rust_file_name) => { Some(ref rust_file_name) => {
// Write transpiled code to Rust file // Write transpiled code to Rust file
compile::write_to_rust_file(&transpiled_code, ("build/".to_string()+rust_file_name).as_str()) compile::write_to_rust_file(&transpiled_code, ("build/".to_string()+rust_file_name).as_str())
.expect("Error writing to Rust file"); .expect("Error writing to Rust file");
println!("Transpiled code written to {}", rust_file_name); println!("Transpiled code written to {}", rust_file_name);
} }
None => { None => {
// No Rust file specified, print transpiled code // No Rust file specified, print transpiled code
if !args.compile.is_some() { if !args.compile.is_some() {
println!("{}", transpiled_code); 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 => {}
}
} }