Skip to content

Commit a8d6af0

Browse files
author
Alan Huang
committedAug 7, 2012
Infrastructure changes to support scoped symbols
Summary: - import_project_symbols supports an optional extra field, which is the context of the symbol. - Symbol query can take a symbol argument, either as a parameter or a URL component (so you can now jump nav to `s Zerg/rush`, for example). - Conduit method not yet updated. Will do that later. NOTE: Not providing a context is distinct from providing an empty context, because an empty context stands for top-level context, i.e. functions and classes for PHP. It will not find class methods, etc. It is possible that we should use some weird token that could not normally be a context name to stand in for empty context. Test Plan: Do a bunch of symbol searches. Reviewers: epriestley Reviewed By: epriestley CC: nh, aran, Korvin Maniphest Tasks: T1602 Differential Revision: https://secure.phabricator.com/D3148
1 parent 1c98ca7 commit a8d6af0

File tree

3 files changed

+51
-35
lines changed

3 files changed

+51
-35
lines changed
 

‎scripts/symbols/import_project_symbols.php

+27-35
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,12 @@
3030
$args->parseStandardArguments();
3131
$args->parse(
3232
array(
33-
array(
34-
'name' => 'ignore-duplicates',
35-
'help' => 'Ignore duplicate symbols, choosing one at random. By '.
36-
'default, this script throws if given duplicate '.
37-
'symbols.',
38-
),
3933
array(
4034
'name' => 'more',
4135
'wildcard' => true,
4236
),
4337
));
4438

45-
$ignore_duplicates = $args->getArg('ignore-duplicates');
4639
$more = $args->getArg('more');
4740
if (count($more) !== 1) {
4841
$args->printHelpAndExit();
@@ -66,42 +59,39 @@
6659
$input = trim($input);
6760
$input = explode("\n", $input);
6861

69-
$map = array();
7062
$symbols = array();
7163
foreach ($input as $key => $line) {
7264
$line_no = $key + 1;
7365
$matches = null;
74-
$ok = preg_match('/^([^ ]+) ([^ ]+) ([^ ]+) (\d+) (.*)$/', $line, $matches);
66+
$ok = preg_match(
67+
'/^((?P<context>[^ ]+)? )?(?P<name>[^ ]+) (?P<type>[^ ]+) '.
68+
'(?P<lang>[^ ]+) (?P<line>\d+) (?P<path>.*)$/',
69+
$line,
70+
$matches);
7571
if (!$ok) {
7672
throw new Exception(
77-
"Line #{$line_no} of input is invalid. Expected five space-delimited ".
78-
"fields: symbol name, symbol type, symbol language, line number, path. ".
73+
"Line #{$line_no} of input is invalid. Expected five or six ".
74+
"space-delimited fields: maybe symbol context, symbol name, symbol ".
75+
"type, symbol language, line number, path. ".
7976
"For example:\n\n".
8077
"idx function php 13 /path/to/some/file.php\n\n".
8178
"Actual line was:\n\n".
8279
"{$line}");
8380
}
84-
list($all, $name, $type, $lang, $line_number, $path) = $matches;
85-
86-
if (isset($map[$name][$type][$lang])) {
87-
if ($ignore_duplicates) {
88-
echo "Ignoring duplicate definition of '{$name}' on line {$line_no}.\n";
89-
} else {
90-
$previous = $map[$name][$type][$lang] + 1;
91-
throw new Exception(
92-
"Line #{$line_no} of input is invalid. It specifies a duplicate ".
93-
"symbol (same name, language, and type) which has already been ".
94-
"defined elsewhere. You must preprocess the symbol list to remove ".
95-
"duplicates and choose exactly one master definition for each ".
96-
"symbol, or specify --ignore-duplicates. This symbol was previously ".
97-
"defined on line #{$previous}.\n\n".
98-
"Line #{$line_no}:\n".
99-
$line."\n\n".
100-
"Line #{$previous}:\n".
101-
$input[$previous - 1]);
102-
}
103-
} else {
104-
$map[$name][$type][$lang] = $key;
81+
if (empty($matches['context'])) {
82+
$matches['context'] = '';
83+
}
84+
$context = $matches['context'];
85+
$name = $matches['name'];
86+
$type = $matches['type'];
87+
$lang = $matches['lang'];
88+
$line_number = $matches['line'];
89+
$path = $matches['path'];
90+
91+
if (strlen($context) > 128) {
92+
throw new Exception(
93+
"Symbol context '{$context}' defined on line #{$line_no} is too long, ".
94+
"maximum symbol context length is 128 characters.");
10595
}
10696

10797
if (strlen($name) > 128) {
@@ -130,6 +120,7 @@
130120
}
131121

132122
$symbols[] = array(
123+
'ctxt' => $context,
133124
'name' => $name,
134125
'type' => $type,
135126
'lang' => $lang,
@@ -150,8 +141,9 @@
150141
foreach ($symbols as $dict) {
151142
$sql[] = qsprintf(
152143
$conn_w,
153-
'(%d, %s, %s, %s, %d, %d)',
144+
'(%d, %s, %s, %s, %s, %d, %d)',
154145
$project->getID(),
146+
$dict['ctxt'],
155147
$dict['name'],
156148
$dict['type'],
157149
$dict['lang'],
@@ -171,8 +163,8 @@
171163
queryfx(
172164
$conn_w,
173165
'INSERT INTO %T
174-
(arcanistProjectID, symbolName, symbolType, symbolLanguage, lineNumber,
175-
pathID) VALUES %Q',
166+
(arcanistProjectID, symbolContext, symbolName, symbolType,
167+
symbolLanguage, lineNumber, pathID) VALUES %Q',
176168
$symbol->getTableName(),
177169
implode(', ', $chunk));
178170
}

‎src/applications/diffusion/controller/DiffusionSymbolController.php

+7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public function processRequest() {
3131
$query = new DiffusionSymbolQuery();
3232
$query->setName($this->name);
3333

34+
if ($request->getStr('context') !== null) {
35+
$query->setContext($request->getStr('context'));
36+
}
37+
3438
if ($request->getStr('type')) {
3539
$query->setType($request->getStr('type'));
3640
}
@@ -122,6 +126,7 @@ interface_exists($this->name, false)) {
122126

123127
$rows[] = array(
124128
phutil_escape_html($symbol->getSymbolType()),
129+
phutil_escape_html($symbol->getSymbolContext()),
125130
phutil_escape_html($symbol->getSymbolName()),
126131
phutil_escape_html($symbol->getSymbolLanguage()),
127132
phutil_escape_html($project_name),
@@ -133,13 +138,15 @@ interface_exists($this->name, false)) {
133138
$table->setHeaders(
134139
array(
135140
'Type',
141+
'Context',
136142
'Name',
137143
'Language',
138144
'Project',
139145
'File',
140146
));
141147
$table->setColumnClasses(
142148
array(
149+
'',
143150
'',
144151
'pri',
145152
'',

‎src/applications/diffusion/query/DiffusionSymbolQuery.php

+17
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*/
3030
final class DiffusionSymbolQuery extends PhabricatorOffsetPagedQuery {
3131

32+
private $context;
3233
private $namePrefix;
3334
private $name;
3435

@@ -44,6 +45,15 @@ final class DiffusionSymbolQuery extends PhabricatorOffsetPagedQuery {
4445
/* -( Configuring the Query )---------------------------------------------- */
4546

4647

48+
/**
49+
* @task config
50+
*/
51+
public function setContext($context) {
52+
$this->context = $context;
53+
return $this;
54+
}
55+
56+
4757
/**
4858
* @task config
4959
*/
@@ -180,6 +190,13 @@ private function buildOrderClause($conn_r) {
180190
private function buildWhereClause($conn_r) {
181191
$where = array();
182192

193+
if (isset($this->context)) {
194+
$where[] = qsprintf(
195+
$conn_r,
196+
'symbolContext = %s',
197+
$this->context);
198+
}
199+
183200
if ($this->name) {
184201
$where[] = qsprintf(
185202
$conn_r,

0 commit comments

Comments
 (0)
Failed to load comments.