From 4067a7e50cd89ec7bb5cba53183fb9a893f6771d Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Thu, 27 Mar 2025 20:45:04 +0100 Subject: [PATCH] [red-knot] Don't check non-python files (#17021) ## Summary Fixes https://github.com/astral-sh/ruff/issues/17018 ## Test Plan I renamed a python file to `knot.toml` and verified that there are no diagnostics. Renaming back the file to `*.py` brings back the diagnostics --- crates/red_knot_wasm/src/lib.rs | 4 ++++ playground/knot/src/Editor/Chrome.tsx | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/red_knot_wasm/src/lib.rs b/crates/red_knot_wasm/src/lib.rs index ba1dc01bea..a28b41f2fd 100644 --- a/crates/red_knot_wasm/src/lib.rs +++ b/crates/red_knot_wasm/src/lib.rs @@ -214,6 +214,10 @@ impl FileHandle { pub fn js_to_string(&self) -> String { format!("file(id: {:?}, path: {})", self.file, self.path) } + + pub fn path(&self) -> String { + self.path.to_string() + } } #[wasm_bindgen] diff --git a/playground/knot/src/Editor/Chrome.tsx b/playground/knot/src/Editor/Chrome.tsx index ebfadade91..c55d9787b3 100644 --- a/playground/knot/src/Editor/Chrome.tsx +++ b/playground/knot/src/Editor/Chrome.tsx @@ -220,7 +220,9 @@ function useCheckResult( const currentHandle = files.handles[files.selected]; - if (currentHandle == null) { + const extension = + currentHandle?.path()?.toLowerCase().split(".").pop() ?? ""; + if (currentHandle == null || !["py", "pyi", "pyw"].includes(extension)) { return { diagnostics: [], error: null,