From 1045baa0d78f43af980599317a953f57f444ea94 Mon Sep 17 00:00:00 2001 From: VonTum Date: Sun, 6 Aug 2023 20:50:54 +0200 Subject: [PATCH] Added Windows support to LSP. Nice --- src/dev_aid/lsp.rs | 14 +++++++++++--- src/dev_aid/syntax_highlighting.rs | 5 ++++- src/tokenizer.rs | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/dev_aid/lsp.rs b/src/dev_aid/lsp.rs index fbd8e0e..99f93cc 100644 --- a/src/dev_aid/lsp.rs +++ b/src/dev_aid/lsp.rs @@ -14,12 +14,20 @@ use crate::{parser::{perform_full_semantic_parse, FullParseResult}, dev_aid::syn use super::syntax_highlighting::{IDETokenType, IDEIdentifierType, IDEToken}; -thread_local!(static OUT_FILE: File = File::create("/home/lennart/lsp_out.txt").expect("Replacement terminal /home/lennart/lsp_out.txt could not be created")); +use std::env; + +static LSP_LOG_PATH : &str = if crate::tokenizer::const_eq_str(std::env::consts::OS, "windows") { + "C:\\Users\\lenna\\lsp_out.txt" +} else { + "/home/lennart/lsp_out.txt" +}; + +thread_local!(static LSP_LOG: File = File::create(LSP_LOG_PATH).expect("Replacement terminal /home/lennart/lsp_out.txt could not be created")); macro_rules! print { ($($arg:tt)*) => {{ use std::io::Write; - OUT_FILE.with(|mut file| { + LSP_LOG.with(|mut file| { write!(file, $($arg)*).unwrap(); }) }}; @@ -27,7 +35,7 @@ macro_rules! print { macro_rules! println { ($($arg:tt)*) => {{ use std::io::Write; - OUT_FILE.with(|mut file| { + LSP_LOG.with(|mut file| { write!(file, $($arg)*).unwrap(); write!(file, "\n").unwrap(); }) diff --git a/src/dev_aid/syntax_highlighting.rs b/src/dev_aid/syntax_highlighting.rs index ae167f1..efae134 100644 --- a/src/dev_aid/syntax_highlighting.rs +++ b/src/dev_aid/syntax_highlighting.rs @@ -154,7 +154,10 @@ pub fn create_token_ide_info<'a>(parsed: &FullParseResult) -> Vec { } pub fn syntax_highlight_file(file_path : &str) { - let file_text = std::fs::read_to_string(file_path).expect("Could not open file!"); + let file_text = match std::fs::read_to_string(file_path) { + Ok(file_text) => file_text, + Err(reason) => panic!("Could not open file '{file_path}' for syntax highlighting because {reason}") + }; let (full_parse, errors) = perform_full_semantic_parse(&file_text); diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 49a756b..7cb42db 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -107,7 +107,7 @@ pub const TOKEN_NUMBER : TokenTypeIdx = TOKEN_IDENTIFIER + 1; pub const TOKEN_COMMENT : TokenTypeIdx = TOKEN_IDENTIFIER + 2; pub const TOKEN_INVALID : TokenTypeIdx = TOKEN_IDENTIFIER + 3; -const fn const_eq_str(a: &str, b: &str) -> bool { +pub const fn const_eq_str(a: &str, b: &str) -> bool { let a_bytes = a.as_bytes(); let b_bytes = b.as_bytes();