Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/diff/PhabricatorDiffScopeEngine.php
Show First 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | for ($ii = $line - 1; $ii > $search_until; $ii--) { | ||||
$depth = $depth_map[$ii]; | $depth = $depth_map[$ii]; | ||||
// This line is all whitespace. This isn't a possible match. | // This line is all whitespace. This isn't a possible match. | ||||
if ($depth === null) { | if ($depth === null) { | ||||
continue; | continue; | ||||
} | } | ||||
// Don't match context lines which are too deeply indented, since they | |||||
// are very unlikely to be symbol definitions. | |||||
if ($depth > 2) { | |||||
continue; | |||||
} | |||||
// The depth is the same as (or greater than) the depth we started with, | // The depth is the same as (or greater than) the depth we started with, | ||||
// so this isn't a possible match. | // so this isn't a possible match. | ||||
if ($depth >= $line_depth) { | if ($depth >= $line_depth) { | ||||
continue; | continue; | ||||
} | } | ||||
// Reject lines which begin with "}" or "{". These lines are probably | // Reject lines which begin with "}" or "{". These lines are probably | ||||
// never good matches. | // never good matches. | ||||
Show All 10 Lines | final class PhabricatorDiffScopeEngine | ||||
private function getLineDepthMap() { | private function getLineDepthMap() { | ||||
if (!$this->lineDepthMap) { | if (!$this->lineDepthMap) { | ||||
$this->lineDepthMap = $this->newLineDepthMap(); | $this->lineDepthMap = $this->newLineDepthMap(); | ||||
} | } | ||||
return $this->lineDepthMap; | return $this->lineDepthMap; | ||||
} | } | ||||
private function getTabWidth() { | |||||
// TODO: This should be configurable once we handle tab widths better. | |||||
return 2; | |||||
} | |||||
private function newLineDepthMap() { | private function newLineDepthMap() { | ||||
$text_map = $this->getLineTextMap(); | $text_map = $this->getLineTextMap(); | ||||
$tab_width = $this->getTabWidth(); | |||||
// TODO: This should be configurable once we handle tab widths better. | |||||
$tab_width = 2; | |||||
$depth_map = array(); | $depth_map = array(); | ||||
foreach ($text_map as $line_number => $line_text) { | foreach ($text_map as $line_number => $line_text) { | ||||
if ($line_text === null) { | if ($line_text === null) { | ||||
$depth_map[$line_number] = null; | $depth_map[$line_number] = null; | ||||
continue; | continue; | ||||
} | } | ||||
Show All 13 Lines | foreach ($text_map as $line_number => $line_text) { | ||||
} else if ($c == "\t") { | } else if ($c == "\t") { | ||||
$count += $tab_width; | $count += $tab_width; | ||||
} else { | } else { | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
// Round down to cheat our way through the " *" parts of docblock | // Round down to cheat our way through the " *" parts of docblock | ||||
// comments. This is generally a reasonble heuristic because odd tab | // comments. | ||||
// widths are exceptionally rare. | $depth = (int)floor($count / $tab_width); | ||||
$depth = ($count >> 1); | |||||
$depth_map[$line_number] = $depth; | $depth_map[$line_number] = $depth; | ||||
} | } | ||||
return $depth_map; | return $depth_map; | ||||
} | } | ||||
} | } |