|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace LanguageServer\Tests; |
| 4 | +require __DIR__ . '/../vendor/autoload.php'; |
| 5 | + |
| 6 | +use Composer\XdebugHandler\XdebugHandler; |
| 7 | +use Exception; |
| 8 | +use LanguageServer\CompletionProvider; |
| 9 | +use LanguageServer\DefinitionResolver; |
| 10 | +use LanguageServer\Index\Index; |
| 11 | +use LanguageServer\PhpDocument; |
| 12 | +use LanguageServer\StderrLogger; |
| 13 | +use LanguageServerProtocol\Position; |
| 14 | +use Microsoft\PhpParser; |
| 15 | +use phpDocumentor\Reflection\DocBlockFactory; |
| 16 | +use RecursiveDirectoryIterator; |
| 17 | +use RecursiveIteratorIterator; |
| 18 | + |
| 19 | +$logger = new StderrLogger(); |
| 20 | +$xdebugHandler = new XdebugHandler('PHPLS'); |
| 21 | +$xdebugHandler->setLogger($logger); |
| 22 | +$xdebugHandler->check(); |
| 23 | +unset($xdebugHandler); |
| 24 | + |
| 25 | +$totalSize = 0; |
| 26 | + |
| 27 | +$framework = "symfony"; |
| 28 | + |
| 29 | +$iterator = new RecursiveDirectoryIterator(__DIR__ . "/../validation/frameworks/$framework"); |
| 30 | +$testProviderArray = array(); |
| 31 | + |
| 32 | +foreach (new RecursiveIteratorIterator($iterator) as $file) { |
| 33 | + if (strpos((string)$file, ".php") !== false) { |
| 34 | + $totalSize += $file->getSize(); |
| 35 | + $testProviderArray[] = $file->getRealPath(); |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +if (count($testProviderArray) === 0) { |
| 40 | + throw new Exception("ERROR: Validation testsuite frameworks not found - run `git submodule update --init --recursive` to download."); |
| 41 | +} |
| 42 | + |
| 43 | +$index = new Index; |
| 44 | +$definitionResolver = new DefinitionResolver($index); |
| 45 | +$completionProvider = new CompletionProvider($definitionResolver, $index); |
| 46 | +$docBlockFactory = DocBlockFactory::createInstance(); |
| 47 | +$completionFile = realpath(__DIR__ . '/../validation/frameworks/symfony/src/Symfony/Component/HttpFoundation/Request.php'); |
| 48 | +$parser = new PhpParser\Parser(); |
| 49 | +$completionDocument = null; |
| 50 | + |
| 51 | +echo "Indexing $framework" . PHP_EOL; |
| 52 | + |
| 53 | +foreach ($testProviderArray as $idx => $testCaseFile) { |
| 54 | + if (filesize($testCaseFile) > 100000) { |
| 55 | + continue; |
| 56 | + } |
| 57 | + if ($idx % 100 === 0) { |
| 58 | + echo $idx . '/' . count($testProviderArray) . PHP_EOL; |
| 59 | + } |
| 60 | + |
| 61 | + $fileContents = file_get_contents($testCaseFile); |
| 62 | + |
| 63 | + try { |
| 64 | + $d = new PhpDocument($testCaseFile, $fileContents, $index, $parser, $docBlockFactory, $definitionResolver); |
| 65 | + if ($testCaseFile === $completionFile) { |
| 66 | + $completionDocument = $d; |
| 67 | + } |
| 68 | + } catch (\Throwable $e) { |
| 69 | + echo $e->getMessage() . PHP_EOL; |
| 70 | + continue; |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +echo "Getting completion". PHP_EOL; |
| 75 | + |
| 76 | +// Completion in $this->|request = new ParameterBag($request); |
| 77 | +$start = microtime(true); |
| 78 | +$list = $completionProvider->provideCompletion($completionDocument, new Position(274, 15)); |
| 79 | +$end = microtime(true); |
| 80 | +echo 'Time ($this->|): ' . ($end - $start) . 's' . PHP_EOL; |
| 81 | +echo count($list->items) . ' completion items' . PHP_EOL; |
| 82 | + |
| 83 | +// Completion in $this->request = new| ParameterBag($request); |
| 84 | +// (this only finds ParameterBag though.) |
| 85 | +$start = microtime(true); |
| 86 | +$list = $completionProvider->provideCompletion($completionDocument, new Position(274, 28)); |
| 87 | +$end = microtime(true); |
| 88 | +echo 'Time (new|): ' . ($end - $start) . 's' . PHP_EOL; |
| 89 | +echo count($list->items) . ' completion items' . PHP_EOL; |
0 commit comments