mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-26 00:32:41 +01:00
Resolve XHPAST linter futures on background
Summary: This is a little bit tricky - if both XHPAST and PhutilXHPAST linters lint the same path then they get the same future wrapped in two different Future iterators. Test Plan: $ arc unit Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D5015
This commit is contained in:
parent
a3e0c26ea8
commit
df013f6282
3 changed files with 22 additions and 22 deletions
|
@ -3,7 +3,7 @@
|
||||||
/**
|
/**
|
||||||
* @group linter
|
* @group linter
|
||||||
*/
|
*/
|
||||||
abstract class ArcanistBaseXHPASTLinter extends ArcanistLinter {
|
abstract class ArcanistBaseXHPASTLinter extends ArcanistFutureLinter {
|
||||||
|
|
||||||
protected function raiseLintAtToken(
|
protected function raiseLintAtToken(
|
||||||
XHPASTToken $token,
|
XHPASTToken $token,
|
||||||
|
|
|
@ -68,11 +68,11 @@ final class ArcanistPhutilXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function willLintPaths(array $paths) {
|
protected function buildFutures(array $paths) {
|
||||||
$this->xhpastLinter->willLintPaths($paths);
|
return $this->xhpastLinter->buildFutures($paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function lintPath($path) {
|
protected function resolveFuture($path, Future $future) {
|
||||||
$tree = $this->xhpastLinter->getXHPASTTreeForPath($path);
|
$tree = $this->xhpastLinter->getXHPASTTreeForPath($path);
|
||||||
if (!$tree) {
|
if (!$tree) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
*/
|
*/
|
||||||
final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
||||||
|
|
||||||
protected $trees = array();
|
private $futures = array();
|
||||||
|
private $trees = array();
|
||||||
|
|
||||||
const LINT_PHP_SYNTAX_ERROR = 1;
|
const LINT_PHP_SYNTAX_ERROR = 1;
|
||||||
const LINT_UNABLE_TO_PARSE = 2;
|
const LINT_UNABLE_TO_PARSE = 2;
|
||||||
|
@ -123,21 +124,25 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function willLintPaths(array $paths) {
|
protected function buildFutures(array $paths) {
|
||||||
$futures = array();
|
$futures = Futures(array())->limit(8);
|
||||||
foreach ($paths as $path) {
|
foreach ($paths as $path) {
|
||||||
if (array_key_exists($path, $this->trees)) {
|
if (!isset($this->futures[$path])) {
|
||||||
continue;
|
$this->futures[$path] = xhpast_get_parser_future($this->getData($path));
|
||||||
}
|
}
|
||||||
$futures[$path] = xhpast_get_parser_future($this->getData($path));
|
$futures->addFuture($this->futures[$path], $path);
|
||||||
}
|
}
|
||||||
foreach (Futures($futures)->limit(8) as $path => $future) {
|
return $futures;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getXHPASTTreeForPath($path) {
|
||||||
|
if (!array_key_exists($path, $this->trees)) {
|
||||||
$this->willLintPath($path);
|
$this->willLintPath($path);
|
||||||
$this->trees[$path] = null;
|
$this->trees[$path] = null;
|
||||||
try {
|
try {
|
||||||
$this->trees[$path] = XHPASTTree::newFromDataAndResolvedExecFuture(
|
$this->trees[$path] = XHPASTTree::newFromDataAndResolvedExecFuture(
|
||||||
$this->getData($path),
|
$this->getData($path),
|
||||||
$future->resolve());
|
$this->futures[$path]->resolve());
|
||||||
$root = $this->trees[$path]->getRootNode();
|
$root = $this->trees[$path]->getRootNode();
|
||||||
$root->buildSelectCache();
|
$root->buildSelectCache();
|
||||||
$root->buildTokenCache();
|
$root->buildTokenCache();
|
||||||
|
@ -147,21 +152,15 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
||||||
1,
|
1,
|
||||||
self::LINT_PHP_SYNTAX_ERROR,
|
self::LINT_PHP_SYNTAX_ERROR,
|
||||||
'This file contains a syntax error: '.$ex->getMessage());
|
'This file contains a syntax error: '.$ex->getMessage());
|
||||||
$this->stopAllLinters();
|
|
||||||
return;
|
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
$this->raiseLintAtPath(
|
$this->raiseLintAtPath(
|
||||||
self::LINT_UNABLE_TO_PARSE,
|
self::LINT_UNABLE_TO_PARSE,
|
||||||
'XHPAST could not parse this file, probably because the AST is too '.
|
'XHPAST could not parse this file, probably because the AST is too '.
|
||||||
'deep. Some lint issues may not have been detected. You may safely '.
|
'deep. Some lint issues may not have been detected. You may safely '.
|
||||||
'ignore this warning.');
|
'ignore this warning.');
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return $this->trees[$path];
|
||||||
|
|
||||||
public function getXHPASTTreeForPath($path) {
|
|
||||||
return idx($this->trees, $path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCacheVersion() {
|
public function getCacheVersion() {
|
||||||
|
@ -173,12 +172,13 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
||||||
return $version;
|
return $version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function lintPath($path) {
|
protected function resolveFuture($path, Future $future) {
|
||||||
if (!$this->trees[$path]) {
|
$tree = $this->getXHPASTTreeForPath($path);
|
||||||
|
if (!$tree) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$root = $this->trees[$path]->getRootNode();
|
$root = $tree->getRootNode();
|
||||||
|
|
||||||
$method_codes = array(
|
$method_codes = array(
|
||||||
'lintStrstrUsedForCheck' => self::LINT_SLOWNESS,
|
'lintStrstrUsedForCheck' => self::LINT_SLOWNESS,
|
||||||
|
|
Loading…
Reference in a new issue