Restore coverage reporting to Diffusion browse UI

Summary:
Depends on D19377. Ref T13125. Ref T13124. Ref T13105. Coverage reporting in Diffusion didn't initially survive the transition to Document Engine; restore it.

This adds some tentative/theoretical support for multiple columns of coverage, but no way to actually produce them in the UI. For now, the labels, codes, and colors are hard coded.

Test Plan:
Added coverage with `diffusion.updatecoverage`, saw coverage in the UI:

{F5525542}

Hovered over coverage, got labels and highlighting.

Double-checked labels for "N" (Not Executable) and "U" (Uncovered). See PHI577.

Faked some multi-column coverage, but you can't currently get this yourself today:

{F5525544}

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13125, T13124, T13105

Differential Revision: https://secure.phabricator.com/D19378
This commit is contained in:
epriestley
2018-04-17 06:40:41 -07:00
parent 21bb0215db
commit 665529ab60
10 changed files with 159 additions and 15 deletions

View File

@@ -4,7 +4,6 @@ final class DiffusionBrowseController extends DiffusionController {
private $lintCommit;
private $lintMessages;
private $coverage;
private $corpusButtons = array();
public function shouldAllowPublic() {
@@ -182,7 +181,6 @@ final class DiffusionBrowseController extends DiffusionController {
$corpus = $this->buildGitLFSCorpus($lfs_ref);
} else {
$this->coverage = $drequest->loadCoverage();
$show_editor = true;
$ref = id(new PhabricatorDocumentRef())

View File

@@ -81,6 +81,11 @@ final class DiffusionDocumentRenderingEngine
$ref
->setSymbolMetadata($this->getSymbolMetadata())
->setBlameURI($blame_uri);
$coverage = $drequest->loadCoverage();
if (strlen($coverage)) {
$ref->addCoverage($coverage);
}
}
private function getSymbolMetadata() {

View File

@@ -10,6 +10,7 @@ final class PhabricatorDocumentRef
private $snippet;
private $symbolMetadata = array();
private $blameURI;
private $coverage = array();
public function setFile(PhabricatorFile $file) {
$this->file = $file;
@@ -151,4 +152,15 @@ final class PhabricatorDocumentRef
return $this->blameURI;
}
public function addCoverage($coverage) {
$this->coverage[] = array(
'data' => $coverage,
);
return $this;
}
public function getCoverage() {
return $this->coverage;
}
}

View File

@@ -57,6 +57,10 @@ final class PhabricatorSourceDocumentEngine
$options['blame'] = $blame;
}
if ($ref->getCoverage()) {
$options['coverage'] = $ref->getCoverage();
}
return array(
$messages,
$this->newTextDocumentContent($ref, $content, $options),

View File

@@ -22,6 +22,7 @@ abstract class PhabricatorTextDocumentEngine
$options,
array(
'blame' => 'optional wild',
'coverage' => 'optional list<wild>',
));
if (is_array($content)) {
@@ -40,6 +41,11 @@ abstract class PhabricatorTextDocumentEngine
$view->setBlameMap($blame);
}
$coverage = idx($options, 'coverage');
if ($coverage !== null) {
$view->setCoverage($coverage);
}
$message = null;
if ($this->encodingMessage !== null) {
$message = $this->newMessage($this->encodingMessage);

View File

@@ -145,6 +145,17 @@ abstract class PhabricatorDocumentRenderingEngine
'uri' => $ref->getBlameURI(),
'value' => null,
),
'coverage' => array(
'labels' => array(
// TODO: Modularize this properly, see T13125.
array(
'C' => pht('Covered'),
'U' => pht('Not Covered'),
'N' => pht('Not Executable'),
'X' => pht('Not Reachable'),
),
),
),
);
$view_button = id(new PHUIButtonView())

View File

@@ -10,6 +10,7 @@ final class PhabricatorSourceCodeView extends AphrontView {
private $truncatedFirstLines = false;
private $symbolMetadata;
private $blameMap;
private $coverage = array();
public function setLines(array $lines) {
$this->lines = $lines;
@@ -59,6 +60,15 @@ final class PhabricatorSourceCodeView extends AphrontView {
return $this->blameMap;
}
public function setCoverage(array $coverage) {
$this->coverage = $coverage;
return $this;
}
public function getCoverage() {
return $this->coverage;
}
public function render() {
$blame_map = $this->getBlameMap();
$has_blame = ($blame_map !== null);
@@ -97,6 +107,19 @@ final class PhabricatorSourceCodeView extends AphrontView {
$base_uri = (string)$this->uri;
$wrote_anchor = false;
$coverage = $this->getCoverage();
$coverage_count = count($coverage);
$coverage_data = ipull($coverage, 'data');
// TODO: Modularize this properly, see T13125.
$coverage_map = array(
'C' => 'background: #66bbff;',
'U' => 'background: #dd8866;',
'N' => 'background: #ddeeff;',
'X' => 'background: #aa00aa;',
);
foreach ($lines as $line) {
$row_attributes = array();
if (isset($this->highlights[$line_number])) {
@@ -157,6 +180,25 @@ final class PhabricatorSourceCodeView extends AphrontView {
$blame_cells = null;
}
$coverage_cells = array();
foreach ($coverage as $coverage_idx => $coverage_spec) {
if (isset($coverage_spec['data'][$line_number - 1])) {
$coverage_char = $coverage_spec['data'][$line_number - 1];
} else {
$coverage_char = null;
}
$coverage_style = idx($coverage_map, $coverage_char, null);
$coverage_cells[] = phutil_tag(
'th',
array(
'class' => 'phabricator-source-coverage',
'style' => $coverage_style,
'data-coverage' => $coverage_idx.'/'.$coverage_char,
));
}
$rows[] = phutil_tag(
'tr',
$row_attributes,
@@ -174,7 +216,8 @@ final class PhabricatorSourceCodeView extends AphrontView {
'class' => 'phabricator-source-code',
),
$line),
));
$coverage_cells,
));
$line_number++;
}