1
0
Fork 0
pull/214/head
Felix Becker 2016-12-12 23:13:26 +01:00
parent 91323a8e07
commit 243819e553
5 changed files with 5 additions and 144 deletions

View File

@ -41,7 +41,6 @@ class ComposerScripts
$index->save(); $index->save();
echo "Finished\n"; echo "Finished\n";
})->wait(); })->wait();
} }
} }

View File

@ -1,81 +0,0 @@
<?php
namespace LanguageServer;
class PhpDocumentLoader
{
public function __construct(ContentRetriever $contentRetriever)
{
$this->contentRetriever = $contentRetriever;
}
/**
* Loads a document
*
* @param string $uri
* @return Promise <PhpDocument>
*/
public function load(string $uri): Promise
{
return coroutine(function () use ($uri) {
$limit = 150000;
$content = yield $this->contentRetriever->retrieve($uri);
$size = strlen($content);
if ($size > $limit) {
throw new ContentTooLargeException($uri, $size, $limit);
}
/** The key for the index */
$key = '';
// If the document is part of a dependency
if (preg_match($u['path'], '/vendor\/(\w+\/\w+)/', $matches)) {
if ($this->composerLockFiles === null) {
throw new \Exception('composer.lock files were not read yet');
}
// Try to find closest composer.lock
$u = Uri\parse($uri);
$packageName = $matches[1];
do {
$u['path'] = dirname($u['path']);
foreach ($this->composerLockFiles as $lockFileUri => $lockFileContent) {
$lockFileUri = Uri\parse($composerLockFile);
$lockFileUri['path'] = dirname($lockFileUri['path']);
if ($u == $lockFileUri) {
// Found it, find out package version
foreach ($lockFileContent->packages as $package) {
if ($package->name === $packageName) {
$key = $packageName . ':' . $package->version;
break;
}
}
break;
}
}
} while (!empty(trim($u, '/')));
}
// If there is no index for the key yet, create one
if (!isset($this->indexes[$key])) {
$this->indexes[$key] = new Index;
}
$index = $this->indexes[$key];
if (isset($this->documents[$uri])) {
$document = $this->documents[$uri];
$document->updateContent($content);
} else {
$document = new PhpDocument(
$uri,
$content,
$index,
$this->parser,
$this->docBlockFactory,
$this->definitionResolver
);
}
return $document;
});
}
}

View File

@ -10,7 +10,7 @@ abstract class AbstractAggregateIndex implements ReadableIndex
* *
* @return ReadableIndex[] * @return ReadableIndex[]
*/ */
protected abstract function getIndexes(): array; abstract protected function getIndexes(): array;
/** /**
* Returns an associative array [string => Definition] that maps fully qualified symbol names * Returns an associative array [string => Definition] that maps fully qualified symbol names

View File

@ -1,56 +0,0 @@
<?php
declare(strict_types = 1);
namespace LanguageServer\Index;
use LanguageServer\FilesFinder\FileSystemFilesFinder;
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
use LanguageServer\Index\StubsIndex;
use phpDocumentor\Reflection\DocBlockFactory;
use Webmozart\PathUtil\Path;
use function Sabre\Event\coroutine;
/**
* A factory for the StubIndex
*/
class StubsIndexer
{
/**
* @var
*/
private $filesFinder;
public function __construct()
/**
* @return Promise <StubsIndex>
*/
public function index(): Promise
{
coroutine(function () {
$index = new StubsIndex;
$finder = new FileSystemFilesFinder;
$contentRetriever = new FileSystemContentRetriever;
$docBlockFactory = DocBlockFactory::createInstance();
$parser = new Parser;
$definitionResolver = new DefinitionResolver($index);
$uris = yield $finder->find(Path::canonicalize(__DIR__ . '/../vendor/JetBrains/phpstorm-stubs/**/*.php'));
foreach ($uris as $uri) {
echo "Parsing $uri\n";
$content = yield $contentRetriever->retrieve($uri);
$document = new PhpDocument($uri, $content, $index, $parser, $docBlockFactory, $definitionResolver);
}
echo "Saving Index\n";
file_put_contents(__DIR__ . '/../stubs', serialize($index));
echo "Finished\n";
})->wait();
}
}

View File

@ -216,17 +216,16 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
* *
* @return Promise <void> * @return Promise <void>
*/ */
private function index(array $phpFiles): Promise private function index(array $uris): Promise
{ {
return coroutine(function () use ($phpFiles) { return coroutine(function () use ($uris) {
$count = count($phpFiles); $count = count($uris);
$startTime = microtime(true); $startTime = microtime(true);
// Parse PHP files // Parse PHP files
foreach ($phpFiles as $i => $uri) { foreach ($uris as $i => $uri) {
if ($this->documentLoader->isOpen($uri)) { if ($this->documentLoader->isOpen($uri)) {
continue; continue;
} }