1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-19 16:58:48 +02:00

Improve sequencing of various content/header checks in abstract block diffs

Summary:
Ref T13425. Some diff checks currently sequence incorrectly:

  - When we're rendering block lists, syntax highlighting isn't relevant.
  - The "large change" guard can prevent rendering of otherwise-renderable changes.
  - Actual errors in the document engine (like bad JSON in a ".ipynb" file) aren't surfaced properly.

Improve sequencing somewhat to resolve these issues.

Test Plan:
  - Viewed a notebook, no longer saw a "highlighting disabled" warning.
  - Forced a notebook to fail, got a useful inline error instead of a popup dialog error.
  - Forced a notebook to have a large number of differences, got a rendering out of it.

Maniphest Tasks: T13425

Differential Revision: https://secure.phabricator.com/D20843
This commit is contained in:
epriestley 2019-09-27 13:14:45 -07:00
parent 9944b669ad
commit a7f3316aa3
7 changed files with 72 additions and 17 deletions

View file

@ -868,8 +868,11 @@ final class DifferentialChangesetParser extends Phobject {
->setHighlightingDisabled($this->highlightingDisabled)
->setDepthOnlyLines($this->getDepthOnlyLines());
$engine_blocks = $this->newDocumentEngineBlocks();
$has_document_engine = ($engine_blocks !== null);
$shield = null;
if ($this->isTopLevel && !$this->comments) {
if ($this->isTopLevel && !$this->comments && !$has_document_engine) {
if ($this->isGenerated()) {
$shield = $renderer->renderShield(
pht(
@ -1024,7 +1027,6 @@ final class DifferentialChangesetParser extends Phobject {
->setOldComments($old_comments)
->setNewComments($new_comments);
$engine_blocks = $this->newDocumentEngineChangesetView();
if ($engine_blocks !== null) {
$reference = $this->getRenderingReference();
$parts = explode('/', $reference);
@ -1041,6 +1043,8 @@ final class DifferentialChangesetParser extends Phobject {
$vs = $id;
}
$renderer->setDocumentEngineBlocks($engine_blocks);
return $renderer->renderDocumentEngineBlocks(
$engine_blocks,
(string)$id,
@ -1653,7 +1657,7 @@ final class DifferentialChangesetParser extends Phobject {
return $prefix.$line;
}
private function newDocumentEngineChangesetView() {
private function newDocumentEngineBlocks() {
$changeset = $this->changeset;
$viewer = $this->getViewer();
@ -1724,7 +1728,7 @@ final class DifferentialChangesetParser extends Phobject {
}
if ($document_engine) {
return $document_engine->newDiffView(
return $document_engine->newEngineBlocks(
$old_ref,
$new_ref);
}

View file

@ -270,11 +270,20 @@ abstract class DifferentialChangesetHTMLRenderer
}
}
if ($this->getHighlightingDisabled()) {
$messages[] = pht(
'This file is larger than %s, so syntax highlighting is '.
'disabled by default.',
phutil_format_bytes(DifferentialChangesetParser::HIGHLIGHT_BYTE_LIMIT));
$blocks = $this->getDocumentEngineBlocks();
if ($blocks) {
foreach ($blocks->getMessages() as $message) {
$messages[] = $message;
}
} else {
if ($this->getHighlightingDisabled()) {
$byte_limit = DifferentialChangesetParser::HIGHLIGHT_BYTE_LIMIT;
$byte_limit = phutil_format_bytes($byte_limit);
$messages[] = pht(
'This file is larger than %s, so syntax highlighting is '.
'disabled by default.',
$byte_limit);
}
}
return $this->formatHeaderMessages($messages);

View file

@ -35,6 +35,7 @@ abstract class DifferentialChangesetRenderer extends Phobject {
private $highlightingDisabled;
private $scopeEngine = false;
private $depthOnlyLines;
private $documentEngineBlocks;
private $oldFile = false;
private $newFile = false;
@ -239,6 +240,16 @@ abstract class DifferentialChangesetRenderer extends Phobject {
return $this->oldChangesetID;
}
public function setDocumentEngineBlocks(
PhabricatorDocumentEngineBlocks $blocks) {
$this->documentEngineBlocks = $blocks;
return $this;
}
public function getDocumentEngineBlocks() {
return $this->documentEngineBlocks;
}
public function setNewComments(array $new_comments) {
foreach ($new_comments as $line_number => $comments) {
assert_instances_of($comments, 'PhabricatorInlineCommentInterface');
@ -355,6 +366,16 @@ abstract class DifferentialChangesetRenderer extends Phobject {
$notice = null;
if ($this->getIsTopLevel()) {
$force = (!$content && !$props);
// If we have DocumentEngine messages about the blocks, assume they
// explain why there's no content.
$blocks = $this->getDocumentEngineBlocks();
if ($blocks) {
if ($blocks->getMessages()) {
$force = false;
}
}
$notice = $this->renderChangeTypeHeader($force);
}

View file

@ -4,6 +4,16 @@ final class PhabricatorDocumentEngineBlocks
extends Phobject {
private $lists = array();
private $messages = array();
public function addMessage($message) {
$this->messages[] = $message;
return $this;
}
public function getMessages() {
return $this->messages;
}
public function addBlockList(PhabricatorDocumentRef $ref, array $blocks) {
assert_instances_of($blocks, 'PhabricatorDocumentEngineBlock');
@ -20,6 +30,10 @@ final class PhabricatorDocumentEngineBlocks
$rows = array();
$lists = $this->lists;
if (count($lists) != 2) {
return array();
}
$specs = array();
foreach ($this->lists as $list) {
$specs[] = $this->newDiffSpec($list['blocks']);

View file

@ -37,7 +37,7 @@ abstract class PhabricatorDocumentEngine
return false;
}
public function newDiffView(
public function newEngineBlocks(
PhabricatorDocumentRef $uref,
PhabricatorDocumentRef $vref) {
throw new PhutilMethodNotImplementedException();

View file

@ -27,7 +27,7 @@ final class PhabricatorImageDocumentEngine
return ($uref->getFile() && $vref->getFile());
}
public function newDiffView(
public function newEngineBlocks(
PhabricatorDocumentRef $uref,
PhabricatorDocumentRef $vref) {

View file

@ -41,16 +41,23 @@ final class PhabricatorJupyterDocumentEngine
return true;
}
public function newDiffView(
public function newEngineBlocks(
PhabricatorDocumentRef $uref,
PhabricatorDocumentRef $vref) {
$u_blocks = $this->newDiffBlocks($uref);
$v_blocks = $this->newDiffBlocks($vref);
$blocks = new PhabricatorDocumentEngineBlocks();
return id(new PhabricatorDocumentEngineBlocks())
->addBlockList($uref, $u_blocks)
->addBlockList($vref, $v_blocks);
try {
$u_blocks = $this->newDiffBlocks($uref);
$v_blocks = $this->newDiffBlocks($vref);
$blocks->addBlockList($uref, $u_blocks);
$blocks->addBlockList($vref, $v_blocks);
} catch (Exception $ex) {
$blocks->addMessage($ex->getMessage());
}
return $blocks;
}
private function newDiffBlocks(PhabricatorDocumentRef $ref) {