fix(p10-1b): PR review round 1 — 5 actionable items

(1) tasks/HOTFIXES.md: add 2026-05-20 entry for path-sanitize gap in
    module_path_for_python / _tsjs (promised in task spec line 55 but
    not landed in round 0). Bidirectional cross-link added.

(2) crates/kebab-parse-code: dedup filename_from_workspace_path /
    strip_extension / join_symbol via new pub(crate) module scaffold.rs.
    Removed 9 byte-identical fn copies across rust/python/typescript/
    javascript extractors. Pure refactor — no behavior change.

(3) crates/kebab-parse-code/tests/fixtures/sample.py: @staticmethod was
    semantically inappropriate on a module-level fn (class-method
    decorator). Changed to @no_type_check; test assertion updated.

(5)+(6) crates/kebab-parse-code/src/lang.rs: add tests/test_foo.py case
    to module_path_for_python test + doc clarifying that tests/ /
    examples/ / benches/ are intentionally not stripped.

(4) PUSH BACK — TS/JS class decorator handling is design intent of 1B
    1차 (typescript.rs:242-244 + HOTFIXES entry 2 already in place).
    No code change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-20 02:03:52 +00:00
parent 44813df052
commit 4503b5b12f
9 changed files with 68 additions and 104 deletions

View File

@@ -41,6 +41,8 @@ use kebab_core::{
use serde_json::Map;
use time::OffsetDateTime;
use crate::scaffold::{filename_from_workspace_path, join_symbol, strip_extension};
pub const PARSER_VERSION: &str = "code-js-v1";
/// JavaScript / JSX AST extractor. Per-unit blocks via
@@ -177,36 +179,6 @@ impl Extractor for JavascriptAstExtractor {
}
}
fn filename_from_workspace_path(p: &str) -> String {
p.rsplit('/').next().unwrap_or(p).to_string()
}
fn strip_extension(filename: &str) -> String {
match filename.rfind('.') {
Some(0) => filename.to_string(),
Some(idx) => filename[..idx].to_string(),
None => filename.to_string(),
}
}
/// Join (mod_prefix, mod_path, name) into a dotted JS symbol.
///
/// Note: JS uses `.` as the join separator between mod_prefix /
/// class-nesting / leaf — even though `mod_prefix` itself may contain
/// `/` (e.g. `src/search/Retriever`), the JOIN between segments stays
/// `.`. So a class method symbol looks like `src/search/Foo.search`.
fn join_symbol(mod_prefix: &str, mod_path: &[String], name: &str) -> String {
let mut parts: Vec<&str> = Vec::with_capacity(mod_path.len() + 2);
if !mod_prefix.is_empty() {
parts.push(mod_prefix);
}
for p in mod_path {
parts.push(p.as_str());
}
parts.push(name);
parts.join(".")
}
fn build_blocks(
source: &str,
doc_id: &kebab_core::DocumentId,

View File

@@ -18,6 +18,7 @@ pub mod lang;
pub mod python;
pub mod repo;
pub mod rust;
pub(crate) mod scaffold;
pub mod skip;
pub mod typescript;

View File

@@ -26,6 +26,8 @@ use kebab_core::{
use serde_json::Map;
use time::OffsetDateTime;
use crate::scaffold::{filename_from_workspace_path, join_symbol, strip_extension};
pub const PARSER_VERSION: &str = "code-python-v1";
/// Python AST extractor. Per-unit blocks via tree-sitter-python 0.25
@@ -159,35 +161,6 @@ impl Extractor for PythonAstExtractor {
}
}
fn filename_from_workspace_path(p: &str) -> String {
p.rsplit('/').next().unwrap_or(p).to_string()
}
fn strip_extension(filename: &str) -> String {
match filename.rfind('.') {
Some(0) => filename.to_string(),
Some(idx) => filename[..idx].to_string(),
None => filename.to_string(),
}
}
/// Join (mod_prefix, mod_path, name) into a dotted Python symbol.
///
/// Empty `mod_prefix` (e.g. file is `__init__.py` at workspace root)
/// drops the leading prefix segment; empty `mod_path` (file top-level)
/// drops the class-nesting middle.
fn join_symbol(mod_prefix: &str, mod_path: &[String], name: &str) -> String {
let mut parts: Vec<&str> = Vec::with_capacity(mod_path.len() + 2);
if !mod_prefix.is_empty() {
parts.push(mod_prefix);
}
for p in mod_path {
parts.push(p.as_str());
}
parts.push(name);
parts.join(".")
}
fn build_blocks(
source: &str,
doc_id: &kebab_core::DocumentId,
@@ -446,14 +419,14 @@ mod tests {
assert!(syms.iter().any(|s| s == "kebab_eval.metrics.Outer.Inner.helper"));
assert!(syms.iter().any(|s| s == "kebab_eval.metrics.with_decorator"));
assert!(syms.iter().any(|s| s == "kebab_eval.metrics.<top-level>"));
// The `@staticmethod` decorator on `free` is folded into its
// The `@no_type_check` decorator on `free` is folded into its
// unit's line range (decorated_definition unwrap).
let free_src = doc.blocks.iter().find_map(|b| match b {
Block::Code(c) if matches!(&c.common.source_span,
SourceSpan::Code{symbol,..} if symbol.as_deref()==Some("kebab_eval.metrics.free")) => Some(c.code.clone()),
_ => None,
}).unwrap();
assert!(free_src.contains("@staticmethod"), "decorator folded in: {free_src}");
assert!(free_src.contains("@no_type_check"), "decorator folded in: {free_src}");
}
#[test]

View File

@@ -30,6 +30,8 @@ use kebab_core::{
use serde_json::Map;
use time::OffsetDateTime;
use crate::scaffold::{filename_from_workspace_path, strip_extension};
pub const PARSER_VERSION: &str = "code-rust-v1";
/// Rust AST extractor. Per-unit blocks via tree-sitter-rust 0.24
@@ -162,18 +164,6 @@ impl Extractor for RustAstExtractor {
}
}
fn filename_from_workspace_path(p: &str) -> String {
p.rsplit('/').next().unwrap_or(p).to_string()
}
fn strip_extension(filename: &str) -> String {
match filename.rfind('.') {
Some(0) => filename.to_string(),
Some(idx) => filename[..idx].to_string(),
None => filename.to_string(),
}
}
fn build_blocks(
source: &str,
doc_id: &kebab_core::DocumentId,

View File

@@ -0,0 +1,45 @@
//! `kebab-parse-code::scaffold` — shared pure helpers used by all
//! per-language extractor modules.
//!
//! These are `pub(crate)` utilities extracted from the four extractor
//! modules (rust / python / typescript / javascript) where identical
//! copies existed. Keeping them here is the single source of truth.
/// Extract the last path component (filename) from a `/`-separated
/// workspace path string.
/// For a path like `crates/x/src/foo.rs` this returns `foo.rs`.
pub(crate) fn filename_from_workspace_path(p: &str) -> String {
p.rsplit('/').next().unwrap_or(p).to_string()
}
/// Strip the last dot-extension from a filename string.
/// A leading dot (hidden-file convention) is preserved as-is.
/// `foo.rs` → `foo`, `.hidden` → `.hidden`, `noext` → `noext`.
pub(crate) fn strip_extension(filename: &str) -> String {
match filename.rfind('.') {
Some(0) => filename.to_string(),
Some(idx) => filename[..idx].to_string(),
None => filename.to_string(),
}
}
/// Join `(mod_prefix, mod_path, name)` into a dotted symbol string.
///
/// Used by Python / TypeScript / JavaScript extractors. Rust uses
/// `::` separators instead and builds symbols inline; this helper
/// covers the `.`-joined languages.
///
/// Empty `mod_prefix` (e.g. file is `__init__.py` at workspace root)
/// drops the leading prefix segment; empty `mod_path` (file top-level)
/// drops the class-nesting middle segment.
pub(crate) fn join_symbol(mod_prefix: &str, mod_path: &[String], name: &str) -> String {
let mut parts: Vec<&str> = Vec::with_capacity(mod_path.len() + 2);
if !mod_prefix.is_empty() {
parts.push(mod_prefix);
}
for p in mod_path {
parts.push(p.as_str());
}
parts.push(name);
parts.join(".")
}

View File

@@ -34,6 +34,8 @@ use kebab_core::{
use serde_json::Map;
use time::OffsetDateTime;
use crate::scaffold::{filename_from_workspace_path, join_symbol, strip_extension};
pub const PARSER_VERSION: &str = "code-ts-v1";
/// TypeScript / TSX AST extractor. Per-unit blocks via
@@ -181,36 +183,6 @@ fn select_grammar(workspace_path: &str) -> tree_sitter::Language {
}
}
fn filename_from_workspace_path(p: &str) -> String {
p.rsplit('/').next().unwrap_or(p).to_string()
}
fn strip_extension(filename: &str) -> String {
match filename.rfind('.') {
Some(0) => filename.to_string(),
Some(idx) => filename[..idx].to_string(),
None => filename.to_string(),
}
}
/// Join (mod_prefix, mod_path, name) into a dotted TS symbol.
///
/// Note: TS uses `.` as the join separator between mod_prefix /
/// class-nesting / leaf — even though `mod_prefix` itself may contain
/// `/` (e.g. `src/search/Retriever`), the JOIN between segments stays
/// `.`. So a class method symbol looks like `src/search/Foo.search`.
fn join_symbol(mod_prefix: &str, mod_path: &[String], name: &str) -> String {
let mut parts: Vec<&str> = Vec::with_capacity(mod_path.len() + 2);
if !mod_prefix.is_empty() {
parts.push(mod_prefix);
}
for p in mod_path {
parts.push(p.as_str());
}
parts.push(name);
parts.join(".")
}
fn build_blocks(
source: &str,
doc_id: &kebab_core::DocumentId,

View File

@@ -3,7 +3,7 @@ import os
ANSWER = 42
@staticmethod
@no_type_check
def free(x):
"""free fn."""
return x + 1