1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 00:32:42 +01:00

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
This commit is contained in:
epriestley 2019-04-25 15:26:48 -07:00
parent 6eae75d8f2
commit 6d13b9fb7a

View file

@ -83,6 +83,12 @@ final class PhabricatorDiffScopeEngine
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,
// so this isn't a possible match.
if ($depth >= $line_depth) {
@ -109,11 +115,14 @@ final class PhabricatorDiffScopeEngine
return $this->lineDepthMap;
}
private function getTabWidth() {
// TODO: This should be configurable once we handle tab widths better.
return 2;
}
private function newLineDepthMap() {
$text_map = $this->getLineTextMap();
// TODO: This should be configurable once we handle tab widths better.
$tab_width = 2;
$tab_width = $this->getTabWidth();
$depth_map = array();
foreach ($text_map as $line_number => $line_text) {
@ -143,9 +152,8 @@ final class PhabricatorDiffScopeEngine
}
// Round down to cheat our way through the " *" parts of docblock
// comments. This is generally a reasonble heuristic because odd tab
// widths are exceptionally rare.
$depth = ($count >> 1);
// comments.
$depth = (int)floor($count / $tab_width);
$depth_map[$line_number] = $depth;
}