@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

When available, pass path, line and repository hints to external symbol queries

Summary:
Depends on D18936. Ref T13047. Third parties can define external symbol sources that let users jump to PHP or Python documentation or query some server.

Give these queries more information so they can try to get better results: the path and line where the symbol appeared, and any known repository scope.

Test Plan: Wrote a fake external source that used this data, command-clicked a symbol in Differential, saw a fake external symbol result.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13047

Differential Revision: https://secure.phabricator.com/D18937

+74 -5
+36 -5
src/applications/diffusion/controller/DiffusionSymbolController.php
··· 22 22 $query->setLanguage($request->getStr('lang')); 23 23 } 24 24 25 + $repos = array(); 25 26 if ($request->getStr('repositories')) { 26 27 $phids = $request->getStr('repositories'); 27 28 $phids = explode(',', $phids); ··· 33 34 ->withPHIDs($phids) 34 35 ->execute(); 35 36 36 - $repos = mpull($repos, 'getPHID'); 37 - if ($repos) { 38 - $query->withRepositoryPHIDs($repos); 37 + $repo_phids = mpull($repos, 'getPHID'); 38 + if ($repo_phids) { 39 + $query->withRepositoryPHIDs($repo_phids); 39 40 } 40 41 } 41 42 } ··· 44 45 $query->needRepositories(true); 45 46 46 47 $symbols = $query->execute(); 47 - 48 48 49 49 $external_query = id(new DiffusionExternalSymbolQuery()) 50 50 ->withNames(array($name)); ··· 61 61 $external_query->withLanguages(array($request->getStr('lang'))); 62 62 } 63 63 64 + if ($request->getStr('path')) { 65 + $external_query->withPaths(array($request->getStr('path'))); 66 + } 67 + 68 + if ($request->getInt('line')) { 69 + $external_query->withLines(array($request->getInt('line'))); 70 + } 71 + 72 + if ($repos) { 73 + $external_query->withRepositories($repos); 74 + } 75 + 64 76 $external_sources = id(new PhutilClassMapQuery()) 65 77 ->setAncestorClass('DiffusionExternalSymbolsSource') 66 78 ->execute(); 67 79 68 80 $results = array($symbols); 69 81 foreach ($external_sources as $source) { 70 - $results[] = $source->executeQuery($external_query); 82 + $source_results = $source->executeQuery($external_query); 83 + 84 + if (!is_array($source_results)) { 85 + throw new Exception( 86 + pht( 87 + 'Expected a list of results from external symbol source "%s".', 88 + get_class($source))); 89 + } 90 + 91 + try { 92 + assert_instances_of($source_results, 'PhabricatorRepositorySymbol'); 93 + } catch (InvalidArgumentException $ex) { 94 + throw new Exception( 95 + pht( 96 + 'Expected a list of PhabricatorRepositorySymbol objects '. 97 + 'from external symbol source "%s".', 98 + get_class($source))); 99 + } 100 + 101 + $results[] = $source_results; 71 102 } 72 103 $symbols = array_mergev($results); 73 104
+38
src/applications/diffusion/symbol/DiffusionExternalSymbolQuery.php
··· 1 1 <?php 2 2 3 3 final class DiffusionExternalSymbolQuery extends Phobject { 4 + 4 5 private $languages = array(); 5 6 private $types = array(); 6 7 private $names = array(); 7 8 private $contexts = array(); 9 + private $paths = array(); 10 + private $lines = array(); 11 + private $repositories = array(); 8 12 9 13 public function withLanguages(array $languages) { 10 14 $this->languages = $languages; 11 15 return $this; 12 16 } 17 + 13 18 public function withTypes(array $types) { 14 19 $this->types = $types; 15 20 return $this; 16 21 } 22 + 17 23 public function withNames(array $names) { 18 24 $this->names = $names; 19 25 return $this; 20 26 } 27 + 21 28 public function withContexts(array $contexts) { 22 29 $this->contexts = $contexts; 23 30 return $this; 24 31 } 25 32 33 + public function withPaths(array $paths) { 34 + $this->paths = $paths; 35 + return $this; 36 + } 37 + 38 + public function withLines(array $lines) { 39 + $this->lines = $lines; 40 + return $this; 41 + } 42 + 43 + public function withRepositories(array $repositories) { 44 + assert_instances_of($repositories, 'PhabricatorRepository'); 45 + $this->repositories = $repositories; 46 + return $this; 47 + } 26 48 27 49 public function getLanguages() { 28 50 return $this->languages; 29 51 } 52 + 30 53 public function getTypes() { 31 54 return $this->types; 32 55 } 56 + 33 57 public function getNames() { 34 58 return $this->names; 35 59 } 60 + 36 61 public function getContexts() { 37 62 return $this->contexts; 38 63 } 39 64 65 + public function getPaths() { 66 + return $this->paths; 67 + } 68 + 69 + public function getLines() { 70 + return $this->lines; 71 + } 72 + 73 + public function getRepositories() { 74 + return $this->repositories; 75 + } 76 + 40 77 public function matchesAnyLanguage(array $languages) { 41 78 return (!$this->languages) || array_intersect($languages, $this->languages); 42 79 } 80 + 43 81 public function matchesAnyType(array $types) { 44 82 return (!$this->types) || array_intersect($types, $this->types); 45 83 }