Skip to content

Commit 6f02c45

Browse files
unhappychoiceclaude
andcommitted
feat: add .name pattern mapping to CodeBlock for all language parsers
Add capture_name_to_chunk_type mapping for .name patterns to return CodeBlock chunk type. This ensures proper handling of name captures (e.g., function.name, class.name, struct.name) across all supported languages. Languages updated: - C: function.name, struct.name, type.name, enum.name, variable.name, macro.name - C++: function.name, method.name, class.name, struct.name, namespace.name, etc. - C#, Dart, Go, Haskell, Java, JavaScript, PHP, Python, Ruby, Rust, Scala, Swift, TypeScript, Zig This complements the definition patterns (e.g., function.definition) which return specific chunk types like Function, Class, Struct, etc. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 18b06e5 commit 6f02c45

File tree

14 files changed

+14
-1
lines changed

14 files changed

+14
-1
lines changed

src/domain/services/source_code_parser/parsers/c.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ impl LanguageExtractor for CExtractor {
6565
"type.definition" => Some(ChunkType::Struct),
6666
"enum.definition" => Some(ChunkType::Struct),
6767
"macro.definition" => Some(ChunkType::Function),
68+
"function.name" | "struct.name" | "type.name" | "enum.name" | "variable.name" | "macro.name" => Some(ChunkType::CodeBlock),
6869
_ => None,
6970
}
7071
}

src/domain/services/source_code_parser/parsers/cpp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ impl LanguageExtractor for CppExtractor {
9191
"type.definition" => Some(ChunkType::Struct),
9292
"enum.definition" => Some(ChunkType::Struct),
9393
"variable.definition" => Some(ChunkType::Variable),
94+
"function.name" | "method.name" | "class.name" | "struct.name" | "namespace.name" | "template_class.name" | "template_function.name" | "type.name" | "enum.name" | "variable.name" => Some(ChunkType::CodeBlock),
9495
_ => None,
9596
}
9697
}

src/domain/services/source_code_parser/parsers/csharp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ impl LanguageExtractor for CSharpExtractor {
4545
"field" => Some(ChunkType::Variable),
4646
"delegate" => Some(ChunkType::Method),
4747
"namespace" => Some(ChunkType::Namespace),
48+
"name" => Some(ChunkType::CodeBlock),
4849
_ => None,
4950
}
5051
}

src/domain/services/source_code_parser/parsers/dart.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ impl LanguageExtractor for DartExtractor {
3535
"mixin" => Some(ChunkType::Class),
3636
"extension" => Some(ChunkType::Class),
3737
"variable" => Some(ChunkType::Variable),
38+
"name" => Some(ChunkType::CodeBlock),
3839
_ => None,
3940
}
4041
}

src/domain/services/source_code_parser/parsers/go.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl LanguageExtractor for GoExtractor {
4141
"const_block" => Some(ChunkType::Const),
4242
"var_block" => Some(ChunkType::Variable),
4343
"type_alias" => Some(ChunkType::TypeAlias),
44+
"name" => Some(ChunkType::CodeBlock),
4445
_ => None,
4546
}
4647
}

src/domain/services/source_code_parser/parsers/java.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ impl LanguageExtractor for JavaExtractor {
3737
"method" => Some(ChunkType::Method),
3838
"enum" => Some(ChunkType::Enum),
3939
"field" => Some(ChunkType::Variable),
40+
"name" => Some(ChunkType::CodeBlock),
4041
_ => None,
4142
}
4243
}

src/domain/services/source_code_parser/parsers/javascript.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ impl LanguageExtractor for JavaScriptExtractor {
3636
"jsx_element" => Some(ChunkType::Component),
3737
"jsx_self_closing_element" => Some(ChunkType::Component),
3838
"variable" => Some(ChunkType::Variable),
39+
"name" => Some(ChunkType::CodeBlock),
3940
_ => None,
4041
}
4142
}

src/domain/services/source_code_parser/parsers/php.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl LanguageExtractor for PhpExtractor {
3535
"interface" => Some(ChunkType::Class),
3636
"trait" => Some(ChunkType::Class),
3737
"namespace" => Some(ChunkType::Function),
38-
"name" => None, // name captures are not chunks themselves
38+
"name" => Some(ChunkType::CodeBlock),
3939
_ => None,
4040
}
4141
}

src/domain/services/source_code_parser/parsers/python.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ impl LanguageExtractor for PythonExtractor {
2525
match capture_name {
2626
"function" => Some(ChunkType::Function),
2727
"class" => Some(ChunkType::Class),
28+
"name" => Some(ChunkType::CodeBlock),
2829
_ => None,
2930
}
3031
}

src/domain/services/source_code_parser/parsers/ruby.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ impl LanguageExtractor for RubyExtractor {
3333
"attr_accessor" => Some(ChunkType::Method),
3434
"class" => Some(ChunkType::Class),
3535
"module" => Some(ChunkType::Module),
36+
"name" => Some(ChunkType::CodeBlock),
3637
_ => None,
3738
}
3839
}

0 commit comments

Comments
 (0)