Skip to content

Commit

Permalink
support python import list syntax & prepare release
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelb committed Apr 21, 2024
1 parent f170e10 commit 3ed0558
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sniprun"
version = "1.3.13-beta"
version = "1.3.13"
authors = ["michaelb <[email protected]>"]
rust-version = "1.65"
edition = "2018"
Expand Down
8 changes: 6 additions & 2 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Expand Down
33 changes: 23 additions & 10 deletions src/interpreters/Python3_fifo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand All @@ -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);
}
}
Expand Down
29 changes: 21 additions & 8 deletions src/interpreters/Python3_original.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3ed0558

Please sign in to comment.