Skip to content

Commit 6d13b9f

Browse files
author
epriestley
committedApr 30, 2019
Make very minor generality improvements to the scope selector
Summary: See PHI985. I think we pretty much need to start applying language-specific rules, but we can apply at least one more relatively language-agnostic rule: don't match lines which are indented 3+ levels. In C++, we may have symbols like this: ``` class X { public: int m() { ... } } ``` ..but I believe no mainstream language puts symbol definitions 3+ levels deep. Also clean up some of the tab handling very slightly. Test Plan: Tests pass, looked at some C++ code and got slightly better (but still not great) matches. Reviewers: amckinley Reviewed By: amckinley Differential Revision: https://secure.phabricator.com/D20479
1 parent 6eae75d commit 6d13b9f

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed
 

‎src/infrastructure/diff/PhabricatorDiffScopeEngine.php

+14-6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ public function getScopeStart($line) {
8383
continue;
8484
}
8585

86+
// Don't match context lines which are too deeply indented, since they
87+
// are very unlikely to be symbol definitions.
88+
if ($depth > 2) {
89+
continue;
90+
}
91+
8692
// The depth is the same as (or greater than) the depth we started with,
8793
// so this isn't a possible match.
8894
if ($depth >= $line_depth) {
@@ -109,11 +115,14 @@ private function getLineDepthMap() {
109115
return $this->lineDepthMap;
110116
}
111117

118+
private function getTabWidth() {
119+
// TODO: This should be configurable once we handle tab widths better.
120+
return 2;
121+
}
122+
112123
private function newLineDepthMap() {
113124
$text_map = $this->getLineTextMap();
114-
115-
// TODO: This should be configurable once we handle tab widths better.
116-
$tab_width = 2;
125+
$tab_width = $this->getTabWidth();
117126

118127
$depth_map = array();
119128
foreach ($text_map as $line_number => $line_text) {
@@ -143,9 +152,8 @@ private function newLineDepthMap() {
143152
}
144153

145154
// Round down to cheat our way through the " *" parts of docblock
146-
// comments. This is generally a reasonble heuristic because odd tab
147-
// widths are exceptionally rare.
148-
$depth = ($count >> 1);
155+
// comments.
156+
$depth = (int)floor($count / $tab_width);
149157

150158
$depth_map[$line_number] = $depth;
151159
}

0 commit comments

Comments
 (0)
Failed to load comments.