-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Optimizing listCodeDefinitionNamesTool for Object-oriented design language. FIX 7330 #7373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dafe76e
e015096
a0be919
75670f3
c0dbbaf
cdbba62
59a3dc9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,15 @@ import { parseMarkdown } from "./markdownParser" | |
| import { RooIgnoreController } from "../../core/ignore/RooIgnoreController" | ||
| import { QueryCapture } from "web-tree-sitter" | ||
|
|
||
| type OutputItem = { | ||
| startLine: number | ||
| endLine: number | ||
| type: string | ||
| startContent: string | ||
| } | ||
|
|
||
| const METHOD_CAPTURE = ["definition.method", "definition.method.start"] | ||
|
|
||
| // Private constant | ||
| const DEFAULT_MIN_COMPONENT_LINES_VALUE = 4 | ||
|
|
||
|
|
@@ -27,6 +36,14 @@ export function setMinComponentLines(value: number): void { | |
| currentMinComponentLines = value | ||
| } | ||
|
|
||
| function passesMinLines(lineCount: number, capture: QueryCapture, language: string) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method-specific bypass (added to handle Java) brings language concerns into the generic processor. Can we keep language-specific handling in queries (e.g., java.ts) or adopt a simpler language-agnostic rule, rather than special-casing in index.ts?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am confused about this. In the latest code, I did not introduce any language-specific processing logic in index.ts. |
||
| if (METHOD_CAPTURE.includes(capture.name)) { | ||
| // In object-oriented programming languages, method signatures are only one line and should not be ignored. | ||
| return false | ||
| } | ||
| return lineCount < getMinComponentLines() | ||
| } | ||
|
|
||
| const extensions = [ | ||
| "tla", | ||
| "js", | ||
|
|
@@ -262,7 +279,7 @@ This approach allows us to focus on the most relevant parts of the code (defined | |
| * | ||
| * @param captures - The captures to process | ||
| * @param lines - The lines of the file | ||
| * @param minComponentLines - Minimum number of lines for a component to be included | ||
| * @param language - The programming language of the file | ||
NaccOll marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @returns A formatted string with definitions | ||
| */ | ||
| function processCaptures(captures: QueryCapture[], lines: string[], language: string): string | null { | ||
|
|
@@ -283,7 +300,7 @@ function processCaptures(captures: QueryCapture[], lines: string[], language: st | |
| return null | ||
| } | ||
|
|
||
| let formattedOutput = "" | ||
| const outputArr: OutputItem[] = [] | ||
|
|
||
| // Sort captures by their start position | ||
| captures.sort((a, b) => a.node.startPosition.row - b.node.startPosition.row) | ||
|
|
@@ -310,7 +327,7 @@ function processCaptures(captures: QueryCapture[], lines: string[], language: st | |
| const lineCount = endLine - startLine + 1 | ||
|
|
||
| // Skip components that don't span enough lines | ||
| if (lineCount < getMinComponentLines()) { | ||
| if (passesMinLines(lineCount, capture, language)) { | ||
| return | ||
| } | ||
|
|
||
|
|
@@ -333,13 +350,23 @@ function processCaptures(captures: QueryCapture[], lines: string[], language: st | |
|
|
||
| // Add component name to output regardless of HTML filtering | ||
| if (!processedLines.has(lineKey) && componentName) { | ||
| formattedOutput += `${startLine + 1}--${endLine + 1} | ${lines[startLine]}\n` | ||
| outputArr.push({ | ||
| startLine: startLine, | ||
| endLine: endLine, | ||
| type: name, | ||
| startContent: lines[startLine], | ||
| }) | ||
| processedLines.add(lineKey) | ||
| } | ||
| } | ||
| // For other component definitions | ||
| else if (isNotHtmlElement(startLineContent)) { | ||
| formattedOutput += `${startLine + 1}--${endLine + 1} | ${lines[startLine]}\n` | ||
| outputArr.push({ | ||
| startLine: startLine, | ||
| endLine: endLine, | ||
| type: name, | ||
| startContent: lines[startLine], | ||
| }) | ||
| processedLines.add(lineKey) | ||
|
|
||
| // If this is part of a larger definition, include its non-HTML context | ||
|
|
@@ -352,16 +379,42 @@ function processCaptures(captures: QueryCapture[], lines: string[], language: st | |
| // Add the full range first | ||
| const rangeKey = `${node.parent.startPosition.row}-${contextEnd}` | ||
| if (!processedLines.has(rangeKey)) { | ||
| formattedOutput += `${node.parent.startPosition.row + 1}--${contextEnd + 1} | ${lines[node.parent.startPosition.row]}\n` | ||
| outputArr.push({ | ||
| startLine: node.parent.startPosition.row, | ||
| endLine: contextEnd, | ||
| type: name, | ||
| startContent: lines[node.parent.startPosition.row], | ||
| }) | ||
| processedLines.add(rangeKey) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| if (formattedOutput.length > 0) { | ||
| return formattedOutput | ||
| // Deduplication and filtering | ||
| const dedupedArr: OutputItem[] = [] | ||
| const seen = new Set<string>() | ||
| for (const item of outputArr) { | ||
| // Only skip if there is another item with the same startLine and startContent | ||
| if (item.startLine === item.endLine && METHOD_CAPTURE.includes(item.type)) { | ||
| const isDuplicate = outputArr.some( | ||
| (other) => | ||
| other !== item && other.startLine === item.startLine && other.startContent === item.startContent, | ||
| ) | ||
| if (isDuplicate) { | ||
| continue | ||
| } | ||
| } | ||
| const key = `${item.startLine}-${item.endLine}-${item.type}-${item.startContent}` | ||
| if (!seen.has(key)) { | ||
| dedupedArr.push(item) | ||
| seen.add(key) | ||
| } | ||
| } | ||
|
|
||
| if (dedupedArr.length > 0) { | ||
| return dedupedArr.map((item) => `${item.startLine + 1}--${item.endLine + 1} | ${item.startContent}`).join("\n") | ||
| } | ||
|
|
||
| return null | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,9 @@ export default ` | |
|
|
||
| ; Method declarations | ||
| (method_declaration | ||
| name: (identifier) @name.definition.method) @definition.method | ||
| type: (_) @definition.method.start | ||
|
||
| name: (identifier) @name.definition.method)@definition.method | ||
|
|
||
|
|
||
| ; Inner class declarations | ||
| (class_declaration | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test fixture modifications compress multi-line method declarations into single lines. Could this reduce test coverage for real-world Java code formatting? Consider keeping some multi-line examples to ensure the parser handles various formatting styles correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it actually expands to four lines just to accommodate currentMinComponentLines=4