diff --git a/src/ComposerScripts.php b/src/ComposerScripts.php index 12572fe..f507c80 100644 --- a/src/ComposerScripts.php +++ b/src/ComposerScripts.php @@ -41,7 +41,6 @@ class ComposerScripts $index->save(); echo "Finished\n"; - })->wait(); } } diff --git a/src/DocumentLoader.php b/src/DocumentLoader.php deleted file mode 100644 index fcf2226..0000000 --- a/src/DocumentLoader.php +++ /dev/null @@ -1,81 +0,0 @@ -contentRetriever = $contentRetriever; - } - - /** - * Loads a document - * - * @param string $uri - * @return Promise - */ - 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; - }); - } -} diff --git a/src/Index/AbstractAggregateIndex.php b/src/Index/AbstractAggregateIndex.php index 590bbd5..4da668c 100644 --- a/src/Index/AbstractAggregateIndex.php +++ b/src/Index/AbstractAggregateIndex.php @@ -10,7 +10,7 @@ abstract class AbstractAggregateIndex implements 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 diff --git a/src/Index/StubsIndexer.php b/src/Index/StubsIndexer.php deleted file mode 100644 index 49d47e2..0000000 --- a/src/Index/StubsIndexer.php +++ /dev/null @@ -1,56 +0,0 @@ - - */ - 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(); - } -} diff --git a/src/LanguageServer.php b/src/LanguageServer.php index a37003c..b9739d9 100644 --- a/src/LanguageServer.php +++ b/src/LanguageServer.php @@ -216,17 +216,16 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher * * @return Promise */ - 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); // Parse PHP files - foreach ($phpFiles as $i => $uri) { - + foreach ($uris as $i => $uri) { if ($this->documentLoader->isOpen($uri)) { continue; }