Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete class aliases whose targets do not exist #605

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2d91ee8
speedup autocomplete with ReadableIndex::getDefinitionsForNamespace
nicolasmure Aug 6, 2017
b7c7128
update tests
nicolasmure Aug 6, 2017
6d725a2
speedup static access autocomplete
nicolasmure Aug 6, 2017
18f2f4c
cleanup
nicolasmure Aug 6, 2017
17602aa
globalDefinitions cache to speedup autocomplete
nicolasmure Aug 6, 2017
6d30035
also remove empty namespace index
nicolasmure Aug 8, 2017
ca0caf1
store definitions under the namespaceDefinitions cache key directly
nicolasmure Aug 9, 2017
8768b69
use Generators to get definitions without wasting memory
nicolasmure Aug 9, 2017
8801edb
also yield URIs to save memory
nicolasmure Aug 9, 2017
6a41a7f
add example of indexed definitions
nicolasmure Aug 10, 2017
6a36828
avoid useless array
nicolasmure Aug 10, 2017
e34d8e1
use of null coalescing operator
nicolasmure Aug 10, 2017
14f840b
use correct terminology
nicolasmure Oct 5, 2017
e9fd572
consider the merge of #511
nicolasmure Nov 13, 2017
d1f85f1
use tree representation index
nicolasmure Nov 13, 2017
188a5df
fix definitions storage collision (member / non member)
nicolasmure Nov 14, 2017
cacde1e
use a single array to store definitions
nicolasmure Nov 14, 2017
e162d94
cleanup
nicolasmure Nov 14, 2017
7437d30
Fix formatting
felixfbecker Nov 15, 2017
b118c77
Correct some docblocks
felixfbecker Nov 15, 2017
b3f30f3
cache is backward compatible
nicolasmure Nov 15, 2017
7511e25
Merge branch 'master' into feature/autocomplete-speedup
felixfbecker Nov 15, 2017
fcdf791
use string concatenation instead of sprintf
nicolasmure Nov 16, 2017
3bda390
Merge branch 'master' into feature/autocomplete-speedup
felixfbecker Nov 19, 2017
b03950c
Cleanup
felixfbecker Nov 18, 2017
97ec127
fix definition removal
nicolasmure Nov 19, 2017
48bbbb5
differenciate member and non member definitions
nicolasmure Nov 19, 2017
67dd980
Merge branch 'master' into feature/autocomplete-speedup
felixfbecker Nov 19, 2017
91ca99a
Revert "differenciate member and non member definitions"
felixfbecker Nov 23, 2017
fa67f84
perf: get direct children
felixfbecker Nov 23, 2017
81c40f2
chore: add completion benchmark
felixfbecker Nov 23, 2017
8617948
Merge remote-tracking branch 'origin/master' into autocomplet-speedup
Declspeck Feb 3, 2018
439cebe
fix(tests): fix require in parsing.php benchmark after file move
Declspeck Feb 3, 2018
e589f9e
refactor(completion): make completion of global symbols use Index mor…
Declspeck Feb 3, 2018
6858bd3
tests(completion): add completion of new| ParameterBag to completion …
Declspeck Feb 3, 2018
d6b4e79
feat(completion): complete for used namespaces
Declspeck Feb 9, 2018
98ac9ff
Merge branch 'master' into autocomplet-speedup
Declspeck Feb 9, 2018
d1933b8
refactor(completion): rewrite global name completion with generators
Declspeck Feb 15, 2018
0bc5b81
fix(completion): Return type hint
Declspeck Feb 15, 2018
f5b1256
feat(completion): complete class aliases when the target does not exist
Declspeck Feb 24, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions benchmarks/completion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace LanguageServer\Tests;
require __DIR__ . '/../vendor/autoload.php';

use Exception;
use LanguageServer\Index\Index;
use LanguageServer\PhpDocument;
use LanguageServer\DefinitionResolver;
use LanguageServer\Protocol\Position;
use LanguageServer\CompletionProvider;
use Microsoft\PhpParser;
use phpDocumentor\Reflection\DocBlockFactory;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

$totalSize = 0;

$framework = "symfony";

$iterator = new RecursiveDirectoryIterator(__DIR__ . "/../validation/frameworks/$framework");
$testProviderArray = array();

foreach (new RecursiveIteratorIterator($iterator) as $file) {
if (strpos((string)$file, ".php") !== false) {
$totalSize += $file->getSize();
$testProviderArray[] = $file->getRealPath();
}
}

if (count($testProviderArray) === 0) {
throw new Exception("ERROR: Validation testsuite frameworks not found - run `git submodule update --init --recursive` to download.");
}

$index = new Index;
$definitionResolver = new DefinitionResolver($index);
$completionProvider = new CompletionProvider($definitionResolver, $index);
$docBlockFactory = DocBlockFactory::createInstance();
$completionFile = realpath(__DIR__ . '/../validation/frameworks/symfony/src/Symfony/Component/HttpFoundation/Request.php');
$parser = new PhpParser\Parser();
$completionDocument = null;

echo "Indexing $framework" . PHP_EOL;

foreach ($testProviderArray as $idx => $testCaseFile) {
if (filesize($testCaseFile) > 100000) {
continue;
}
if ($idx % 100 === 0) {
echo $idx . '/' . count($testProviderArray) . PHP_EOL;
}

$fileContents = file_get_contents($testCaseFile);

try {
$d = new PhpDocument($testCaseFile, $fileContents, $index, $parser, $docBlockFactory, $definitionResolver);
if ($testCaseFile === $completionFile) {
$completionDocument = $d;
}
} catch (\Throwable $e) {
echo $e->getMessage() . PHP_EOL;
continue;
}
}

echo "Getting completion". PHP_EOL;

// Completion in $this->|request = new ParameterBag($request);
$start = microtime(true);
$list = $completionProvider->provideCompletion($completionDocument, new Position(274, 15));
$end = microtime(true);
echo 'Time ($this->|): ' . ($end - $start) . 's' . PHP_EOL;
echo count($list->items) . ' completion items' . PHP_EOL;

// Completion in $this->request = new| ParameterBag($request);
// (this only finds ParameterBag though.)
$start = microtime(true);
$list = $completionProvider->provideCompletion($completionDocument, new Position(274, 28));
$end = microtime(true);
echo 'Time (new|): ' . ($end - $start) . 's' . PHP_EOL;
echo count($list->items) . ' completion items' . PHP_EOL;
4 changes: 2 additions & 2 deletions Performance.php → benchmarks/parsing.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

namespace LanguageServer\Tests;
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/../vendor/autoload.php';

use Exception;
use LanguageServer\Index\Index;
Expand All @@ -17,7 +17,7 @@
$frameworks = ["drupal", "wordpress", "php-language-server", "tolerant-php-parser", "math-php", "symfony", "codeigniter", "cakephp"];

foreach($frameworks as $framework) {
$iterator = new RecursiveDirectoryIterator(__DIR__ . "/validation/frameworks/$framework");
$iterator = new RecursiveDirectoryIterator(__DIR__ . "/../validation/frameworks/$framework");
$testProviderArray = array();

foreach (new RecursiveIteratorIterator($iterator) as $file) {
Expand Down
6 changes: 4 additions & 2 deletions fixtures/completion/used_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Whatever;

use TestNamespace\{TestClass, TestInterface};
use TestNamespace\{TestClass, TestInterface, IDontExist};

TestC
TestC;

IDont;

class OtherClass {}
10 changes: 10 additions & 0 deletions fixtures/completion/used_namespace.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Whatever;

use TestNamespace\InnerNamespace as AliasNamespace;

class IDontShowUpInCompletion {}

AliasNamespace\I;
AliasNamespace\;
5 changes: 5 additions & 0 deletions fixtures/symbols.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,8 @@ class Example {
public function __construct() {}
public function __destruct() {}
}

namespace TestNamespace\InnerNamespace;

class InnerClass {
}
Loading