diff --git a/Cargo.lock b/Cargo.lock index 353c5f0..1740117 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,9 +31,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.92" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74f37166d7d48a0284b99dd824694c26119c700b53bf0d1540cdb147dbdaaf13" +checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" [[package]] name = "autocfg" @@ -93,9 +93,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cc" -version = "1.1.34" +version = "1.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67b9470d453346108f93a59222a9a1a5724db32d0a4727b7ab7ace4b4d822dc9" +checksum = "40545c26d092346d8a8dab71ee48e7685a7a9cba76e634790c215b41a4a7b4cf" dependencies = [ "shlex", ] @@ -131,6 +131,17 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "either" version = "1.13.0" @@ -139,9 +150,9 @@ checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "els" -version = "0.1.60-nightly.0" +version = "0.1.60-nightly.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91526cd54184ae2ddea4124e87a00dca78fff3780de423dcc0b089d8ed0f31e1" +checksum = "89c30c054c5e833e623d0673f81696e19e58269c66a7a134785e00c0534979b6" dependencies = [ "erg_common", "erg_compiler", @@ -155,9 +166,9 @@ dependencies = [ [[package]] name = "erg_common" -version = "0.6.48-nightly.0" +version = "0.6.48-nightly.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc5e16917f93caa5866a8f628d8d4c82c72c7bde70bb1cae1969f1f5d0521f9a" +checksum = "b194a638b1a921dfe528d62aa8a027f822142a3898f28d65c965bdacf50a2de1" dependencies = [ "backtrace-on-stack-overflow", "erg_proc_macros", @@ -168,9 +179,9 @@ dependencies = [ [[package]] name = "erg_compiler" -version = "0.6.48-nightly.0" +version = "0.6.48-nightly.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "446393772e60305fbbce5d331aad109037e4ee7c098f8431c6431c2fab200548" +checksum = "9d437395714e82c213db0366bab94b314f8f0fac5eaeb8297580df1e0b004fa1" dependencies = [ "erg_common", "erg_parser", @@ -178,9 +189,9 @@ dependencies = [ [[package]] name = "erg_parser" -version = "0.6.48-nightly.0" +version = "0.6.48-nightly.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e00edb38b9576bace8b914c65d5c4511055feb2de41527449bae6471bd05017" +checksum = "d27a6c9659043cf12bcfc8066f34193438e19633ecc1161bfe5e36df12d2aa4a" dependencies = [ "erg_common", "erg_proc_macros", @@ -189,9 +200,9 @@ dependencies = [ [[package]] name = "erg_proc_macros" -version = "0.6.48-nightly.0" +version = "0.6.48-nightly.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f51df19e941a11864b34dc9cbf7c94b36a8641def3bdb041de873dad566b9f7" +checksum = "52070b88941a145aecc724ff8dd57742f6e36cbb422311db5858dccf7c84efed" dependencies = [ "quote", "syn 1.0.109", @@ -247,14 +258,143 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "idna" -version = "0.5.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" dependencies = [ - "unicode-bidi", - "unicode-normalization", + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" +dependencies = [ + "icu_normalizer", + "icu_properties", ] [[package]] @@ -292,9 +432,9 @@ checksum = "507460a910eb7b32ee961886ff48539633b788a36b65692b95f225b844c82553" [[package]] name = "libc" -version = "0.2.161" +version = "0.2.162" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" +checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" [[package]] name = "libm" @@ -302,6 +442,12 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" +[[package]] +name = "litemap" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" + [[package]] name = "lock_api" version = "0.4.12" @@ -803,6 +949,12 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "static_assertions" version = "1.1.0" @@ -831,6 +983,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "thread_local" version = "1.1.8" @@ -851,20 +1014,15 @@ dependencies = [ ] [[package]] -name = "tinyvec" -version = "1.8.0" +name = "tinystr" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" dependencies = [ - "tinyvec_macros", + "displaydoc", + "zerovec", ] -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - [[package]] name = "unic-char-property" version = "0.9.0" @@ -917,27 +1075,12 @@ dependencies = [ "unic-common", ] -[[package]] -name = "unicode-bidi" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" - [[package]] name = "unicode-ident" version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" -[[package]] -name = "unicode-normalization" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" -dependencies = [ - "tinyvec", -] - [[package]] name = "unicode-width" version = "0.1.14" @@ -974,9 +1117,9 @@ dependencies = [ [[package]] name = "url" -version = "2.5.2" +version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +checksum = "8d157f1b96d14500ffdc1f10ba712e780825526c03d9a49b4d0324b0d9113ada" dependencies = [ "form_urlencoded", "idna", @@ -984,6 +1127,18 @@ dependencies = [ "serde", ] +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "version_check" version = "0.9.5" @@ -1188,6 +1343,42 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + +[[package]] +name = "yoke" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c5b1314b079b0930c31e3af543d8ee1757b1951ae1e1565ec704403a7240ca5" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", + "synstructure", +] + [[package]] name = "zerocopy" version = "0.7.35" @@ -1208,3 +1399,46 @@ dependencies = [ "quote", "syn 2.0.87", ] + +[[package]] +name = "zerofrom" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ec111ce797d0e0784a1116d0ddcdbea84322cd79e5d5ad173daeba4f93ab55" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", + "synstructure", +] + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] diff --git a/Cargo.toml b/Cargo.toml index 951d8ea..bafc9e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,9 +24,9 @@ edition = "2021" repository = "https://github.com/mtshiba/pylyzer" [workspace.dependencies] -erg_common = { version = "0.6.48-nightly.0", features = ["py_compat", "els"] } -erg_compiler = { version = "0.6.48-nightly.0", features = ["py_compat", "els"] } -els = { version = "0.1.60-nightly.0", features = ["py_compat"] } +erg_common = { version = "0.6.48-nightly.1", features = ["py_compat", "els"] } +erg_compiler = { version = "0.6.48-nightly.1", features = ["py_compat", "els"] } +els = { version = "0.1.60-nightly.1", features = ["py_compat"] } # rustpython-parser = { version = "0.3.0", features = ["all-nodes-with-ranges", "location"] } # rustpython-ast = { version = "0.3.0", features = ["all-nodes-with-ranges", "location"] } rustpython-parser = { git = "https://github.com/RustPython/Parser", version = "0.4.0", features = ["all-nodes-with-ranges", "location"] } diff --git a/crates/pylyzer_core/handle_err.rs b/crates/pylyzer_core/handle_err.rs index 7883276..3d8161f 100644 --- a/crates/pylyzer_core/handle_err.rs +++ b/crates/pylyzer_core/handle_err.rs @@ -1,3 +1,5 @@ +use std::path::{Path, PathBuf}; + use erg_common::error::ErrorKind; use erg_common::log; use erg_common::style::{remove_style, StyledStr}; @@ -5,10 +7,26 @@ use erg_common::style::{remove_style, StyledStr}; use erg_compiler::context::ModuleContext; use erg_compiler::error::{CompileError, CompileErrors}; +fn project_root(path: &Path) -> Option { + let mut parent = path.to_path_buf(); + while parent.pop() { + if parent.join("pyproject.toml").exists() || parent.join(".git").exists() { + let path = if parent == Path::new("") { + PathBuf::from(".") + } else { + parent + }; + return path.canonicalize().ok(); + } + } + None +} + pub(crate) fn filter_errors(ctx: &ModuleContext, errors: CompileErrors) -> CompileErrors { + let root = project_root(ctx.get_top_cfg().input.path()); errors .into_iter() - .filter_map(|error| filter_error(ctx, error)) + .filter_map(|error| filter_error(root.as_deref(), ctx, error)) .collect() } @@ -32,7 +50,23 @@ fn handle_name_error(error: CompileError) -> Option { } } -fn filter_error(_ctx: &ModuleContext, mut error: CompileError) -> Option { +fn filter_error( + root: Option<&Path>, + ctx: &ModuleContext, + mut error: CompileError, +) -> Option { + if ctx.get_top_cfg().do_not_show_ext_errors + && error.input.path() != Path::new("") + && root.is_some_and(|root| { + error + .input + .path() + .canonicalize() + .is_ok_and(|path| !path.starts_with(root)) + }) + { + return None; + } match error.core.kind { ErrorKind::FeatureError => { log!(err "this error is ignored:"); diff --git a/docs/options/options.md b/docs/options/options.md index 1fc8255..8a8eb4d 100644 --- a/docs/options/options.md +++ b/docs/options/options.md @@ -52,3 +52,19 @@ Default (disableable) features are: ## --verbose Print process information verbosely. + +## --no-infer-fn-type + +When a function type is not specified, no type inference is performed and the function type is assumed to be `Any`. + +## --fast-error-report + +Simplify error reporting by eliminating to search for similar variables when a variable does not exist. + +## --hurry + +Enable `--no-infer-fn-type` and `--fast-error-report`. + +## --do-not-show-ext-errors + +Do not show errors from external libraries. diff --git a/src/config.rs b/src/config.rs index 2518828..43df4f7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -135,6 +135,19 @@ pub(crate) fn parse_args() -> ErgConfig { clear_cache(); std::process::exit(0); } + "--no-infer-fn-type" => { + cfg.no_infer_fn_type = true; + } + "--fast-error-report" => { + cfg.fast_error_report = true; + } + "--hurry" => { + cfg.no_infer_fn_type = true; + cfg.fast_error_report = true; + } + "--do-not-show-ext-errors" => { + cfg.do_not_show_ext_errors = true; + } other if other.starts_with('-') => { println!( "\