mirror of
https://github.com/mtshiba/pylyzer.git
synced 2025-08-04 14:28:24 +00:00
keep order of insertion, and works with options or flags in the middle
This commit is contained in:
parent
9497bfa046
commit
f2e4da85ac
5 changed files with 78 additions and 37 deletions
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
|
@ -6,5 +6,8 @@
|
|||
"[typescript]": {
|
||||
"editor.formatOnSave": true,
|
||||
"editor.defaultFormatter": "biomejs.biome"
|
||||
}
|
||||
},
|
||||
"cSpell.words": [
|
||||
"indexmap"
|
||||
]
|
||||
}
|
25
Cargo.lock
generated
25
Cargo.lock
generated
|
@ -166,6 +166,12 @@ dependencies = [
|
|||
"windows",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||
|
||||
[[package]]
|
||||
name = "erg_common"
|
||||
version = "0.6.53-nightly.2"
|
||||
|
@ -260,6 +266,12 @@ dependencies = [
|
|||
"ahash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.15.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
|
@ -405,6 +417,16 @@ dependencies = [
|
|||
"icu_properties",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8c9c992b02b5b4c94ea26e32fe5bccb7aa7d9f390ab5c1221ff895bc7ea8b652"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown 0.15.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is-macro"
|
||||
version = "0.3.7"
|
||||
|
@ -502,7 +524,7 @@ version = "0.4.22"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ea0ed76adf7defc1a92240b5c36d5368cfe9251640dcce5bd2d0b7c1fd87aeb"
|
||||
dependencies = [
|
||||
"hashbrown",
|
||||
"hashbrown 0.14.5",
|
||||
"itertools",
|
||||
"libm",
|
||||
"ryu",
|
||||
|
@ -733,6 +755,7 @@ dependencies = [
|
|||
"erg_common",
|
||||
"erg_compiler",
|
||||
"glob",
|
||||
"indexmap",
|
||||
"pylyzer_core",
|
||||
]
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ pylyzer_core = { version = "0.0.81", path = "./crates/pylyzer_core" }
|
|||
erg_common = { workspace = true }
|
||||
els = { workspace = true }
|
||||
glob = "0.3.2"
|
||||
indexmap = "2.7.1"
|
||||
|
||||
[dev-dependencies]
|
||||
erg_compiler = { workspace = true }
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use std::collections::HashSet;
|
||||
use std::env;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
|
@ -7,6 +6,7 @@ use erg_common::config::{ErgConfig, ErgMode};
|
|||
use erg_common::io::Input;
|
||||
use erg_common::pathutil::project_entry_file_of;
|
||||
use erg_common::switch_lang;
|
||||
use indexmap::IndexSet;
|
||||
|
||||
use crate::copy::clear_cache;
|
||||
|
||||
|
@ -50,7 +50,7 @@ OPTIONS
|
|||
--clear-cache キャッシュをクリア
|
||||
--code/-c cmd 文字列をプログラムに渡す
|
||||
--dump-decl 型宣言ファイルを出力
|
||||
--disable 指定した機能を無効化",
|
||||
--disable feat 指定した機能を無効化",
|
||||
|
||||
"simplified_chinese" =>
|
||||
"\
|
||||
|
@ -68,7 +68,7 @@ OPTIONS
|
|||
--clear-cache 清除缓存
|
||||
--code/-c cmd 作为字符串传入程序
|
||||
--dump-decl 输出类型声明文件
|
||||
--disable 禁用指定功能",
|
||||
--disable feat 禁用指定功能",
|
||||
|
||||
"traditional_chinese" =>
|
||||
"\
|
||||
|
@ -86,7 +86,7 @@ OPTIONS
|
|||
--clear-cache 清除快取
|
||||
--code/-c cmd 作為字串傳入程式
|
||||
--dump-decl 輸出類型宣告檔案
|
||||
--disable 禁用指定功能",
|
||||
--disable feat 禁用指定功能",
|
||||
|
||||
"english" =>
|
||||
"\
|
||||
|
@ -104,7 +104,7 @@ OPTIONS
|
|||
--clear-cache clear cache
|
||||
--code/-c cmd program passed in as string
|
||||
--dump-decl output type declaration file
|
||||
--disable disable specified features",
|
||||
--disable feat disable specified features",
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -214,33 +214,49 @@ For more information try `pylyzer --help`"
|
|||
cfg
|
||||
}
|
||||
|
||||
pub(crate) fn files_to_be_checked() -> (Vec<PathBuf>, Vec<String>) {
|
||||
let file_or_patterns = env::args()
|
||||
.skip(1)
|
||||
.rev()
|
||||
.take_while(|arg| !arg.starts_with("-"));
|
||||
let mut files = HashSet::new();
|
||||
let mut invalid_files = HashSet::new();
|
||||
pub(crate) fn files_to_be_checked() -> Vec<Result<PathBuf, String>> {
|
||||
let mut file_or_patterns: Vec<String> = vec![];
|
||||
let mut args = env::args().skip(1);
|
||||
while let Some(arg) = &args.next() {
|
||||
match arg.as_str() {
|
||||
"--" => {
|
||||
// Discard runtime args
|
||||
break;
|
||||
}
|
||||
"--verbose" | "--code" | "-c" | "--disable" => {
|
||||
// Skip options
|
||||
let _ = &args.next();
|
||||
continue;
|
||||
}
|
||||
file_or_pattern if file_or_pattern.starts_with("-") => {
|
||||
// Skip flags
|
||||
continue;
|
||||
}
|
||||
|
||||
file_or_pattern => file_or_patterns.push(file_or_pattern.to_owned()),
|
||||
}
|
||||
}
|
||||
let mut files = IndexSet::new();
|
||||
for file_or_pattern in file_or_patterns {
|
||||
if PathBuf::from(&file_or_pattern).is_file() {
|
||||
files.insert(PathBuf::from(&file_or_pattern));
|
||||
files.insert(Ok(PathBuf::from(&file_or_pattern)));
|
||||
} else {
|
||||
let entries = glob::glob(&file_or_pattern);
|
||||
match entries {
|
||||
Err(_) => {
|
||||
invalid_files.insert(file_or_pattern.clone());
|
||||
files.insert(Err(file_or_pattern.clone()));
|
||||
continue;
|
||||
}
|
||||
Ok(entries) => {
|
||||
let mut entries = entries.into_iter().peekable();
|
||||
if entries.peek().is_none() {
|
||||
invalid_files.insert(file_or_pattern.clone());
|
||||
files.insert(Err(file_or_pattern.clone()));
|
||||
}
|
||||
for entry in entries {
|
||||
match entry {
|
||||
Err(e) => eprintln!("err: {e}"),
|
||||
Ok(path) if path.is_file() => {
|
||||
files.insert(path);
|
||||
files.insert(Ok(path));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
@ -249,8 +265,5 @@ pub(crate) fn files_to_be_checked() -> (Vec<PathBuf>, Vec<String>) {
|
|||
}
|
||||
}
|
||||
}
|
||||
(
|
||||
files.into_iter().collect(),
|
||||
invalid_files.into_iter().collect(),
|
||||
)
|
||||
files.into_iter().collect()
|
||||
}
|
||||
|
|
31
src/main.rs
31
src/main.rs
|
@ -19,26 +19,27 @@ fn run() {
|
|||
lang_server.run();
|
||||
} else {
|
||||
let mut code = 0;
|
||||
let (mut files, invalid_files) = files_to_be_checked();
|
||||
for invalid_file in invalid_files {
|
||||
if code == 0 {
|
||||
code = 1;
|
||||
}
|
||||
println!("{RED}Invalid file or pattern{RESET}: {invalid_file}");
|
||||
}
|
||||
let files = files_to_be_checked();
|
||||
if files.is_empty() {
|
||||
let mut analyzer = PythonAnalyzer::new(cfg);
|
||||
code = analyzer.run();
|
||||
} else {
|
||||
files.reverse(); // TODO: actually this only makes sense if not using a hashset
|
||||
// TODO use a Vec<Result<PathBuf, String>> and keep the order?
|
||||
// ^- error msg
|
||||
for path in files {
|
||||
let cfg = cfg.inherit(path);
|
||||
let mut analyzer = PythonAnalyzer::new(cfg);
|
||||
let c = analyzer.run();
|
||||
if c != 0 {
|
||||
code = 1;
|
||||
match path {
|
||||
Err(invalid_file_or_pattern) => {
|
||||
if code == 0 {
|
||||
code = 1;
|
||||
}
|
||||
println!("{RED}Invalid file or pattern{RESET}: {invalid_file_or_pattern}");
|
||||
}
|
||||
Ok(path) => {
|
||||
let cfg = cfg.inherit(path);
|
||||
let mut analyzer = PythonAnalyzer::new(cfg);
|
||||
let c = analyzer.run();
|
||||
if c != 0 {
|
||||
code = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue