2011-09-05 19:43:24 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-03-10 00:46:25 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-09-05 19:43:24 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class DiffusionSymbolController extends DiffusionController {
|
2011-09-05 19:43:24 +02:00
|
|
|
|
|
|
|
private $name;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->name = $data['name'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$query = new DiffusionSymbolQuery();
|
Tie all the pieces for symbol cross-references together
Summary:
This makes symbol cross-references work in Differential. You need to do a little
legwork but I'll document that once the change has baked for a little while.
Basically:
- Projects are annotated with indexed languages, and "shared library" projects
(for example, symbols in Phabricator should be searched for in Arcanist and
libphutil).
- When we render a changeset, we check if its language is an indexed one. If
it is, we invoke the decorator Javascript.
- The Javascript takes you to a lookup page, which either gives you a list of
matching symbols (if several match) or redirects you instantly to the
definition.
Test Plan: Clicked class and function symbols in a diff, got jumped into
sensible sorts of places in Diffusion.
Reviewers: jungejason, nh, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason
Differential Revision: 980
2011-10-03 01:02:56 +02:00
|
|
|
$query->setName($this->name);
|
2011-09-05 19:43:24 +02:00
|
|
|
|
|
|
|
if ($request->getStr('type')) {
|
|
|
|
$query->setType($request->getStr('type'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->getStr('lang')) {
|
|
|
|
$query->setLanguage($request->getStr('lang'));
|
|
|
|
}
|
|
|
|
|
Tie all the pieces for symbol cross-references together
Summary:
This makes symbol cross-references work in Differential. You need to do a little
legwork but I'll document that once the change has baked for a little while.
Basically:
- Projects are annotated with indexed languages, and "shared library" projects
(for example, symbols in Phabricator should be searched for in Arcanist and
libphutil).
- When we render a changeset, we check if its language is an indexed one. If
it is, we invoke the decorator Javascript.
- The Javascript takes you to a lookup page, which either gives you a list of
matching symbols (if several match) or redirects you instantly to the
definition.
Test Plan: Clicked class and function symbols in a diff, got jumped into
sensible sorts of places in Diffusion.
Reviewers: jungejason, nh, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason
Differential Revision: 980
2011-10-03 01:02:56 +02:00
|
|
|
if ($request->getStr('projects')) {
|
|
|
|
$phids = $request->getStr('projects');
|
|
|
|
$phids = explode(',', $phids);
|
|
|
|
$phids = array_filter($phids);
|
|
|
|
|
|
|
|
if ($phids) {
|
|
|
|
$projects = id(new PhabricatorRepositoryArcanistProject())
|
|
|
|
->loadAllWhere(
|
|
|
|
'phid IN (%Ls)',
|
|
|
|
$phids);
|
|
|
|
$projects = mpull($projects, 'getID');
|
|
|
|
if ($projects) {
|
|
|
|
$query->setProjectIDs($projects);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-21 18:39:33 +01:00
|
|
|
$query->needPaths(true);
|
|
|
|
$query->needArcanistProjects(true);
|
|
|
|
$query->needRepositories(true);
|
|
|
|
|
2011-09-05 19:43:24 +02:00
|
|
|
$symbols = $query->execute();
|
|
|
|
|
Tie all the pieces for symbol cross-references together
Summary:
This makes symbol cross-references work in Differential. You need to do a little
legwork but I'll document that once the change has baked for a little while.
Basically:
- Projects are annotated with indexed languages, and "shared library" projects
(for example, symbols in Phabricator should be searched for in Arcanist and
libphutil).
- When we render a changeset, we check if its language is an indexed one. If
it is, we invoke the decorator Javascript.
- The Javascript takes you to a lookup page, which either gives you a list of
matching symbols (if several match) or redirects you instantly to the
definition.
Test Plan: Clicked class and function symbols in a diff, got jumped into
sensible sorts of places in Diffusion.
Reviewers: jungejason, nh, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason
Differential Revision: 980
2011-10-03 01:02:56 +02:00
|
|
|
// For PHP builtins, jump to php.net documentation.
|
|
|
|
if ($request->getBool('jump') && count($symbols) == 0) {
|
|
|
|
if ($request->getStr('lang') == 'php') {
|
2012-03-21 20:18:05 +01:00
|
|
|
switch ($request->getStr('type')) {
|
|
|
|
case 'function':
|
|
|
|
$functions = get_defined_functions();
|
|
|
|
if (in_array($this->name, $functions['internal'])) {
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI('http://www.php.net/function.'.$this->name);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'class':
|
|
|
|
if (class_exists($this->name) ||
|
|
|
|
in_array($this->name, get_declared_interfaces())) {
|
|
|
|
if (id(new ReflectionClass($this->name))->isInternal()) {
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI('http://www.php.net/class.'.$this->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
Tie all the pieces for symbol cross-references together
Summary:
This makes symbol cross-references work in Differential. You need to do a little
legwork but I'll document that once the change has baked for a little while.
Basically:
- Projects are annotated with indexed languages, and "shared library" projects
(for example, symbols in Phabricator should be searched for in Arcanist and
libphutil).
- When we render a changeset, we check if its language is an indexed one. If
it is, we invoke the decorator Javascript.
- The Javascript takes you to a lookup page, which either gives you a list of
matching symbols (if several match) or redirects you instantly to the
definition.
Test Plan: Clicked class and function symbols in a diff, got jumped into
sensible sorts of places in Diffusion.
Reviewers: jungejason, nh, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason
Differential Revision: 980
2011-10-03 01:02:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-05 19:43:24 +02:00
|
|
|
$rows = array();
|
|
|
|
foreach ($symbols as $symbol) {
|
2011-12-21 18:39:33 +01:00
|
|
|
$project = $symbol->getArcanistProject();
|
Tie all the pieces for symbol cross-references together
Summary:
This makes symbol cross-references work in Differential. You need to do a little
legwork but I'll document that once the change has baked for a little while.
Basically:
- Projects are annotated with indexed languages, and "shared library" projects
(for example, symbols in Phabricator should be searched for in Arcanist and
libphutil).
- When we render a changeset, we check if its language is an indexed one. If
it is, we invoke the decorator Javascript.
- The Javascript takes you to a lookup page, which either gives you a list of
matching symbols (if several match) or redirects you instantly to the
definition.
Test Plan: Clicked class and function symbols in a diff, got jumped into
sensible sorts of places in Diffusion.
Reviewers: jungejason, nh, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason
Differential Revision: 980
2011-10-03 01:02:56 +02:00
|
|
|
if ($project) {
|
|
|
|
$project_name = $project->getName();
|
|
|
|
} else {
|
|
|
|
$project_name = '-';
|
|
|
|
}
|
|
|
|
|
2011-12-21 18:39:33 +01:00
|
|
|
$file = phutil_escape_html($symbol->getPath());
|
Tie all the pieces for symbol cross-references together
Summary:
This makes symbol cross-references work in Differential. You need to do a little
legwork but I'll document that once the change has baked for a little while.
Basically:
- Projects are annotated with indexed languages, and "shared library" projects
(for example, symbols in Phabricator should be searched for in Arcanist and
libphutil).
- When we render a changeset, we check if its language is an indexed one. If
it is, we invoke the decorator Javascript.
- The Javascript takes you to a lookup page, which either gives you a list of
matching symbols (if several match) or redirects you instantly to the
definition.
Test Plan: Clicked class and function symbols in a diff, got jumped into
sensible sorts of places in Diffusion.
Reviewers: jungejason, nh, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason
Differential Revision: 980
2011-10-03 01:02:56 +02:00
|
|
|
$line = phutil_escape_html($symbol->getLineNumber());
|
|
|
|
|
2011-12-21 18:39:33 +01:00
|
|
|
$repo = $symbol->getRepository();
|
Tie all the pieces for symbol cross-references together
Summary:
This makes symbol cross-references work in Differential. You need to do a little
legwork but I'll document that once the change has baked for a little while.
Basically:
- Projects are annotated with indexed languages, and "shared library" projects
(for example, symbols in Phabricator should be searched for in Arcanist and
libphutil).
- When we render a changeset, we check if its language is an indexed one. If
it is, we invoke the decorator Javascript.
- The Javascript takes you to a lookup page, which either gives you a list of
matching symbols (if several match) or redirects you instantly to the
definition.
Test Plan: Clicked class and function symbols in a diff, got jumped into
sensible sorts of places in Diffusion.
Reviewers: jungejason, nh, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason
Differential Revision: 980
2011-10-03 01:02:56 +02:00
|
|
|
if ($repo) {
|
2011-12-21 18:39:33 +01:00
|
|
|
$href = $symbol->getURI();
|
Tie all the pieces for symbol cross-references together
Summary:
This makes symbol cross-references work in Differential. You need to do a little
legwork but I'll document that once the change has baked for a little while.
Basically:
- Projects are annotated with indexed languages, and "shared library" projects
(for example, symbols in Phabricator should be searched for in Arcanist and
libphutil).
- When we render a changeset, we check if its language is an indexed one. If
it is, we invoke the decorator Javascript.
- The Javascript takes you to a lookup page, which either gives you a list of
matching symbols (if several match) or redirects you instantly to the
definition.
Test Plan: Clicked class and function symbols in a diff, got jumped into
sensible sorts of places in Diffusion.
Reviewers: jungejason, nh, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason
Differential Revision: 980
2011-10-03 01:02:56 +02:00
|
|
|
|
|
|
|
if ($request->getBool('jump') && count($symbols) == 1) {
|
|
|
|
// If this is a clickthrough from Differential, just jump them
|
|
|
|
// straight to the target if we got a single hit.
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($href);
|
|
|
|
}
|
|
|
|
|
|
|
|
$location = phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $href,
|
|
|
|
),
|
|
|
|
phutil_escape_html($file.':'.$line));
|
|
|
|
} else if ($file) {
|
|
|
|
$location = phutil_escape_html($file.':'.$line);
|
|
|
|
} else {
|
|
|
|
$location = '?';
|
|
|
|
}
|
|
|
|
|
2011-09-05 19:43:24 +02:00
|
|
|
$rows[] = array(
|
|
|
|
phutil_escape_html($symbol->getSymbolType()),
|
|
|
|
phutil_escape_html($symbol->getSymbolName()),
|
|
|
|
phutil_escape_html($symbol->getSymbolLanguage()),
|
Tie all the pieces for symbol cross-references together
Summary:
This makes symbol cross-references work in Differential. You need to do a little
legwork but I'll document that once the change has baked for a little while.
Basically:
- Projects are annotated with indexed languages, and "shared library" projects
(for example, symbols in Phabricator should be searched for in Arcanist and
libphutil).
- When we render a changeset, we check if its language is an indexed one. If
it is, we invoke the decorator Javascript.
- The Javascript takes you to a lookup page, which either gives you a list of
matching symbols (if several match) or redirects you instantly to the
definition.
Test Plan: Clicked class and function symbols in a diff, got jumped into
sensible sorts of places in Diffusion.
Reviewers: jungejason, nh, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason
Differential Revision: 980
2011-10-03 01:02:56 +02:00
|
|
|
phutil_escape_html($project_name),
|
|
|
|
$location,
|
2011-09-05 19:43:24 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$table = new AphrontTableView($rows);
|
|
|
|
$table->setHeaders(
|
|
|
|
array(
|
|
|
|
'Type',
|
|
|
|
'Name',
|
|
|
|
'Language',
|
Tie all the pieces for symbol cross-references together
Summary:
This makes symbol cross-references work in Differential. You need to do a little
legwork but I'll document that once the change has baked for a little while.
Basically:
- Projects are annotated with indexed languages, and "shared library" projects
(for example, symbols in Phabricator should be searched for in Arcanist and
libphutil).
- When we render a changeset, we check if its language is an indexed one. If
it is, we invoke the decorator Javascript.
- The Javascript takes you to a lookup page, which either gives you a list of
matching symbols (if several match) or redirects you instantly to the
definition.
Test Plan: Clicked class and function symbols in a diff, got jumped into
sensible sorts of places in Diffusion.
Reviewers: jungejason, nh, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason
Differential Revision: 980
2011-10-03 01:02:56 +02:00
|
|
|
'Project',
|
|
|
|
'File',
|
2011-09-05 19:43:24 +02:00
|
|
|
));
|
|
|
|
$table->setColumnClasses(
|
|
|
|
array(
|
|
|
|
'',
|
|
|
|
'pri',
|
|
|
|
'',
|
Tie all the pieces for symbol cross-references together
Summary:
This makes symbol cross-references work in Differential. You need to do a little
legwork but I'll document that once the change has baked for a little while.
Basically:
- Projects are annotated with indexed languages, and "shared library" projects
(for example, symbols in Phabricator should be searched for in Arcanist and
libphutil).
- When we render a changeset, we check if its language is an indexed one. If
it is, we invoke the decorator Javascript.
- The Javascript takes you to a lookup page, which either gives you a list of
matching symbols (if several match) or redirects you instantly to the
definition.
Test Plan: Clicked class and function symbols in a diff, got jumped into
sensible sorts of places in Diffusion.
Reviewers: jungejason, nh, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason
Differential Revision: 980
2011-10-03 01:02:56 +02:00
|
|
|
'',
|
|
|
|
'',
|
2011-09-05 19:43:24 +02:00
|
|
|
));
|
Tie all the pieces for symbol cross-references together
Summary:
This makes symbol cross-references work in Differential. You need to do a little
legwork but I'll document that once the change has baked for a little while.
Basically:
- Projects are annotated with indexed languages, and "shared library" projects
(for example, symbols in Phabricator should be searched for in Arcanist and
libphutil).
- When we render a changeset, we check if its language is an indexed one. If
it is, we invoke the decorator Javascript.
- The Javascript takes you to a lookup page, which either gives you a list of
matching symbols (if several match) or redirects you instantly to the
definition.
Test Plan: Clicked class and function symbols in a diff, got jumped into
sensible sorts of places in Diffusion.
Reviewers: jungejason, nh, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, jungejason
Differential Revision: 980
2011-10-03 01:02:56 +02:00
|
|
|
$table->setNoDataString(
|
|
|
|
"No matching symbol could be found in any indexed project.");
|
2011-09-05 19:43:24 +02:00
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel->setHeader('Similar Symbols');
|
|
|
|
$panel->appendChild($table);
|
|
|
|
|
|
|
|
return $this->buildStandardPageResponse(
|
|
|
|
array(
|
|
|
|
$panel,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => 'Find Symbol',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|