1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-09-20 08:58:55 +02: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:
vrana 2013-02-19 13:42:09 -08:00
parent a3e0c26ea8
commit df013f6282
3 changed files with 22 additions and 22 deletions

View file

@ -3,7 +3,7 @@
/**
* @group linter
*/
abstract class ArcanistBaseXHPASTLinter extends ArcanistLinter {
abstract class ArcanistBaseXHPASTLinter extends ArcanistFutureLinter {
protected function raiseLintAtToken(
XHPASTToken $token,

View file

@ -68,11 +68,11 @@ final class ArcanistPhutilXHPASTLinter extends ArcanistBaseXHPASTLinter {
return 2;
}
public function willLintPaths(array $paths) {
$this->xhpastLinter->willLintPaths($paths);
protected function buildFutures(array $paths) {
return $this->xhpastLinter->buildFutures($paths);
}
public function lintPath($path) {
protected function resolveFuture($path, Future $future) {
$tree = $this->xhpastLinter->getXHPASTTreeForPath($path);
if (!$tree) {
return;

View file

@ -7,7 +7,8 @@
*/
final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
protected $trees = array();
private $futures = array();
private $trees = array();
const LINT_PHP_SYNTAX_ERROR = 1;
const LINT_UNABLE_TO_PARSE = 2;
@ -123,21 +124,25 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
);
}
public function willLintPaths(array $paths) {
$futures = array();
protected function buildFutures(array $paths) {
$futures = Futures(array())->limit(8);
foreach ($paths as $path) {
if (array_key_exists($path, $this->trees)) {
continue;
if (!isset($this->futures[$path])) {
$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->trees[$path] = null;
try {
$this->trees[$path] = XHPASTTree::newFromDataAndResolvedExecFuture(
$this->getData($path),
$future->resolve());
$this->futures[$path]->resolve());
$root = $this->trees[$path]->getRootNode();
$root->buildSelectCache();
$root->buildTokenCache();
@ -147,21 +152,15 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
1,
self::LINT_PHP_SYNTAX_ERROR,
'This file contains a syntax error: '.$ex->getMessage());
$this->stopAllLinters();
return;
} catch (Exception $ex) {
$this->raiseLintAtPath(
self::LINT_UNABLE_TO_PARSE,
'XHPAST could not parse this file, probably because the AST is too '.
'deep. Some lint issues may not have been detected. You may safely '.
'ignore this warning.');
return;
}
}
}
public function getXHPASTTreeForPath($path) {
return idx($this->trees, $path);
return $this->trees[$path];
}
public function getCacheVersion() {
@ -173,12 +172,13 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
return $version;
}
public function lintPath($path) {
if (!$this->trees[$path]) {
protected function resolveFuture($path, Future $future) {
$tree = $this->getXHPASTTreeForPath($path);
if (!$tree) {
return;
}
$root = $this->trees[$path]->getRootNode();
$root = $tree->getRootNode();
$method_codes = array(
'lintStrstrUsedForCheck' => self::LINT_SLOWNESS,