1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 18:22:41 +01:00

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
This commit is contained in:
epriestley 2018-01-25 19:16:22 -08:00
parent c37b6c6633
commit d606eb1c38
2 changed files with 74 additions and 5 deletions

View file

@ -22,6 +22,7 @@ final class DiffusionSymbolController extends DiffusionController {
$query->setLanguage($request->getStr('lang')); $query->setLanguage($request->getStr('lang'));
} }
$repos = array();
if ($request->getStr('repositories')) { if ($request->getStr('repositories')) {
$phids = $request->getStr('repositories'); $phids = $request->getStr('repositories');
$phids = explode(',', $phids); $phids = explode(',', $phids);
@ -33,9 +34,9 @@ final class DiffusionSymbolController extends DiffusionController {
->withPHIDs($phids) ->withPHIDs($phids)
->execute(); ->execute();
$repos = mpull($repos, 'getPHID'); $repo_phids = mpull($repos, 'getPHID');
if ($repos) { if ($repo_phids) {
$query->withRepositoryPHIDs($repos); $query->withRepositoryPHIDs($repo_phids);
} }
} }
} }
@ -45,7 +46,6 @@ final class DiffusionSymbolController extends DiffusionController {
$symbols = $query->execute(); $symbols = $query->execute();
$external_query = id(new DiffusionExternalSymbolQuery()) $external_query = id(new DiffusionExternalSymbolQuery())
->withNames(array($name)); ->withNames(array($name));
@ -61,13 +61,44 @@ final class DiffusionSymbolController extends DiffusionController {
$external_query->withLanguages(array($request->getStr('lang'))); $external_query->withLanguages(array($request->getStr('lang')));
} }
if ($request->getStr('path')) {
$external_query->withPaths(array($request->getStr('path')));
}
if ($request->getInt('line')) {
$external_query->withLines(array($request->getInt('line')));
}
if ($repos) {
$external_query->withRepositories($repos);
}
$external_sources = id(new PhutilClassMapQuery()) $external_sources = id(new PhutilClassMapQuery())
->setAncestorClass('DiffusionExternalSymbolsSource') ->setAncestorClass('DiffusionExternalSymbolsSource')
->execute(); ->execute();
$results = array($symbols); $results = array($symbols);
foreach ($external_sources as $source) { foreach ($external_sources as $source) {
$results[] = $source->executeQuery($external_query); $source_results = $source->executeQuery($external_query);
if (!is_array($source_results)) {
throw new Exception(
pht(
'Expected a list of results from external symbol source "%s".',
get_class($source)));
}
try {
assert_instances_of($source_results, 'PhabricatorRepositorySymbol');
} catch (InvalidArgumentException $ex) {
throw new Exception(
pht(
'Expected a list of PhabricatorRepositorySymbol objects '.
'from external symbol source "%s".',
get_class($source)));
}
$results[] = $source_results;
} }
$symbols = array_mergev($results); $symbols = array_mergev($results);

View file

@ -1,45 +1,83 @@
<?php <?php
final class DiffusionExternalSymbolQuery extends Phobject { final class DiffusionExternalSymbolQuery extends Phobject {
private $languages = array(); private $languages = array();
private $types = array(); private $types = array();
private $names = array(); private $names = array();
private $contexts = array(); private $contexts = array();
private $paths = array();
private $lines = array();
private $repositories = array();
public function withLanguages(array $languages) { public function withLanguages(array $languages) {
$this->languages = $languages; $this->languages = $languages;
return $this; return $this;
} }
public function withTypes(array $types) { public function withTypes(array $types) {
$this->types = $types; $this->types = $types;
return $this; return $this;
} }
public function withNames(array $names) { public function withNames(array $names) {
$this->names = $names; $this->names = $names;
return $this; return $this;
} }
public function withContexts(array $contexts) { public function withContexts(array $contexts) {
$this->contexts = $contexts; $this->contexts = $contexts;
return $this; return $this;
} }
public function withPaths(array $paths) {
$this->paths = $paths;
return $this;
}
public function withLines(array $lines) {
$this->lines = $lines;
return $this;
}
public function withRepositories(array $repositories) {
assert_instances_of($repositories, 'PhabricatorRepository');
$this->repositories = $repositories;
return $this;
}
public function getLanguages() { public function getLanguages() {
return $this->languages; return $this->languages;
} }
public function getTypes() { public function getTypes() {
return $this->types; return $this->types;
} }
public function getNames() { public function getNames() {
return $this->names; return $this->names;
} }
public function getContexts() { public function getContexts() {
return $this->contexts; return $this->contexts;
} }
public function getPaths() {
return $this->paths;
}
public function getLines() {
return $this->lines;
}
public function getRepositories() {
return $this->repositories;
}
public function matchesAnyLanguage(array $languages) { public function matchesAnyLanguage(array $languages) {
return (!$this->languages) || array_intersect($languages, $this->languages); return (!$this->languages) || array_intersect($languages, $this->languages);
} }
public function matchesAnyType(array $types) { public function matchesAnyType(array $types) {
return (!$this->types) || array_intersect($types, $this->types); return (!$this->types) || array_intersect($types, $this->types);
} }