Make repository symbol references work with DocumentEngine
Summary: Ref T13105. Ref T13047. This makes symbol indexes work with DocumentEngine in Files, and restores support in Diffusion. Test Plan: Command-clicked stuff, got taken to the symbol index with reasonable metadata in Diffusion, Differential and Files. Reviewers: mydeveloperday Reviewed By: mydeveloperday Maniphest Tasks: T13105, T13047 Differential Revision: https://secure.phabricator.com/D19307
This commit is contained in:
@@ -69,4 +69,24 @@ final class DiffusionDocumentRenderingEngine
|
||||
return;
|
||||
}
|
||||
|
||||
protected function willRenderRef(PhabricatorDocumentRef $ref) {
|
||||
$ref->setSymbolMetadata($this->getSymbolMetadata());
|
||||
}
|
||||
|
||||
private function getSymbolMetadata() {
|
||||
$drequest = $this->getDiffusionRequest();
|
||||
|
||||
$repo = $drequest->getRepository();
|
||||
$symbol_repos = nonempty($repo->getSymbolSources(), array());
|
||||
$symbol_repos[] = $repo->getPHID();
|
||||
|
||||
$lang = last(explode('.', $drequest->getPath()));
|
||||
|
||||
return array(
|
||||
'repositories' => $symbol_repos,
|
||||
'lang' => $lang,
|
||||
'path' => $drequest->getPath(),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ final class PhabricatorDocumentRef
|
||||
private $file;
|
||||
private $byteLength;
|
||||
private $snippet;
|
||||
private $symbolMetadata = array();
|
||||
|
||||
public function setFile(PhabricatorFile $file) {
|
||||
$this->file = $file;
|
||||
@@ -131,4 +132,15 @@ final class PhabricatorDocumentRef
|
||||
return $this->snippet;
|
||||
}
|
||||
|
||||
public function setSymbolMetadata(array $metadata) {
|
||||
$this->symbolMetadata = $metadata;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSymbolMetadata() {
|
||||
return $this->symbolMetadata;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ final class PhabricatorJSONDocumentEngine
|
||||
|
||||
return array(
|
||||
$message,
|
||||
$this->newTextDocumentContent($content),
|
||||
$this->newTextDocumentContent($ref, $content),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ final class PhabricatorSourceDocumentEngine
|
||||
|
||||
return array(
|
||||
$messages,
|
||||
$this->newTextDocumentContent($content),
|
||||
$this->newTextDocumentContent($ref, $content),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,12 +13,15 @@ abstract class PhabricatorTextDocumentEngine
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function newTextDocumentContent($content) {
|
||||
protected function newTextDocumentContent(
|
||||
PhabricatorDocumentRef $ref,
|
||||
$content) {
|
||||
$lines = phutil_split_lines($content);
|
||||
|
||||
$view = id(new PhabricatorSourceCodeView())
|
||||
->setHighlights($this->getHighlightedLines())
|
||||
->setLines($lines);
|
||||
->setLines($lines)
|
||||
->setSymbolMetadata($ref->getSymbolMetadata());
|
||||
|
||||
$message = null;
|
||||
if ($this->encodingMessage !== null) {
|
||||
|
||||
@@ -105,6 +105,7 @@ abstract class PhabricatorDocumentRenderingEngine
|
||||
'renderControlID' => $control_id,
|
||||
);
|
||||
} else {
|
||||
$this->willRenderRef($ref);
|
||||
$content = $engine->newDocument($ref);
|
||||
$config = array();
|
||||
}
|
||||
@@ -158,6 +159,8 @@ abstract class PhabricatorDocumentRenderingEngine
|
||||
}
|
||||
|
||||
final public function newRenderResponse(PhabricatorDocumentRef $ref) {
|
||||
$this->willRenderRef($ref);
|
||||
|
||||
$request = $this->getRequest();
|
||||
$viewer = $request->getViewer();
|
||||
|
||||
@@ -290,4 +293,8 @@ abstract class PhabricatorDocumentRenderingEngine
|
||||
return;
|
||||
}
|
||||
|
||||
protected function willRenderRef(PhabricatorDocumentRef $ref) {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ final class PhabricatorSourceCodeView extends AphrontView {
|
||||
private $canClickHighlight = true;
|
||||
private $truncatedFirstBytes = false;
|
||||
private $truncatedFirstLines = false;
|
||||
private $symbolMetadata;
|
||||
|
||||
public function setLines(array $lines) {
|
||||
$this->lines = $lines;
|
||||
@@ -39,6 +40,15 @@ final class PhabricatorSourceCodeView extends AphrontView {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setSymbolMetadata(array $symbol_metadata) {
|
||||
$this->symbolMetadata = $symbol_metadata;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSymbolMetadata() {
|
||||
return $this->symbolMetadata;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
require_celerity_resource('phabricator-source-code-view-css');
|
||||
require_celerity_resource('syntax-highlighting-css');
|
||||
@@ -130,15 +140,24 @@ final class PhabricatorSourceCodeView extends AphrontView {
|
||||
$classes[] = 'remarkup-code';
|
||||
$classes[] = 'PhabricatorMonospaced';
|
||||
|
||||
$symbol_metadata = $this->getSymbolMetadata();
|
||||
|
||||
$sigils = array();
|
||||
$sigils[] = 'phabricator-source';
|
||||
$sigils[] = 'has-symbols';
|
||||
|
||||
Javelin::initBehavior('repository-crossreference');
|
||||
|
||||
return phutil_tag_div(
|
||||
'phabricator-source-code-container',
|
||||
javelin_tag(
|
||||
'table',
|
||||
array(
|
||||
'class' => implode(' ', $classes),
|
||||
'sigil' => 'phabricator-source',
|
||||
'sigil' => implode(' ', $sigils),
|
||||
'meta' => array(
|
||||
'uri' => (string)$this->uri,
|
||||
'symbols' => $symbol_metadata,
|
||||
),
|
||||
),
|
||||
phutil_implode_html('', $rows)));
|
||||
|
||||
Reference in New Issue
Block a user