Skip to content

Commit 155c9be

Browse files
author
Eric Wheeler
committed
refactor: improve MIN_COMPONENT_LINES implementation
- Changed MIN_COMPONENT_LINES constant to use getter/setter functions - Updated references to use getMinComponentLines() function - Modified test helper to set value to 0 during tests - This establishes a single source of truth while making testing easier Signed-off-by: Eric Wheeler <[email protected]>
1 parent 3d7d353 commit 155c9be

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/services/tree-sitter/__tests__/helpers.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { jest } from "@jest/globals"
2-
import { parseSourceCodeDefinitionsForFile } from ".."
2+
import { parseSourceCodeDefinitionsForFile, setMinComponentLines } from ".."
33
import * as fs from "fs/promises"
44
import * as path from "path"
55
import Parser from "web-tree-sitter"
66
import tsxQuery from "../queries/tsx"
7-
87
// Mock setup
98
jest.mock("fs/promises")
109
export const mockedFs = jest.mocked(fs)
@@ -74,6 +73,9 @@ export async function testParseSourceCodeDefinitions(
7473
extKey?: string
7574
} = {},
7675
): Promise<string | undefined> {
76+
// Set minimum component lines to 0 for tests
77+
setMinComponentLines(0)
78+
7779
// Set default options
7880
const wasmFile = options.wasmFile || "tree-sitter-tsx.wasm"
7981
const queryString = options.queryString || tsxQuery

src/services/tree-sitter/index.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,25 @@ import { fileExistsAtPath } from "../../utils/fs"
66
import { parseMarkdown } from "./markdownParser"
77
import { RooIgnoreController } from "../../core/ignore/RooIgnoreController"
88

9-
const MIN_COMPONENT_LINES = 4
9+
// Private constant
10+
const DEFAULT_MIN_COMPONENT_LINES_VALUE = 4
11+
12+
// Getter function for MIN_COMPONENT_LINES (for easier testing)
13+
let currentMinComponentLines = DEFAULT_MIN_COMPONENT_LINES_VALUE
14+
15+
/**
16+
* Get the current minimum number of lines for a component to be included
17+
*/
18+
export function getMinComponentLines(): number {
19+
return currentMinComponentLines
20+
}
21+
22+
/**
23+
* Set the minimum number of lines for a component (for testing)
24+
*/
25+
export function setMinComponentLines(value: number): void {
26+
currentMinComponentLines = value
27+
}
1028

1129
const extensions = [
1230
"tla",
@@ -287,7 +305,7 @@ function processCaptures(captures: any[], lines: string[], language: string): st
287305
const lineCount = endLine - startLine + 1
288306

289307
// Skip components that don't span enough lines
290-
if (lineCount < MIN_COMPONENT_LINES) {
308+
if (lineCount < getMinComponentLines()) {
291309
return
292310
}
293311

@@ -325,7 +343,7 @@ function processCaptures(captures: any[], lines: string[], language: string): st
325343
const contextSpan = contextEnd - node.parent.startPosition.row + 1
326344

327345
// Only include context if it spans multiple lines
328-
if (contextSpan >= MIN_COMPONENT_LINES) {
346+
if (contextSpan >= getMinComponentLines()) {
329347
// Add the full range first
330348
const rangeKey = `${node.parent.startPosition.row}-${contextEnd}`
331349
if (!processedLines.has(rangeKey)) {

0 commit comments

Comments
 (0)