mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 16:22:43 +01:00
When users click a symbol in Differential to jump to the definition, include path/line context
Summary: Ref T13047. In some reasonable cases, knowing the path and line number where a symbol appears is useful in ranking or filtering the set of matching symbols. Giving symbol sources more information can't hurt, and it's generally free for us to include this context since we just need to grab it out of the document and pass it along. We can't always get this data (for example, if a user types `s idx` into global search, we have no clue) but this is similar to other types of context which are only available sometimes (like which repository a symbol appears in). Test Plan: Command-clicked some symbols in 1-up (unified) and 2-up (side-by-side) diff views with symbol indexes configured. Got accurate path and line information in the URI I was redirected to. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13047 Differential Revision: https://secure.phabricator.com/D18936
This commit is contained in:
parent
0ec83132a8
commit
c37b6c6633
3 changed files with 72 additions and 9 deletions
|
@ -13,7 +13,7 @@ return array(
|
|||
'core.pkg.js' => '4c79d74f',
|
||||
'darkconsole.pkg.js' => '1f9a31bc',
|
||||
'differential.pkg.css' => '45951e9e',
|
||||
'differential.pkg.js' => '500a75c5',
|
||||
'differential.pkg.js' => 'c1af2de3',
|
||||
'diffusion.pkg.css' => 'a2d17c7d',
|
||||
'diffusion.pkg.js' => '6134c5a1',
|
||||
'favicon.ico' => '30672e08',
|
||||
|
@ -443,7 +443,7 @@ return array(
|
|||
'rsrc/js/application/releeph/releeph-preview-branch.js' => 'b2b4fbaf',
|
||||
'rsrc/js/application/releeph/releeph-request-state-change.js' => 'a0b57eb8',
|
||||
'rsrc/js/application/releeph/releeph-request-typeahead.js' => 'de2e896f',
|
||||
'rsrc/js/application/repository/repository-crossreference.js' => '7fe9bc12',
|
||||
'rsrc/js/application/repository/repository-crossreference.js' => 'c5627622',
|
||||
'rsrc/js/application/search/behavior-reorder-profile-menu-items.js' => 'e2e0a072',
|
||||
'rsrc/js/application/search/behavior-reorder-queries.js' => 'e9581f08',
|
||||
'rsrc/js/application/slowvote/behavior-slowvote-embed.js' => '887ad43f',
|
||||
|
@ -692,7 +692,7 @@ return array(
|
|||
'javelin-behavior-reorder-applications' => '76b9fc3e',
|
||||
'javelin-behavior-reorder-columns' => 'e1d25dfb',
|
||||
'javelin-behavior-reorder-profile-menu-items' => 'e2e0a072',
|
||||
'javelin-behavior-repository-crossreference' => '7fe9bc12',
|
||||
'javelin-behavior-repository-crossreference' => 'c5627622',
|
||||
'javelin-behavior-scrollbar' => '834a1173',
|
||||
'javelin-behavior-search-reorder-queries' => 'e9581f08',
|
||||
'javelin-behavior-select-content' => 'bf5374ef',
|
||||
|
@ -1555,12 +1555,6 @@ return array(
|
|||
'7f243deb' => array(
|
||||
'javelin-install',
|
||||
),
|
||||
'7fe9bc12' => array(
|
||||
'javelin-behavior',
|
||||
'javelin-dom',
|
||||
'javelin-stratcom',
|
||||
'javelin-uri',
|
||||
),
|
||||
'834a1173' => array(
|
||||
'javelin-behavior',
|
||||
'javelin-scrollbar',
|
||||
|
@ -1928,6 +1922,12 @@ return array(
|
|||
'javelin-stratcom',
|
||||
'phabricator-tooltip',
|
||||
),
|
||||
'c5627622' => array(
|
||||
'javelin-behavior',
|
||||
'javelin-dom',
|
||||
'javelin-stratcom',
|
||||
'javelin-uri',
|
||||
),
|
||||
'c587b80f' => array(
|
||||
'javelin-install',
|
||||
),
|
||||
|
|
|
@ -204,6 +204,7 @@ final class DifferentialChangesetDetailView extends AphrontView {
|
|||
'loaded' => $this->getLoaded(),
|
||||
'undoTemplates' => hsprintf('%s', $renderer->renderUndoTemplates()),
|
||||
'displayPath' => hsprintf('%s', $display_parts),
|
||||
'path' => $display_filename,
|
||||
'icon' => $display_icon,
|
||||
),
|
||||
'class' => $class,
|
||||
|
|
|
@ -96,6 +96,17 @@ JX.behavior('repository-crossreference', function(config, statics) {
|
|||
if (target.hasAttribute('data-symbol-name')) {
|
||||
symbol = target.getAttribute('data-symbol-name');
|
||||
}
|
||||
|
||||
var line = getLineNumber(target);
|
||||
if (line !== null) {
|
||||
query.line = line;
|
||||
}
|
||||
|
||||
var path = getPath(target);
|
||||
if (path !== null) {
|
||||
query.path = path;
|
||||
}
|
||||
|
||||
var uri = JX.$U('/diffusion/symbol/' + symbol + '/');
|
||||
uri.addQueryParams(query);
|
||||
window.open(uri);
|
||||
|
@ -111,6 +122,57 @@ JX.behavior('repository-crossreference', function(config, statics) {
|
|||
}
|
||||
}
|
||||
|
||||
function getLineNumber(target) {
|
||||
|
||||
// Figure out the line number by finding the most recent "<th />" in this
|
||||
// row with a number in it. We may need to skip over one "<th />" if the
|
||||
// diff is being displayed in unified mode.
|
||||
|
||||
var cell = JX.DOM.findAbove(target, 'td');
|
||||
if (!cell) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var row = JX.DOM.findAbove(target, 'tr');
|
||||
if (!row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var ii;
|
||||
|
||||
var cell_list = [];
|
||||
for (ii = 0; ii < row.childNodes.length; ii++) {
|
||||
cell_list.push(row.childNodes[ii]);
|
||||
}
|
||||
cell_list.reverse();
|
||||
|
||||
var found = false;
|
||||
for (ii = 0; ii < cell_list.length; ii++) {
|
||||
if (cell_list[ii] === cell) {
|
||||
found = true;
|
||||
}
|
||||
|
||||
if (found && JX.DOM.isType(cell_list[ii], 'th')) {
|
||||
var int_value = parseInt(cell_list[ii].textContent, 10);
|
||||
if (int_value) {
|
||||
return int_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function getPath(target) {
|
||||
var changeset = JX.DOM.findAbove(target, 'div', 'differential-changeset');
|
||||
|
||||
if (!changeset) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return JX.Stratcom.getData(changeset).path;
|
||||
}
|
||||
|
||||
if (config.container) {
|
||||
link(JX.$(config.container), config.lang);
|
||||
} else if (config.section) {
|
||||
|
|
Loading…
Reference in a new issue