Address code review feedback

- Fix context analysis to use original file lines instead of merged lines
- Add named constants for confidence score weights
- Add named constant for import scan limit
- Improve code maintainability and documentation

Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-27 02:47:17 +00:00
parent 7c489b5c55
commit a0f7fcb63e
3 changed files with 21 additions and 13 deletions

View File

@@ -12,6 +12,9 @@ namespace analysis {
namespace {
// Maximum number of lines to scan for imports (imports typically at file top)
constexpr size_t IMPORT_SCAN_LIMIT = 50;
/**
* @brief Trim whitespace from string.
*/
@@ -209,8 +212,8 @@ std::vector<std::string> extract_imports(
) {
std::vector<std::string> imports;
// Scan first 50 lines (imports are typically at the top)
size_t scan_limit = std::min(lines.size(), size_t(50));
// Scan first lines for imports (imports are typically at the top)
size_t scan_limit = std::min(lines.size(), IMPORT_SCAN_LIMIT);
for (size_t i = 0; i < scan_limit; ++i) {
std::string line = trim(lines[i]);

View File

@@ -13,6 +13,11 @@ namespace analysis {
namespace {
// Confidence score weights for risk assessment
constexpr double BASE_CONFIDENCE = 0.5; // Base confidence level
constexpr double SIMILARITY_WEIGHT = 0.3; // Weight for code similarity
constexpr double CHANGE_RATIO_WEIGHT = 0.2; // Weight for change ratio
/**
* @brief Trim whitespace from string.
*/
@@ -198,8 +203,10 @@ RiskAssessment analyze_risk_ours(
// Calculate confidence score based on various factors
double change_ratio = (our_changes + their_changes) > 0 ?
static_cast<double>(our_changes) / (our_changes + their_changes) : 0.5;
assessment.confidence_score = 0.5 + (0.3 * similarity_to_theirs) + (0.2 * change_ratio);
static_cast<double>(our_changes) / (our_changes + their_changes) : BASE_CONFIDENCE;
assessment.confidence_score = BASE_CONFIDENCE +
(SIMILARITY_WEIGHT * similarity_to_theirs) +
(CHANGE_RATIO_WEIGHT * change_ratio);
// Add recommendations
if (assessment.level >= RiskLevel::MEDIUM) {
@@ -273,8 +280,10 @@ RiskAssessment analyze_risk_theirs(
// Calculate confidence score
double change_ratio = (our_changes + their_changes) > 0 ?
static_cast<double>(their_changes) / (our_changes + their_changes) : 0.5;
assessment.confidence_score = 0.5 + (0.3 * similarity_to_ours) + (0.2 * change_ratio);
static_cast<double>(their_changes) / (our_changes + their_changes) : BASE_CONFIDENCE;
assessment.confidence_score = BASE_CONFIDENCE +
(SIMILARITY_WEIGHT * similarity_to_ours) +
(CHANGE_RATIO_WEIGHT * change_ratio);
// Add recommendations
if (assessment.level >= RiskLevel::MEDIUM) {

View File

@@ -70,13 +70,9 @@ MergeResult three_way_merge(
conflict.their_lines.push_back({their_line, Line::THEIRS});
conflict.end_line = result.merged_lines.size();
// Perform context analysis
// Use the merged lines we have so far as context
std::vector<std::string> context_lines;
for (const auto& line : result.merged_lines) {
context_lines.push_back(line.content);
}
conflict.context = analysis::analyze_context(context_lines, i, i);
// Perform context analysis using ours version as context
// (could also use base or theirs, but ours is typically most relevant)
conflict.context = analysis::analyze_context(ours, i, i);
// Perform risk analysis for different resolution strategies
std::vector<std::string> base_vec = {base_line};