mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 05:12:41 +01:00
Add a simple symbol lookup interface for cross-references
Summary: This will get fancier, but here's a basic interface for doing symbol lookups. Still all pretty tentative. Test Plan: Looked up various things, got some sensible results. Reviewers: jungejason, nh, tuomaspelkonen, aran Reviewed By: tuomaspelkonen CC: aran, tuomaspelkonen Differential Revision: 900
This commit is contained in:
parent
77ed7ade66
commit
888af7309a
6 changed files with 241 additions and 0 deletions
|
@ -271,6 +271,8 @@ phutil_register_library_map(array(
|
|||
'DiffusionSvnHistoryQuery' => 'applications/diffusion/query/history/svn',
|
||||
'DiffusionSvnLastModifiedQuery' => 'applications/diffusion/query/lastmodified/svn',
|
||||
'DiffusionSvnRequest' => 'applications/diffusion/request/svn',
|
||||
'DiffusionSymbolController' => 'applications/diffusion/controller/symbol',
|
||||
'DiffusionSymbolQuery' => 'applications/diffusion/query/symbol',
|
||||
'DiffusionView' => 'applications/diffusion/view/base',
|
||||
'HeraldAction' => 'applications/herald/storage/action',
|
||||
'HeraldActionConfig' => 'applications/herald/config/action',
|
||||
|
@ -919,6 +921,7 @@ phutil_register_library_map(array(
|
|||
'DiffusionSvnHistoryQuery' => 'DiffusionHistoryQuery',
|
||||
'DiffusionSvnLastModifiedQuery' => 'DiffusionLastModifiedQuery',
|
||||
'DiffusionSvnRequest' => 'DiffusionRequest',
|
||||
'DiffusionSymbolController' => 'DiffusionController',
|
||||
'DiffusionView' => 'AphrontView',
|
||||
'HeraldAction' => 'HeraldDAO',
|
||||
'HeraldApplyTranscript' => 'HeraldDAO',
|
||||
|
|
|
@ -252,6 +252,7 @@ class AphrontDefaultApplicationConfiguration
|
|||
'$' => 'DiffusionCommitListController',
|
||||
'(?P<username>\w+)/$' => 'DiffusionCommitListController',
|
||||
),
|
||||
'symbol/(?P<name>[^/]+)/$' => 'DiffusionSymbolController',
|
||||
),
|
||||
|
||||
'/daemon/' => array(
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
class DiffusionSymbolController extends DiffusionController {
|
||||
|
||||
private $name;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->name = $data['name'];
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$query = new DiffusionSymbolQuery();
|
||||
$query->setNamePrefix($this->name);
|
||||
|
||||
if ($request->getStr('type')) {
|
||||
$query->setType($request->getStr('type'));
|
||||
}
|
||||
|
||||
if ($request->getStr('lang')) {
|
||||
$query->setLanguage($request->getStr('lang'));
|
||||
}
|
||||
|
||||
$symbols = $query->execute();
|
||||
|
||||
$rows = array();
|
||||
foreach ($symbols as $symbol) {
|
||||
$rows[] = array(
|
||||
phutil_escape_html($symbol->getSymbolType()),
|
||||
phutil_escape_html($symbol->getSymbolName()),
|
||||
phutil_escape_html($symbol->getSymbolLanguage()),
|
||||
);
|
||||
}
|
||||
|
||||
$table = new AphrontTableView($rows);
|
||||
$table->setHeaders(
|
||||
array(
|
||||
'Type',
|
||||
'Name',
|
||||
'Language',
|
||||
));
|
||||
$table->setColumnClasses(
|
||||
array(
|
||||
'',
|
||||
'pri',
|
||||
'',
|
||||
));
|
||||
|
||||
$panel = new AphrontPanelView();
|
||||
$panel->setHeader('Similar Symbols');
|
||||
$panel->appendChild($table);
|
||||
|
||||
return $this->buildStandardPageResponse(
|
||||
array(
|
||||
$panel,
|
||||
),
|
||||
array(
|
||||
'title' => 'Find Symbol',
|
||||
));
|
||||
}
|
||||
|
||||
}
|
17
src/applications/diffusion/controller/symbol/__init__.php
Normal file
17
src/applications/diffusion/controller/symbol/__init__.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/diffusion/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/diffusion/query/symbol');
|
||||
phutil_require_module('phabricator', 'view/control/table');
|
||||
phutil_require_module('phabricator', 'view/layout/panel');
|
||||
|
||||
phutil_require_module('phutil', 'markup');
|
||||
|
||||
|
||||
phutil_require_source('DiffusionSymbolController.php');
|
124
src/applications/diffusion/query/symbol/DiffusionSymbolQuery.php
Normal file
124
src/applications/diffusion/query/symbol/DiffusionSymbolQuery.php
Normal file
|
@ -0,0 +1,124 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
final class DiffusionSymbolQuery {
|
||||
|
||||
private $namePrefix;
|
||||
private $name;
|
||||
|
||||
private $projectIDs;
|
||||
private $language;
|
||||
private $type;
|
||||
|
||||
private $limit = 20;
|
||||
|
||||
public function setName($name) {
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setNamePrefix($name_prefix) {
|
||||
$this->namePrefix = $name_prefix;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setProjectIDs(array $project_ids) {
|
||||
$this->projectIDs = $project_ids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setLanguage($language) {
|
||||
$this->language = $language;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setType($type) {
|
||||
$this->type = $type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setLimit($limit) {
|
||||
$this->limit = $limit;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
if ($this->name && $this->namePrefix) {
|
||||
throw new Exception(
|
||||
"You can not set both a name and a name prefix!");
|
||||
} else if (!$this->name && !$this->namePrefix) {
|
||||
throw new Exception(
|
||||
"You must set a name or a name prefix!");
|
||||
}
|
||||
|
||||
$symbol = new PhabricatorRepositorySymbol();
|
||||
$conn_r = $symbol->establishConnection('r');
|
||||
|
||||
$where = array();
|
||||
if ($this->name) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'symbolName = %s',
|
||||
$this->name);
|
||||
}
|
||||
|
||||
if ($this->namePrefix) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'symbolName LIKE %>',
|
||||
$this->namePrefix);
|
||||
}
|
||||
|
||||
if ($this->projectIDs) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'arcanistProjectID IN (%Ld)',
|
||||
$this->projectIDs);
|
||||
}
|
||||
|
||||
$where = 'WHERE ('.implode(') AND (', $where).')';
|
||||
|
||||
$data = queryfx_all(
|
||||
$conn_r,
|
||||
'SELECT * FROM %T %Q',
|
||||
$symbol->getTableName(),
|
||||
$where);
|
||||
|
||||
// Our ability to match up symbol types and languages probably isn't all
|
||||
// that great, so use them as hints for ranking rather than hard
|
||||
// requirements. TODO: Is this really the right choice?
|
||||
foreach ($data as $key => $row) {
|
||||
$score = 0;
|
||||
if ($this->language && $row['symbolLanguage'] == $this->language) {
|
||||
$score += 2;
|
||||
}
|
||||
if ($this->type && $row['symbolType'] == $this->type) {
|
||||
$score += 1;
|
||||
}
|
||||
$data[$key]['score'] = $score;
|
||||
$data[$key]['id'] = $key;
|
||||
}
|
||||
|
||||
$data = isort($data, 'score');
|
||||
$data = array_reverse($data);
|
||||
|
||||
$data = array_slice($data, 0, $this->limit);
|
||||
|
||||
return $symbol->loadAllFromArray($data);
|
||||
}
|
||||
}
|
16
src/applications/diffusion/query/symbol/__init__.php
Normal file
16
src/applications/diffusion/query/symbol/__init__.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/repository/storage/symbol');
|
||||
phutil_require_module('phabricator', 'storage/qsprintf');
|
||||
phutil_require_module('phabricator', 'storage/queryfx');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('DiffusionSymbolQuery.php');
|
Loading…
Reference in a new issue