Skip to content

Commit 888af73

Browse files
author
epriestley
committed
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
1 parent 77ed7ad commit 888af73

File tree

6 files changed

+241
-0
lines changed

6 files changed

+241
-0
lines changed

src/__phutil_library_map__.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@
271271
'DiffusionSvnHistoryQuery' => 'applications/diffusion/query/history/svn',
272272
'DiffusionSvnLastModifiedQuery' => 'applications/diffusion/query/lastmodified/svn',
273273
'DiffusionSvnRequest' => 'applications/diffusion/request/svn',
274+
'DiffusionSymbolController' => 'applications/diffusion/controller/symbol',
275+
'DiffusionSymbolQuery' => 'applications/diffusion/query/symbol',
274276
'DiffusionView' => 'applications/diffusion/view/base',
275277
'HeraldAction' => 'applications/herald/storage/action',
276278
'HeraldActionConfig' => 'applications/herald/config/action',
@@ -919,6 +921,7 @@
919921
'DiffusionSvnHistoryQuery' => 'DiffusionHistoryQuery',
920922
'DiffusionSvnLastModifiedQuery' => 'DiffusionLastModifiedQuery',
921923
'DiffusionSvnRequest' => 'DiffusionRequest',
924+
'DiffusionSymbolController' => 'DiffusionController',
922925
'DiffusionView' => 'AphrontView',
923926
'HeraldAction' => 'HeraldDAO',
924927
'HeraldApplyTranscript' => 'HeraldDAO',

src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ public function getURIMap() {
252252
'$' => 'DiffusionCommitListController',
253253
'(?P<username>\w+)/$' => 'DiffusionCommitListController',
254254
),
255+
'symbol/(?P<name>[^/]+)/$' => 'DiffusionSymbolController',
255256
),
256257

257258
'/daemon/' => array(
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2011 Facebook, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
class DiffusionSymbolController extends DiffusionController {
20+
21+
private $name;
22+
23+
public function willProcessRequest(array $data) {
24+
$this->name = $data['name'];
25+
}
26+
27+
public function processRequest() {
28+
$request = $this->getRequest();
29+
$user = $request->getUser();
30+
31+
$query = new DiffusionSymbolQuery();
32+
$query->setNamePrefix($this->name);
33+
34+
if ($request->getStr('type')) {
35+
$query->setType($request->getStr('type'));
36+
}
37+
38+
if ($request->getStr('lang')) {
39+
$query->setLanguage($request->getStr('lang'));
40+
}
41+
42+
$symbols = $query->execute();
43+
44+
$rows = array();
45+
foreach ($symbols as $symbol) {
46+
$rows[] = array(
47+
phutil_escape_html($symbol->getSymbolType()),
48+
phutil_escape_html($symbol->getSymbolName()),
49+
phutil_escape_html($symbol->getSymbolLanguage()),
50+
);
51+
}
52+
53+
$table = new AphrontTableView($rows);
54+
$table->setHeaders(
55+
array(
56+
'Type',
57+
'Name',
58+
'Language',
59+
));
60+
$table->setColumnClasses(
61+
array(
62+
'',
63+
'pri',
64+
'',
65+
));
66+
67+
$panel = new AphrontPanelView();
68+
$panel->setHeader('Similar Symbols');
69+
$panel->appendChild($table);
70+
71+
return $this->buildStandardPageResponse(
72+
array(
73+
$panel,
74+
),
75+
array(
76+
'title' => 'Find Symbol',
77+
));
78+
}
79+
80+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* This file is automatically generated. Lint this module to rebuild it.
4+
* @generated
5+
*/
6+
7+
8+
9+
phutil_require_module('phabricator', 'applications/diffusion/controller/base');
10+
phutil_require_module('phabricator', 'applications/diffusion/query/symbol');
11+
phutil_require_module('phabricator', 'view/control/table');
12+
phutil_require_module('phabricator', 'view/layout/panel');
13+
14+
phutil_require_module('phutil', 'markup');
15+
16+
17+
phutil_require_source('DiffusionSymbolController.php');
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2011 Facebook, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
final class DiffusionSymbolQuery {
20+
21+
private $namePrefix;
22+
private $name;
23+
24+
private $projectIDs;
25+
private $language;
26+
private $type;
27+
28+
private $limit = 20;
29+
30+
public function setName($name) {
31+
$this->name = $name;
32+
return $this;
33+
}
34+
35+
public function setNamePrefix($name_prefix) {
36+
$this->namePrefix = $name_prefix;
37+
return $this;
38+
}
39+
40+
public function setProjectIDs(array $project_ids) {
41+
$this->projectIDs = $project_ids;
42+
return $this;
43+
}
44+
45+
public function setLanguage($language) {
46+
$this->language = $language;
47+
return $this;
48+
}
49+
50+
public function setType($type) {
51+
$this->type = $type;
52+
return $this;
53+
}
54+
55+
public function setLimit($limit) {
56+
$this->limit = $limit;
57+
return $this;
58+
}
59+
60+
public function execute() {
61+
if ($this->name && $this->namePrefix) {
62+
throw new Exception(
63+
"You can not set both a name and a name prefix!");
64+
} else if (!$this->name && !$this->namePrefix) {
65+
throw new Exception(
66+
"You must set a name or a name prefix!");
67+
}
68+
69+
$symbol = new PhabricatorRepositorySymbol();
70+
$conn_r = $symbol->establishConnection('r');
71+
72+
$where = array();
73+
if ($this->name) {
74+
$where[] = qsprintf(
75+
$conn_r,
76+
'symbolName = %s',
77+
$this->name);
78+
}
79+
80+
if ($this->namePrefix) {
81+
$where[] = qsprintf(
82+
$conn_r,
83+
'symbolName LIKE %>',
84+
$this->namePrefix);
85+
}
86+
87+
if ($this->projectIDs) {
88+
$where[] = qsprintf(
89+
$conn_r,
90+
'arcanistProjectID IN (%Ld)',
91+
$this->projectIDs);
92+
}
93+
94+
$where = 'WHERE ('.implode(') AND (', $where).')';
95+
96+
$data = queryfx_all(
97+
$conn_r,
98+
'SELECT * FROM %T %Q',
99+
$symbol->getTableName(),
100+
$where);
101+
102+
// Our ability to match up symbol types and languages probably isn't all
103+
// that great, so use them as hints for ranking rather than hard
104+
// requirements. TODO: Is this really the right choice?
105+
foreach ($data as $key => $row) {
106+
$score = 0;
107+
if ($this->language && $row['symbolLanguage'] == $this->language) {
108+
$score += 2;
109+
}
110+
if ($this->type && $row['symbolType'] == $this->type) {
111+
$score += 1;
112+
}
113+
$data[$key]['score'] = $score;
114+
$data[$key]['id'] = $key;
115+
}
116+
117+
$data = isort($data, 'score');
118+
$data = array_reverse($data);
119+
120+
$data = array_slice($data, 0, $this->limit);
121+
122+
return $symbol->loadAllFromArray($data);
123+
}
124+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* This file is automatically generated. Lint this module to rebuild it.
4+
* @generated
5+
*/
6+
7+
8+
9+
phutil_require_module('phabricator', 'applications/repository/storage/symbol');
10+
phutil_require_module('phabricator', 'storage/qsprintf');
11+
phutil_require_module('phabricator', 'storage/queryfx');
12+
13+
phutil_require_module('phutil', 'utils');
14+
15+
16+
phutil_require_source('DiffusionSymbolQuery.php');

0 commit comments

Comments
 (0)