diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 037df251..41111c94 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -2,7 +2,7 @@ name: Rust on: push: - branches: [ master, dev] + branches: [ master] pull_request: branches: [ master, dev] workflow_dispatch: @@ -48,10 +48,10 @@ jobs: - name: Unit tests - run: cargo test --features ignore_in_ci + run: cargo test --release --features ignore_in_ci - name: Integration tests - run: cargo test --features ignore_in_ci --test integration + run: cargo test --release --features ignore_in_ci --test integration diff --git a/lua/sniprun.lua b/lua/sniprun.lua index 1c45d919..9c523264 100644 --- a/lua/sniprun.lua +++ b/lua/sniprun.lua @@ -145,10 +145,10 @@ function M.setup_autocommands() vim.cmd("augroup END") vim.cmd("function! Sniprun_clear_vt_on_leave()\n lua require'sniprun.display'.clear_virtual_text()\n endfunction") - vim.cmd("augroup sniprun_clear_vt") - vim.cmd("autocmd!") - vim.cmd("autocmd BufWinLeave * call Sniprun_clear_vt_on_leave()") - vim.cmd("augroup END") + -- vim.cmd("augroup sniprun_clear_vt") + -- vim.cmd("autocmd!") + -- vim.cmd("autocmd BufWinLeave * call Sniprun_clear_vt_on_leave()") + -- vim.cmd("augroup END") vim.cmd("function! Sniprun_close_term_on_leave()\n lua require'sniprun.display'.term_close()\n endfunction") vim.cmd("augroup sniprun_close_term") diff --git a/ressources/display_notify.md b/ressources/display_notify.md index 306630dd..51c4ed31 100644 --- a/ressources/display_notify.md +++ b/ressources/display_notify.md @@ -14,9 +14,3 @@ require'sniprun'.setup({ }) EOF ``` - - -!! As of writing, virtual text gets deleted when a notification from nvim-notify expires for an unknown reason. - - - diff --git a/src/display.rs b/src/display.rs index 583293c5..f7a3427f 100644 --- a/src/display.rs +++ b/src/display.rs @@ -9,13 +9,13 @@ use std::sync::{Arc, Mutex}; #[derive(Clone, Debug, Ord, PartialOrd, PartialEq, Eq)] pub enum DisplayType { Classic = 0, + NvimNotify, VirtualTextOk, VirtualTextErr, Terminal, LongTempFloatingWindow, TempFloatingWindow, Api, - NvimNotify, } use DisplayType::*; @@ -101,14 +101,17 @@ pub fn send_api( Ok(result) => { let mut nvim_instance = nvim.lock().unwrap(); nvim_instance.command_async(&format!( - "lua require\"sniprun.display\".send_api(\"{}\", true)", - no_output_wrap(result, data, &DisplayType::Terminal), - ))}, - Err(result) => {let mut nvim_instance = nvim.lock().unwrap(); + "lua require\"sniprun.display\".send_api(\"{}\", true)", + no_output_wrap(result, data, &DisplayType::Terminal), + )) + } + Err(result) => { + let mut nvim_instance = nvim.lock().unwrap(); nvim_instance.command_async(&format!( - "lua require\"sniprun.display\".send_api(\"{}\", false)", - no_output_wrap(&result.to_string(), data, &DisplayType::Terminal), - ))}, + "lua require\"sniprun.display\".send_api(\"{}\", false)", + no_output_wrap(&result.to_string(), data, &DisplayType::Terminal), + )) + } }; info!("!done displyaing notify"); } @@ -123,7 +126,11 @@ pub fn display_virtual_text( return; //don't display unasked-for things } - let namespace_id = nvim.lock().unwrap().create_namespace("sniprun").unwrap(); + let namespace_id = nvim + .lock() + .unwrap() + .create_namespace("sniprun") + .unwrap(); info!("namespace_id = {:?}", namespace_id); let last_line = data.range[1] - 1; @@ -147,7 +154,7 @@ pub fn display_virtual_text( .is_empty() { return; - } + } nvim.lock().unwrap().command(&format!( "lua require\"sniprun.display\".display_extmark({},{},\"{}\",\"{}\")", namespace_id, @@ -159,8 +166,7 @@ pub fn display_virtual_text( )), hl_ok )) - - } + } Err(message_err) => { if shorten_err(&no_output_wrap( &message_err.to_string(), @@ -331,7 +337,7 @@ fn cleanup_and_escape(message: &str) -> String { .trim_start_matches('\n') .trim_end_matches('\n') .to_string(); - + answer_str.replace("\n", "\\\n") } diff --git a/src/interpreters/GFM_original.rs b/src/interpreters/GFM_original.rs index 9c790f4f..3241b7cc 100644 --- a/src/interpreters/GFM_original.rs +++ b/src/interpreters/GFM_original.rs @@ -129,6 +129,9 @@ impl Interpreter for GFM_original { String::from("GFM_original") } + fn default_for_filetype() -> bool { + true + } fn get_current_level(&self) -> SupportLevel { self.support_level } diff --git a/src/interpreters/Sage_fifo.rs b/src/interpreters/Sage_fifo.rs index 6b51c306..1122daf5 100644 --- a/src/interpreters/Sage_fifo.rs +++ b/src/interpreters/Sage_fifo.rs @@ -21,7 +21,7 @@ impl Sage_fifo { err_path: String, id: u32, ) -> Result { - let end_mark = String::from("sniprun_finished_id=") + &id.to_string()+"\n"; + let end_mark = String::from("sniprun_finished_id=") + &id.to_string() + "\n"; let start_mark = String::from("sniprun_started_id=") + &id.to_string(); info!( @@ -46,8 +46,8 @@ impl Sage_fifo { // info!("file : {:?}", contents); if err_contents.contains(&end_mark) { if let Some(index) = err_contents.rfind(&start_mark) { - let err_to_display = err_contents[index + start_mark.len() - ..err_contents.len() - end_mark.len() - 1] + let err_to_display = err_contents + [index + start_mark.len()..err_contents.len() - end_mark.len() - 1] .to_owned(); info!("err to display : {:?}", err_to_display); if !err_to_display.trim().is_empty() { @@ -71,13 +71,37 @@ impl Sage_fifo { if out_contents.contains(&end_mark) { info!("out found"); let index = out_contents.rfind(&start_mark).unwrap(); - let out_contents_current = out_contents[index + start_mark.len() - ..out_contents.len() - end_mark.len() - 1].to_string(); + let out_contents_current = out_contents + [index + start_mark.len()..out_contents.len() - end_mark.len() - 1] + .to_string(); //check it's not actually an error - let error_indicators = ["AssertionError","AttributeError","EOFError","FloatingPointError","GeneratorExit","ImportError","IndexError","KeyError","KeyboardInterrupt","MemoryError","NameError","NotImplementedError","OSError","OverflowError","ReferenceError","RuntimeError","StopIteration","SyntaxError","IndentationError","TabError","SystemError", "ModuleNotFoundError"]; + let error_indicators = [ + "AssertionError", + "AttributeError", + "EOFError", + "FloatingPointError", + "GeneratorExit", + "ImportError", + "IndexError", + "KeyError", + "KeyboardInterrupt", + "MemoryError", + "NameError", + "NotImplementedError", + "OSError", + "OverflowError", + "ReferenceError", + "RuntimeError", + "StopIteration", + "SyntaxError", + "IndentationError", + "TabError", + "SystemError", + "ModuleNotFoundError", + ]; for try_error_indicator in error_indicators.iter() { - if out_contents_current.contains(try_error_indicator){ + if out_contents_current.contains(try_error_indicator) { info!("stdout contains error indicator"); err_contents = out_contents.clone(); // info!("file : {:?}", contents); @@ -98,8 +122,8 @@ impl Sage_fifo { } } - return Ok(out_contents[index + start_mark.len() - ..out_contents.len() - end_mark.len() - 1] + return Ok(out_contents + [index + start_mark.len()..out_contents.len() - end_mark.len() - 1] .to_owned()); } } @@ -237,10 +261,6 @@ impl Interpreter for Sage_fifo { String::from("Sage_fifo") } - fn default_for_filetype() -> bool { - false - } - fn behave_repl_like_default() -> bool { true } @@ -272,6 +292,10 @@ impl Interpreter for Sage_fifo { SupportLevel::Import } + fn default_for_filetype() -> bool { + true + } + fn fetch_code(&mut self) -> Result<(), SniprunError> { self.fetch_config(); self.fetch_python_imports()?; @@ -309,7 +333,6 @@ impl Interpreter for Sage_fifo { impl ReplLikeInterpreter for Sage_fifo { fn fetch_code_repl(&mut self) -> Result<(), SniprunError> { - if !self.read_previous_code().is_empty() { // nothing to do, kernel already running info!("Sage kernel already running"); @@ -322,12 +345,13 @@ impl ReplLikeInterpreter for Sage_fifo { } else { info!("Could not retrieve a previous id even if the kernel is running"); info!("This was in saved code: {}", self.read_previous_code()); - return Err(SniprunError::CustomError("Sniprun failed to connect to the running kernel, please SnipReset".to_string())); + return Err(SniprunError::CustomError( + "Sniprun failed to connect to the running kernel, please SnipReset".to_string(), + )); } self.fetch_code()?; Ok(()) - } else { self.fetch_config(); // launch everything @@ -339,13 +363,12 @@ impl ReplLikeInterpreter for Sage_fifo { init_repl_cmd, &self.cache_dir ); match daemon() { - Ok(Fork::Child) => { let nodotstage_arg = if self.user_sage_config { - "" - } else { - "--nodotsage" - }; + "" + } else { + "--nodotsage" + }; let _res = Command::new("bash") .args(&[ @@ -364,9 +387,9 @@ impl ReplLikeInterpreter for Sage_fifo { )); } Ok(Fork::Parent(_)) => {} - Err(_) => info!( - "Sage_fifo could not fork itself to the background to launch the kernel" - ), + Err(_) => { + info!("Sage_fifo could not fork itself to the background to launch the kernel") + } }; let pause = std::time::Duration::from_millis(100); @@ -377,7 +400,6 @@ impl ReplLikeInterpreter for Sage_fifo { "Sage kernel launched, re-run your snippet".to_owned(), )) } - } fn add_boilerplate_repl(&mut self) -> Result<(), SniprunError> { diff --git a/src/interpreters/TypeScript_original.rs b/src/interpreters/TypeScript_original.rs index 36c515a7..754a3076 100644 --- a/src/interpreters/TypeScript_original.rs +++ b/src/interpreters/TypeScript_original.rs @@ -55,6 +55,9 @@ impl Interpreter for TypeScript_original { self.support_level = level; } + fn default_for_filetype() -> bool { + true + } fn get_data(&self) -> DataHolder { self.data.clone() } diff --git a/src/lib.rs b/src/lib.rs index 9d83ecb5..b229ddcf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -429,7 +429,10 @@ pub fn start() { //main loop info!("[MAIN] Start of main event loop"); + let mut counter = 1; for (event, values) in receiver { + info!("EVENT {} RECEIVED ##################", counter); + counter += 1; match Messages::from(event.clone()) { //Run command Messages::Run => { @@ -437,7 +440,7 @@ pub fn start() { let mut event_handler2 = event_handler.clone(); info!("[RUN] clone event handler"); - let _res2 = send.send(HandleAction::New(thread::spawn(move || { + let _ = send.send(HandleAction::New(thread::spawn(move || { // get up-to-date data // info!("[RUN] spawned thread");