2016-12-13 00:51:02 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types = 1);
|
|
|
|
|
|
|
|
namespace LanguageServer;
|
|
|
|
|
|
|
|
use LanguageServer\FilesFinder\FileSystemFilesFinder;
|
|
|
|
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
|
|
|
|
use LanguageServer\Index\StubsIndex;
|
|
|
|
use phpDocumentor\Reflection\DocBlockFactory;
|
|
|
|
use Webmozart\PathUtil\Path;
|
|
|
|
use Sabre\Uri;
|
|
|
|
use function Sabre\Event\coroutine;
|
2017-06-09 18:25:30 +00:00
|
|
|
use Microsoft\PhpParser;
|
2016-12-13 00:51:02 +00:00
|
|
|
|
2016-12-20 12:44:01 +00:00
|
|
|
foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../autoload.php', __DIR__ . '/../vendor/autoload.php'] as $file) {
|
|
|
|
if (file_exists($file)) {
|
|
|
|
require $file;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-12-13 00:51:02 +00:00
|
|
|
|
|
|
|
class ComposerScripts
|
|
|
|
{
|
|
|
|
public static function parseStubs()
|
|
|
|
{
|
|
|
|
coroutine(function () {
|
|
|
|
|
|
|
|
$index = new StubsIndex;
|
|
|
|
|
|
|
|
$finder = new FileSystemFilesFinder;
|
|
|
|
$contentRetriever = new FileSystemContentRetriever;
|
|
|
|
$docBlockFactory = DocBlockFactory::createInstance();
|
2017-06-09 18:25:30 +00:00
|
|
|
$parser = new PhpParser\Parser();
|
2016-12-13 00:51:02 +00:00
|
|
|
$definitionResolver = new DefinitionResolver($index);
|
|
|
|
|
2016-12-20 12:53:15 +00:00
|
|
|
$stubsLocation = null;
|
2017-01-30 10:55:13 +00:00
|
|
|
foreach ([__DIR__ . '/../../../jetbrains/phpstorm-stubs', __DIR__ . '/../vendor/jetbrains/phpstorm-stubs'] as $dir) {
|
2016-12-20 12:53:15 +00:00
|
|
|
if (file_exists($dir)) {
|
|
|
|
$stubsLocation = Path::canonicalize($dir);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$stubsLocation) {
|
2017-01-30 10:55:13 +00:00
|
|
|
throw new \Exception('jetbrains/phpstorm-stubs package not found');
|
2016-12-20 12:53:15 +00:00
|
|
|
}
|
|
|
|
|
2016-12-13 00:51:02 +00:00
|
|
|
$uris = yield $finder->find("$stubsLocation/**/*.php");
|
|
|
|
|
|
|
|
foreach ($uris as $uri) {
|
|
|
|
echo "Parsing $uri\n";
|
|
|
|
$content = yield $contentRetriever->retrieve($uri);
|
|
|
|
|
|
|
|
// Change URI to phpstubs://
|
|
|
|
$parts = Uri\parse($uri);
|
|
|
|
$parts['path'] = Path::makeRelative($parts['path'], $stubsLocation);
|
|
|
|
$parts['scheme'] = 'phpstubs';
|
|
|
|
$uri = Uri\build($parts);
|
|
|
|
|
2017-10-23 05:54:38 +00:00
|
|
|
// Create a new document and add it to $index
|
|
|
|
new PhpDocument($uri, $content, $index, $parser, $docBlockFactory, $definitionResolver);
|
2016-12-13 00:51:02 +00:00
|
|
|
}
|
|
|
|
|
2017-01-25 00:38:11 +00:00
|
|
|
$index->setComplete();
|
|
|
|
|
2016-12-13 00:51:02 +00:00
|
|
|
echo "Saving Index\n";
|
|
|
|
|
|
|
|
$index->save();
|
|
|
|
|
|
|
|
echo "Finished\n";
|
|
|
|
})->wait();
|
|
|
|
}
|
|
|
|
}
|