1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 10:12:41 +01:00

Provide character position information to symbol queries

Summary: Depends on D18937. Ref T13047. When available, provide character positions so external indexers can return more accurate results.

Test Plan: Clicked symbols in Safari, Firefox and Chrome, got sensible-looking character positions.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13047

Differential Revision: https://secure.phabricator.com/D18939
This commit is contained in:
epriestley 2018-01-26 06:29:35 -08:00
parent 3a2d337679
commit fdc36677ba
4 changed files with 67 additions and 12 deletions

View file

@ -13,7 +13,7 @@ return array(
'core.pkg.js' => '4c79d74f',
'darkconsole.pkg.js' => '1f9a31bc',
'differential.pkg.css' => '45951e9e',
'differential.pkg.js' => 'c1af2de3',
'differential.pkg.js' => 'b69ae3ec',
'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' => 'c5627622',
'rsrc/js/application/repository/repository-crossreference.js' => 'fc2d8ffd',
'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' => 'c5627622',
'javelin-behavior-repository-crossreference' => 'fc2d8ffd',
'javelin-behavior-scrollbar' => '834a1173',
'javelin-behavior-search-reorder-queries' => 'e9581f08',
'javelin-behavior-select-content' => 'bf5374ef',
@ -1922,12 +1922,6 @@ return array(
'javelin-stratcom',
'phabricator-tooltip',
),
'c5627622' => array(
'javelin-behavior',
'javelin-dom',
'javelin-stratcom',
'javelin-uri',
),
'c587b80f' => array(
'javelin-install',
),
@ -2165,6 +2159,12 @@ return array(
'javelin-install',
'javelin-dom',
),
'fc2d8ffd' => array(
'javelin-behavior',
'javelin-dom',
'javelin-stratcom',
'javelin-uri',
),
'fc91ab6c' => array(
'javelin-behavior',
'javelin-dom',

View file

@ -69,6 +69,13 @@ final class DiffusionSymbolController extends DiffusionController {
$external_query->withLines(array($request->getInt('line')));
}
if ($request->getInt('char')) {
$external_query->withCharacterPositions(
array(
$request->getInt('char'),
));
}
if ($repos) {
$external_query->withRepositories($repos);
}

View file

@ -9,6 +9,7 @@ final class DiffusionExternalSymbolQuery extends Phobject {
private $paths = array();
private $lines = array();
private $repositories = array();
private $characterPositions = array();
public function withLanguages(array $languages) {
$this->languages = $languages;
@ -40,6 +41,11 @@ final class DiffusionExternalSymbolQuery extends Phobject {
return $this;
}
public function withCharacterPositions(array $positions) {
$this->characterPositions = $positions;
return $this;
}
public function withRepositories(array $repositories) {
assert_instances_of($repositories, 'PhabricatorRepository');
$this->repositories = $repositories;
@ -74,6 +80,10 @@ final class DiffusionExternalSymbolQuery extends Phobject {
return $this->repositories;
}
public function getCharacterPositions() {
return $this->characterPositions;
}
public function matchesAnyLanguage(array $languages) {
return (!$this->languages) || array_intersect($languages, $this->languages);
}

View file

@ -28,8 +28,8 @@ JX.behavior('repository-crossreference', function(config, statics) {
nf : 'function',
na : null,
nb : 'builtin',
n : null,
};
n : null
};
function link(element, lang) {
JX.DOM.alterClass(element, 'repository-crossreference', true);
@ -58,8 +58,15 @@ JX.behavior('repository-crossreference', function(config, statics) {
// Continue if we're not inside an inline comment.
}
// If only part of the symbol was edited, the symbol name itself will
// have another "<span />" inside of it which highlights only the
// edited part. Skip over it.
if (JX.DOM.isNode(target, 'span') && (target.className === 'bright')) {
target = target.parentNode;
}
if (e.getType() === 'mouseover') {
while (target !== document.body) {
while (target && target !== document.body) {
if (JX.DOM.isNode(target, 'span') &&
(target.className in class_map)) {
highlighted = target;
@ -107,6 +114,11 @@ JX.behavior('repository-crossreference', function(config, statics) {
query.path = path;
}
var char = getChar(target);
if (char !== null) {
query.char = char;
}
var uri = JX.$U('/diffusion/symbol/' + symbol + '/');
uri.addQueryParams(query);
window.open(uri);
@ -173,6 +185,32 @@ JX.behavior('repository-crossreference', function(config, statics) {
return JX.Stratcom.getData(changeset).path;
}
function getChar(target) {
var cell = JX.DOM.findAbove(target, 'td');
if (!cell) {
return null;
}
var char = 1;
for (var ii = 0; ii < cell.childNodes.length; ii++) {
var node = cell.childNodes[ii];
if (node === target) {
return char;
}
var content = '' + node.textContent;
// Strip off any ZWS characters. These are marker characters used to
// improve copy/paste behavior.
content = content.replace(/\u200B/g, '');
char += content.length;
}
return null;
}
if (config.container) {
link(JX.$(config.container), config.lang);
} else if (config.section) {