Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/metricsAnalyzer/languages/csharpAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ interface CSharpFunctionMetrics {
* ```
*/
export class CSharpMetricsAnalyzer {
/** Node types that represent type declarations (class, struct, interface, record, enum). */
private static readonly TYPE_DECLARATION_TYPES: ReadonlySet<string> = new Set([
"class_declaration",
"struct_declaration",
"interface_declaration",
"record_declaration",
"enum_declaration",
]);

/** Current nesting level during analysis */
private nesting = 0;
/** Current complexity score during analysis */
Expand Down Expand Up @@ -221,16 +230,9 @@ export class CSharpMetricsAnalyzer {
* @returns The enclosing type name, or null if none found
*/
private getEnclosingTypeName(node: Parser.SyntaxNode): string | null {
const typeDeclarations = new Set([
"class_declaration",
"struct_declaration",
"interface_declaration",
"record_declaration",
"enum_declaration",
]);
let parent = node.parent;
while (parent) {
if (typeDeclarations.has(parent.type)) {
if (CSharpMetricsAnalyzer.TYPE_DECLARATION_TYPES.has(parent.type)) {
const nameNode = parent.childForFieldName("name");
if (nameNode) {
return this.sourceText.substring(nameNode.startIndex, nameNode.endIndex);
Expand Down
14 changes: 6 additions & 8 deletions src/metricsAnalyzer/languages/goAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ export class GoMetricsAnalyzer {
}

/**
* Finds the type identifier within a parameter list (used for method receivers).
* Finds the type node within a parameter list (used for method receivers).
* Returns the full type node via the tree-sitter "type" field, which correctly
* handles any type form the grammar may produce (pointer, qualified, slice, etc.).
*
* @param parameterList - The parameter list node to search
* @returns The type node or null if not found
Expand All @@ -278,13 +280,9 @@ export class GoMetricsAnalyzer {
): Parser.SyntaxNode | null {
for (const child of parameterList.children) {
if (child.type === "parameter_declaration") {
// Look for type_identifier or pointer_type
const typeNode = child.children.find(
(c) =>
c.type === "type_identifier" ||
c.type === "pointer_type" ||
c.type === "qualified_type"
);
// Use childForFieldName for O(1) field access rather than a linear
// scan over the parameter's children.
const typeNode = child.childForFieldName("type");
Comment on lines +283 to +285
if (typeNode) {
return typeNode;
}
Expand Down