-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/server enhancements #20
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,32 +13,67 @@ internal class CodeContentProcessor(private val patterns: LanguagePatterns, priv | |
| * Processes a list of code lines and returns those that should be included in the summary. Lines are included if they | ||
| * are definitions, comments, or part of a block comment. | ||
| * | ||
| * The processing follows a two-pass approach: | ||
| * 1. First pass: Decides which original lines should be included, tracking comment block state | ||
| * 2. Second pass: Builds output with explicit separators between non-contiguous regions | ||
| * | ||
| * During the first pass, lines are included if they are definitions, comments, or part of a block comment. The | ||
| * comment block state is tracked to ensure multi-line comments are properly captured. | ||
| * | ||
| * During the second pass, separators ("...") are added between non-contiguous regions to indicate omitted code | ||
| * sections. The maxLines limit is strictly respected, prioritizing code lines over separators. | ||
| * | ||
| * @param lines The lines of code to process. | ||
| * @return A list of lines selected for summarization. | ||
| * @return A list of lines selected for summarization, with separators indicating omitted sections. | ||
| */ | ||
| fun processContent(lines: List<String>): List<String> { | ||
| val finalState = | ||
| lines.fold(ProcessingState()) { state, line -> | ||
| if (state.lines.size >= maxLines) return@fold state | ||
| if (lines.isEmpty()) return emptyList() | ||
|
|
||
| // First pass: compute inclusion flags functionally while tracking the comment block state | ||
| data class Pass1(val flags: MutableList<Boolean>, val inBlock: Boolean) | ||
|
|
||
| val pass1 = | ||
| lines.foldIndexed(Pass1(mutableListOf<Boolean>(), false)) { idx, acc, line -> | ||
| val trimmed = line.trim() | ||
| val nextInCommentBlock = determineCommentBlockState(trimmed, state.inCommentBlock) | ||
| val shouldIncludeLine = isDefinition(line) || isCommentLine(line) || state.inCommentBlock | ||
|
|
||
| val updatedLines = | ||
| if (shouldIncludeLine) { | ||
| when { | ||
| isDefinition(line) -> state.lines + processDefinitionLine(line) | ||
| else -> state.lines + line | ||
| } | ||
| } else { | ||
| state.lines | ||
| } | ||
|
|
||
| ProcessingState(updatedLines, nextInCommentBlock) | ||
| val shouldInclude = isDefinition(line) || isCommentLine(line) || acc.inBlock | ||
| acc.flags.add(shouldInclude) | ||
| val nextInCommentBlock = determineCommentBlockState(trimmed, acc.inBlock) | ||
| acc.copy(flags = acc.flags, inBlock = nextInCommentBlock) | ||
| } | ||
|
|
||
| val includeFlags: List<Boolean> = pass1.flags | ||
|
|
||
| // Second pass: build output with separators between non-contiguous regions | ||
| // Accumulates second-pass output and the index of the last included source line | ||
| data class OutputAcc(val result: MutableList<String>, val lastIdx: Int) | ||
|
||
|
|
||
| fun maybeAddSeparatorFn(state: OutputAcc, nextIndex: Int): OutputAcc { | ||
| if (state.result.isEmpty()) return state | ||
| val isGap = nextIndex != state.lastIdx + 1 | ||
| if (!isGap) return state | ||
| if (state.result.size + 2 > maxLines) return state | ||
| state.result.add("...") | ||
| return state | ||
| } | ||
|
|
||
| val finalAcc: OutputAcc = | ||
| lines.indices.fold(OutputAcc(mutableListOf(), -2)) { acc, i -> | ||
| if (!includeFlags[i]) return@fold acc | ||
|
|
||
| val afterSep = maybeAddSeparatorFn(acc, i) | ||
|
|
||
| val line = lines[i] | ||
| val toAdd = if (isDefinition(line)) processDefinitionLine(line) else line | ||
|
|
||
| if (afterSep.result.size >= maxLines) return@fold afterSep | ||
|
|
||
| afterSep.result.add(toAdd) | ||
| val updated = afterSep.copy(result = afterSep.result, lastIdx = i) | ||
|
|
||
| if (updated.result.size >= maxLines) updated else updated | ||
| } | ||
|
|
||
| return finalState.lines | ||
| return finalAcc.result | ||
| } | ||
|
|
||
| private fun isDefinition(line: String): Boolean = patterns.definitionPattern.containsMatchIn(line.trim()) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Using MutableList in an immutable data class creates inconsistent mutability patterns. Consider using an immutable List and functional accumulation approach instead."