diff --git a/CHANGELOG.md b/CHANGELOG.md index d386371..31bf981 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v1.3.13 +- Support Python import list syntax + ## v1.3.12 - More universally-working shebang in scripts - Use Lua api to set highlights in a more extensible way (courtesy of @pwnalone) diff --git a/Cargo.lock b/Cargo.lock index bb233e3..d9ea1a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -798,7 +798,7 @@ checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "sniprun" -version = "1.3.13-beta" +version = "1.3.13" dependencies = [ "close_fds", "dirs", diff --git a/Cargo.toml b/Cargo.toml index c138d8f..286edc6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sniprun" -version = "1.3.13-beta" +version = "1.3.13" authors = ["michaelb "] rust-version = "1.65" edition = "2018" diff --git a/src/display.rs b/src/display.rs index 77b92f3..b57da69 100644 --- a/src/display.rs +++ b/src/display.rs @@ -76,11 +76,15 @@ impl fmt::Display for DisplayType { DisplayType::Classic(filter) => "Classic".to_string() + &filter.to_string(), DisplayType::VirtualText(filter) => "VirtualText".to_string() + &filter.to_string(), DisplayType::Terminal(filter) => "Terminal".to_string() + &filter.to_string(), - DisplayType::TerminalWithCode(filter) => "TerminalWithCode".to_string() + &filter.to_string(), + DisplayType::TerminalWithCode(filter) => { + "TerminalWithCode".to_string() + &filter.to_string() + } DisplayType::LongTempFloatingWindow(filter) => { "LongTempFloatingWindow".to_string() + &filter.to_string() } - DisplayType::TempFloatingWindow(filter) => "TempFloatingWindow".to_string() + &filter.to_string(), + DisplayType::TempFloatingWindow(filter) => { + "TempFloatingWindow".to_string() + &filter.to_string() + } DisplayType::Api(filter) => "Api".to_string() + &filter.to_string(), DisplayType::NvimNotify(filter) => "NvimNotify".to_string() + &filter.to_string(), }; diff --git a/src/interpreters/Python3_fifo.rs b/src/interpreters/Python3_fifo.rs index 12d4289..2d234a7 100644 --- a/src/interpreters/Python3_fifo.rs +++ b/src/interpreters/Python3_fifo.rs @@ -138,19 +138,32 @@ impl Python3_fifo { { self.code = self.data.current_bloc.clone(); } - for line in v.iter() { + let mut in_import_list = false; + for line in v.iter().filter(|line| !line.trim().starts_with('#')) { // info!("lines are : {}", line); - if (line.trim().starts_with("import ") || line.trim().starts_with("from")) //basic selection - && !line.trim().starts_with('#') - && self.module_used(line, &self.code) + if in_import_list { + self.imports = self.imports.clone() + "\n" + line; + if line.contains(')'){ + in_import_list = false; + } + continue; + } + if line.trim().starts_with("import ") || line.trim().starts_with("from") //basic selection { + if line.contains('('){ + self.imports = self.imports.clone() + "\n" + line; + in_import_list = true; + continue; + } // embed in try catch blocs in case uneeded module is unavailable - let already_imported: String = self.read_previous_code(); - if !already_imported.contains(line.trim()) { - let line = line.trim_start(); - self.imports = self.imports.clone() + "\n" + line; - self.save_code(already_imported + "\n" + line); + if self.module_used(line, &self.code){ + let already_imported: String = self.read_previous_code(); + if !already_imported.contains(line.trim()) { + let line = line.trim_start(); + self.imports = self.imports.clone() + "\n" + line; + self.save_code(already_imported + "\n" + line); + } } } } @@ -166,7 +179,7 @@ impl Python3_fifo { return true; } if line.contains(" as ") { - if let Some(name) = line.split(' ').last() { + if let Some(name) = line.replace(',', " ").split(' ').last() { return code.contains(name); } } diff --git a/src/interpreters/Python3_original.rs b/src/interpreters/Python3_original.rs index e0a6ffc..acfbaac 100644 --- a/src/interpreters/Python3_original.rs +++ b/src/interpreters/Python3_original.rs @@ -45,15 +45,28 @@ impl Python3_original { { self.code = self.data.current_bloc.clone(); } - for line in v.iter() { + let mut in_import_list = false; + for line in v.iter().filter(|line| !line.trim().starts_with('#')) { // info!("lines are : {}", line); - if (line.trim().starts_with("import ") || line.trim().starts_with("from ")) //basic selection - && !line.trim().starts_with('#') - && self.module_used(line, &self.code) - { - // embed in try catch blocs in case uneeded module is unavailable - let line = unindent(line); - self.imports = self.imports.clone() + "\n" + &line; + if in_import_list { + self.imports = self.imports.clone() + "\n" + line; + if line.contains(')'){ + in_import_list = false; + } + continue; + } + if line.trim().starts_with("import ") || line.trim().starts_with("from ") { //basic selection + if line.contains('('){ + self.imports = self.imports.clone() + "\n" + line; + in_import_list = true; + continue; + } + if self.module_used(line, &self.code) + { + // embed in try catch blocs in case uneeded module is unavailable + let line = unindent(line); + self.imports = self.imports.clone() + "\n" + &line; + } } } info!("import founds : {:?}", self.imports);