diff --git a/src/applications/differential/parser/DifferentialChangesetParser.php b/src/applications/differential/parser/DifferentialChangesetParser.php index 408988ed1f..3154a8a668 100644 --- a/src/applications/differential/parser/DifferentialChangesetParser.php +++ b/src/applications/differential/parser/DifferentialChangesetParser.php @@ -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); } diff --git a/src/applications/differential/render/DifferentialChangesetHTMLRenderer.php b/src/applications/differential/render/DifferentialChangesetHTMLRenderer.php index ae8db861b6..c856b9b14d 100644 --- a/src/applications/differential/render/DifferentialChangesetHTMLRenderer.php +++ b/src/applications/differential/render/DifferentialChangesetHTMLRenderer.php @@ -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); diff --git a/src/applications/differential/render/DifferentialChangesetRenderer.php b/src/applications/differential/render/DifferentialChangesetRenderer.php index e6c6f01fb7..769b1ee9f8 100644 --- a/src/applications/differential/render/DifferentialChangesetRenderer.php +++ b/src/applications/differential/render/DifferentialChangesetRenderer.php @@ -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); } diff --git a/src/applications/files/diff/PhabricatorDocumentEngineBlocks.php b/src/applications/files/diff/PhabricatorDocumentEngineBlocks.php index fc45c204a8..0dc033d74c 100644 --- a/src/applications/files/diff/PhabricatorDocumentEngineBlocks.php +++ b/src/applications/files/diff/PhabricatorDocumentEngineBlocks.php @@ -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']); diff --git a/src/applications/files/document/PhabricatorDocumentEngine.php b/src/applications/files/document/PhabricatorDocumentEngine.php index 7e2a0d3b34..20769553fb 100644 --- a/src/applications/files/document/PhabricatorDocumentEngine.php +++ b/src/applications/files/document/PhabricatorDocumentEngine.php @@ -37,7 +37,7 @@ abstract class PhabricatorDocumentEngine return false; } - public function newDiffView( + public function newEngineBlocks( PhabricatorDocumentRef $uref, PhabricatorDocumentRef $vref) { throw new PhutilMethodNotImplementedException(); diff --git a/src/applications/files/document/PhabricatorImageDocumentEngine.php b/src/applications/files/document/PhabricatorImageDocumentEngine.php index 53dcb83965..8f39df0e5b 100644 --- a/src/applications/files/document/PhabricatorImageDocumentEngine.php +++ b/src/applications/files/document/PhabricatorImageDocumentEngine.php @@ -27,7 +27,7 @@ final class PhabricatorImageDocumentEngine return ($uref->getFile() && $vref->getFile()); } - public function newDiffView( + public function newEngineBlocks( PhabricatorDocumentRef $uref, PhabricatorDocumentRef $vref) { diff --git a/src/applications/files/document/PhabricatorJupyterDocumentEngine.php b/src/applications/files/document/PhabricatorJupyterDocumentEngine.php index 9836797f84..17e32d0cd0 100644 --- a/src/applications/files/document/PhabricatorJupyterDocumentEngine.php +++ b/src/applications/files/document/PhabricatorJupyterDocumentEngine.php @@ -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) {