1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 17:28:51 +02:00

Allow ghost atoms to be rendered

Summary: Ref T4558. Allow ghost atoms to be rendered in #diviner. This functionality didn't exist previously, but was hinted at by the TODO comments.

Test Plan: Generated #diviner documentation for rARC and then removed a class (before re-generating the documentation). Navigated to the documentation for the removed class and saw "This atom no longer exists".

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley

Maniphest Tasks: T4558

Differential Revision: https://secure.phabricator.com/D13114
This commit is contained in:
Joshua Spence 2015-06-05 17:52:58 +10:00
parent c1c897b961
commit 006a877996
3 changed files with 102 additions and 59 deletions

View file

@ -35,11 +35,6 @@ final class DivinerAtomController extends DivinerController {
return new Aphront404Response();
}
// TODO: This query won't load ghosts, because they'll fail `needAtoms()`.
// Instead, we might want to load ghosts and render a message like
// "this thing existed in an older version, but no longer does", especially
// if we add content like comments.
$symbol = id(new DivinerAtomQuery())
->setViewer($viewer)
->withBookPHIDs(array($book->getPHID()))
@ -47,7 +42,6 @@ final class DivinerAtomController extends DivinerController {
->withNames(array($this->atomName))
->withContexts(array($this->atomContext))
->withIndexes(array($this->atomIndex))
->withGhosts(false)
->withIsDocumentable(true)
->needAtoms(true)
->needExtends(true)
@ -66,9 +60,9 @@ final class DivinerAtomController extends DivinerController {
$book->getShortTitle(),
'/book/'.$book->getName().'/');
$atom_short_title = $atom->getDocblockMetaValue(
'short',
$symbol->getTitle());
$atom_short_title = $atom
? $atom->getDocblockMetaValue('short', $symbol->getTitle())
: $symbol->getTitle();
$crumbs->addTextCrumb($atom_short_title);
@ -78,17 +72,26 @@ final class DivinerAtomController extends DivinerController {
id(new PHUITagView())
->setType(PHUITagView::TYPE_STATE)
->setBackgroundColor(PHUITagView::COLOR_BLUE)
->setName(DivinerAtom::getAtomTypeNameString($atom->getType())));
->setName(DivinerAtom::getAtomTypeNameString(
$atom ? $atom->getType() : $symbol->getType())));
$properties = id(new PHUIPropertyListView());
$group = $atom->getProperty('group');
$group = $atom ? $atom->getProperty('group') : $symbol->getGroupName();
if ($group) {
$group_name = $book->getGroupName($group);
} else {
$group_name = null;
}
$document = id(new PHUIDocumentView())
->setBook($book->getTitle(), $group_name)
->setHeader($header)
->addClass('diviner-view')
->setFontKit(PHUIDocumentView::FONT_SOURCE_SANS)
->appendChild($properties);
if ($atom) {
$this->buildDefined($properties, $symbol);
$this->buildExtendsAndImplements($properties, $symbol);
@ -100,6 +103,9 @@ final class DivinerAtomController extends DivinerController {
->setSeverity(PHUIInfoView::SEVERITY_WARNING);
}
$document->appendChild($warnings);
}
$methods = $this->composeMethods($symbol);
$field = 'default';
@ -113,7 +119,10 @@ final class DivinerAtomController extends DivinerController {
}
$engine->process();
if ($atom) {
$content = $this->renderDocumentationText($symbol, $engine);
$document->appendChild($content);
}
$toc = $engine->getEngineMetadata(
$symbol,
@ -121,16 +130,18 @@ final class DivinerAtomController extends DivinerController {
PhutilRemarkupHeaderBlockRule::KEY_HEADER_TOC,
array());
$document = id(new PHUIDocumentView())
->setBook($book->getTitle(), $group_name)
->setHeader($header)
->addClass('diviner-view')
->setFontKit(PHUIDocumentView::FONT_SOURCE_SANS)
->appendChild($properties)
->appendChild($warnings)
->appendChild($content);
if (!$atom) {
$document->appendChild(
id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
->appendChild(
pht(
'This atom no longer exists.')));
}
if ($atom) {
$document->appendChild($this->buildParametersAndReturn(array($symbol)));
}
if ($methods) {
$tasks = $this->composeTasks($symbol);
@ -473,6 +484,8 @@ final class DivinerAtomController extends DivinerController {
$atom = $symbol->getAtom();
$out = array();
if ($atom) {
if ($atom->getProperty('final')) {
$out[] = 'final';
}
@ -488,6 +501,7 @@ final class DivinerAtomController extends DivinerController {
if ($atom->getProperty('static')) {
$out[] = 'static';
}
}
switch ($symbol->getType()) {
case DivinerAtom::TYPE_CLASS:
@ -530,6 +544,7 @@ final class DivinerAtomController extends DivinerController {
$out = phutil_implode_html(' ', $out);
if ($atom) {
$parameters = $atom->getProperty('parameters');
if ($parameters !== null) {
$pout = array();
@ -538,6 +553,7 @@ final class DivinerAtomController extends DivinerController {
}
$out = array($out, '('.implode(', ', $pout).')');
}
}
return phutil_tag(
'span',

View file

@ -151,10 +151,6 @@ final class DivinerAtomQuery extends PhabricatorCursorPagedPolicyAwareQuery {
foreach ($atoms as $key => $atom) {
$data = idx($atom_data, $atom->getPHID());
if (!$data) {
unset($atoms[$key]);
continue;
}
$atom->attachAtom($data);
}
}
@ -170,6 +166,10 @@ final class DivinerAtomQuery extends PhabricatorCursorPagedPolicyAwareQuery {
$names = array();
foreach ($atoms as $atom) {
if (!$atom->getAtom()) {
continue;
}
foreach ($atom->getAtom()->getExtends() as $xref) {
$names[] = $xref->getName();
}
@ -189,10 +189,17 @@ final class DivinerAtomQuery extends PhabricatorCursorPagedPolicyAwareQuery {
}
foreach ($atoms as $atom) {
$alang = $atom->getAtom()->getLanguage();
$extends = array();
foreach ($atom->getAtom()->getExtends() as $xref) {
$atom_lang = null;
$atom_extends = array();
if ($atom->getAtom()) {
$atom_lang = $atom->getAtom()->getLanguage();
$atom_extends = $atom->getAtom()->getExtends();
}
$extends = array();
foreach ($atom_extends as $xref) {
// If there are no symbols of the matching name and type, we can't
// resolve this.
if (empty($xatoms[$xref->getName()][$xref->getType()])) {
@ -216,7 +223,7 @@ final class DivinerAtomQuery extends PhabricatorCursorPagedPolicyAwareQuery {
// classes can not implement JS classes.
$same_lang = array();
foreach ($maybe as $xatom) {
if ($xatom->getAtom()->getLanguage() == $alang) {
if ($xatom->getAtom()->getLanguage() == $atom_lang) {
$same_lang[] = $xatom;
}
}
@ -396,7 +403,13 @@ final class DivinerAtomQuery extends PhabricatorCursorPagedPolicyAwareQuery {
$hashes = array();
foreach ($symbols as $symbol) {
foreach ($symbol->getAtom()->getChildHashes() as $hash) {
$child_hashes = array();
if ($symbol->getAtom()) {
$child_hashes = $symbol->getAtom()->getChildHashes();
}
foreach ($child_hashes as $hash) {
$hashes[$hash] = $hash;
}
if ($recurse_up) {
@ -426,8 +439,14 @@ final class DivinerAtomQuery extends PhabricatorCursorPagedPolicyAwareQuery {
assert_instances_of($children, 'DivinerLiveSymbol');
foreach ($symbols as $symbol) {
$child_hashes = array();
$symbol_children = array();
foreach ($symbol->getAtom()->getChildHashes() as $hash) {
if ($symbol->getAtom()) {
$child_hashes = $symbol->getAtom()->getChildHashes();
}
foreach ($child_hashes as $hash) {
if (isset($children[$hash])) {
$symbol_children[] = $children[$hash];
}

View file

@ -98,8 +98,12 @@ final class DivinerLiveSymbol extends DivinerDAO
return $this->assertAttached($this->atom);
}
public function attachAtom(DivinerLiveAtom $atom) {
public function attachAtom(DivinerLiveAtom $atom = null) {
if ($atom === null) {
$this->atom = null;
} else {
$this->atom = DivinerAtom::newFromDictionary($atom->getAtomData());
}
return $this;
}
@ -229,6 +233,10 @@ final class DivinerLiveSymbol extends DivinerDAO
public function getMarkupText($field) {
if (!$this->getAtom()) {
return;
}
return $this->getAtom()->getDocblockText();
}