Refactor pull request
* merge latest upstream * remove currently not required code blocks * fix testspull/668/head
parent
9cc2736df2
commit
09fbec247c
|
@ -147,14 +147,4 @@ abstract class AbstractAggregateIndex implements ReadableIndex
|
||||||
}
|
}
|
||||||
return $refs;
|
return $refs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Wipe all indexes for a reindex
|
|
||||||
*/
|
|
||||||
public function wipe()
|
|
||||||
{
|
|
||||||
foreach ($this->getIndexes() as $index) {
|
|
||||||
$index->wipe();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,12 +222,4 @@ class Index implements ReadableIndex, \Serializable
|
||||||
'staticComplete' => $this->staticComplete
|
'staticComplete' => $this->staticComplete
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function wipe()
|
|
||||||
{
|
|
||||||
$this->definitions = [];
|
|
||||||
$this->references = [];
|
|
||||||
$this->complete = false;
|
|
||||||
$this->staticComplete = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,11 @@ class Indexer
|
||||||
*/
|
*/
|
||||||
private $documentLoader;
|
private $documentLoader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Options
|
||||||
|
*/
|
||||||
|
private $options;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \stdClasss
|
* @var \stdClasss
|
||||||
*/
|
*/
|
||||||
|
@ -63,11 +68,6 @@ class Indexer
|
||||||
*/
|
*/
|
||||||
private $composerJson;
|
private $composerJson;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Options
|
|
||||||
*/
|
|
||||||
private $options;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param FilesFinder $filesFinder
|
* @param FilesFinder $filesFinder
|
||||||
* @param string $rootPath
|
* @param string $rootPath
|
||||||
|
@ -75,9 +75,9 @@ class Indexer
|
||||||
* @param Cache $cache
|
* @param Cache $cache
|
||||||
* @param DependenciesIndex $dependenciesIndex
|
* @param DependenciesIndex $dependenciesIndex
|
||||||
* @param Index $sourceIndex
|
* @param Index $sourceIndex
|
||||||
|
* @param Options $options
|
||||||
* @param PhpDocumentLoader $documentLoader
|
* @param PhpDocumentLoader $documentLoader
|
||||||
* @param \stdClass|null $composerLock
|
* @param \stdClass|null $composerLock
|
||||||
* @param Options|null $options
|
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
FilesFinder $filesFinder,
|
FilesFinder $filesFinder,
|
||||||
|
@ -87,9 +87,9 @@ class Indexer
|
||||||
DependenciesIndex $dependenciesIndex,
|
DependenciesIndex $dependenciesIndex,
|
||||||
Index $sourceIndex,
|
Index $sourceIndex,
|
||||||
PhpDocumentLoader $documentLoader,
|
PhpDocumentLoader $documentLoader,
|
||||||
|
Options $options,
|
||||||
\stdClass $composerLock = null,
|
\stdClass $composerLock = null,
|
||||||
\stdClass $composerJson = null,
|
\stdClass $composerJson = null
|
||||||
Options $options = null
|
|
||||||
) {
|
) {
|
||||||
$this->filesFinder = $filesFinder;
|
$this->filesFinder = $filesFinder;
|
||||||
$this->rootPath = $rootPath;
|
$this->rootPath = $rootPath;
|
||||||
|
@ -98,9 +98,9 @@ class Indexer
|
||||||
$this->dependenciesIndex = $dependenciesIndex;
|
$this->dependenciesIndex = $dependenciesIndex;
|
||||||
$this->sourceIndex = $sourceIndex;
|
$this->sourceIndex = $sourceIndex;
|
||||||
$this->documentLoader = $documentLoader;
|
$this->documentLoader = $documentLoader;
|
||||||
|
$this->options = $options;
|
||||||
$this->composerLock = $composerLock;
|
$this->composerLock = $composerLock;
|
||||||
$this->composerJson = $composerJson;
|
$this->composerJson = $composerJson;
|
||||||
$this->options = $options;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -232,6 +232,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
||||||
$dependenciesIndex,
|
$dependenciesIndex,
|
||||||
$sourceIndex,
|
$sourceIndex,
|
||||||
$this->documentLoader,
|
$this->documentLoader,
|
||||||
|
$initializationOptions,
|
||||||
$this->composerLock,
|
$this->composerLock,
|
||||||
$this->composerJson,
|
$this->composerJson,
|
||||||
$initializationOptions
|
$initializationOptions
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer;
|
namespace LanguageServer;
|
||||||
|
|
||||||
class Options
|
class Options
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Filetypes the indexer should process
|
* File types the indexer should process
|
||||||
*
|
*
|
||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
|
@ -14,14 +15,14 @@ class Options
|
||||||
/**
|
/**
|
||||||
* Validate/Filter input and set options for file types
|
* Validate/Filter input and set options for file types
|
||||||
*
|
*
|
||||||
* @param array $fileTypes List of file types
|
* @param string[] $fileTypes List of file types
|
||||||
*/
|
*/
|
||||||
public function setFileTypes(array $fileTypes)
|
public function setFileTypes(array $fileTypes)
|
||||||
{
|
{
|
||||||
$fileTypes = filter_var_array($fileTypes, FILTER_SANITIZE_STRING);
|
$fileTypes = filter_var_array($fileTypes, FILTER_SANITIZE_STRING);
|
||||||
$fileTypes = filter_var($fileTypes, FILTER_CALLBACK, ['options' => [$this, 'filterFileTypes']]); // validate file type format
|
$fileTypes = filter_var($fileTypes, FILTER_CALLBACK, ['options' => [$this, 'filterFileTypes']]);
|
||||||
$fileTypes = array_filter($fileTypes, 'strlen'); // filter empty items
|
$fileTypes = array_filter($fileTypes, 'strlen');
|
||||||
$fileTypes = array_values($fileTypes); //rebase indexes
|
$fileTypes = array_values($fileTypes);
|
||||||
|
|
||||||
$this->fileTypes = !empty($fileTypes) ? $fileTypes : $this->fileTypes;
|
$this->fileTypes = !empty($fileTypes) ? $fileTypes : $this->fileTypes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ class LanguageServerTest extends TestCase
|
||||||
public function testInitialize()
|
public function testInitialize()
|
||||||
{
|
{
|
||||||
$server = new LanguageServer(new MockProtocolStream, new MockProtocolStream);
|
$server = new LanguageServer(new MockProtocolStream, new MockProtocolStream);
|
||||||
$result = $server->initialize(new ClientCapabilities, __DIR__, getmypid())->wait();
|
$result = $server->initialize(new ClientCapabilities, __DIR__, getmypid(), new Options)->wait();
|
||||||
|
|
||||||
$serverCapabilities = new ServerCapabilities();
|
$serverCapabilities = new ServerCapabilities();
|
||||||
$serverCapabilities->textDocumentSync = TextDocumentSyncKind::FULL;
|
$serverCapabilities->textDocumentSync = TextDocumentSyncKind::FULL;
|
||||||
|
@ -67,7 +67,7 @@ class LanguageServerTest extends TestCase
|
||||||
});
|
});
|
||||||
$server = new LanguageServer($input, $output);
|
$server = new LanguageServer($input, $output);
|
||||||
$capabilities = new ClientCapabilities;
|
$capabilities = new ClientCapabilities;
|
||||||
$server->initialize($capabilities, realpath(__DIR__ . '/../fixtures'), getmypid());
|
$server->initialize($capabilities, realpath(__DIR__ . '/../fixtures'), getmypid(), new Options);
|
||||||
$promise->wait();
|
$promise->wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ class LanguageServerTest extends TestCase
|
||||||
$capabilities = new ClientCapabilities;
|
$capabilities = new ClientCapabilities;
|
||||||
$capabilities->xfilesProvider = true;
|
$capabilities->xfilesProvider = true;
|
||||||
$capabilities->xcontentProvider = true;
|
$capabilities->xcontentProvider = true;
|
||||||
$server->initialize($capabilities, $rootPath, getmypid());
|
$server->initialize($capabilities, $rootPath, getmypid(), new Options);
|
||||||
$promise->wait();
|
$promise->wait();
|
||||||
$this->assertTrue($filesCalled);
|
$this->assertTrue($filesCalled);
|
||||||
$this->assertTrue($contentCalled);
|
$this->assertTrue($contentCalled);
|
||||||
|
@ -127,24 +127,22 @@ class LanguageServerTest extends TestCase
|
||||||
$input = new MockProtocolStream;
|
$input = new MockProtocolStream;
|
||||||
$output = new MockProtocolStream;
|
$output = new MockProtocolStream;
|
||||||
$options = new Options;
|
$options = new Options;
|
||||||
|
|
||||||
$options->setFileTypes([
|
$options->setFileTypes([
|
||||||
'.php',
|
'.php',
|
||||||
'.inc'
|
'.inc'
|
||||||
]);
|
]);
|
||||||
|
$output->on('message', function (Message $msg) use ($promise, &$allFilesParsed) {
|
||||||
$output->on('message', function (Message $msg) use ($promise, &$foundFiles) {
|
|
||||||
if ($msg->body->method === 'window/logMessage' && $promise->state === Promise::PENDING) {
|
if ($msg->body->method === 'window/logMessage' && $promise->state === Promise::PENDING) {
|
||||||
if ($msg->body->params->type === MessageType::ERROR) {
|
if ($msg->body->params->type === MessageType::ERROR) {
|
||||||
$promise->reject(new Exception($msg->body->params->message));
|
$promise->reject(new Exception($msg->body->params->message));
|
||||||
} else if (strpos($msg->body->params->message, 'All 27 PHP files parsed') !== false) {
|
} elseif (preg_match('/All \d+ PHP files parsed/', $msg->body->params->message)) {
|
||||||
$promise->fulfill();
|
$promise->fulfill(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$server = new LanguageServer($input, $output);
|
$server = new LanguageServer($input, $output);
|
||||||
$capabilities = new ClientCapabilities;
|
$capabilities = new ClientCapabilities;
|
||||||
$server->initialize($capabilities, realpath(__DIR__ . '/../fixtures'), getmypid(), $options);
|
$server->initialize($capabilities, realpath(__DIR__ . '/../fixtures'), getmypid(), $options);
|
||||||
$promise->wait();
|
$this->assertTrue($promise->wait());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,153 +0,0 @@
|
||||||
<?php
|
|
||||||
declare(strict_types = 1);
|
|
||||||
|
|
||||||
namespace LanguageServer\Tests\Server\Workspace;
|
|
||||||
|
|
||||||
use LanguageServer\Tests\Server\ServerTestCase;
|
|
||||||
use LanguageServer\Tests\MockProtocolStream;
|
|
||||||
use LanguageServer\{Server, LanguageClient, PhpDocumentLoader, DefinitionResolver, Options, Indexer};
|
|
||||||
use LanguageServer\Index\{ProjectIndex, StubsIndex, GlobalIndex, DependenciesIndex, Index};
|
|
||||||
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
|
|
||||||
use LanguageServer\Protocol\{Position, Location, Range, ClientCapabilities, Message, MessageType};
|
|
||||||
use LanguageServer\FilesFinder\FileSystemFilesFinder;
|
|
||||||
use LanguageServer\Cache\FileSystemCache;
|
|
||||||
use LanguageServer\Server\Workspace;
|
|
||||||
use Sabre\Event\Promise;
|
|
||||||
use Exception;
|
|
||||||
|
|
||||||
class DidChangeConfigurationTest extends ServerTestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* didChangeConfiguration does not need to do anything when no options/settings are passed
|
|
||||||
*/
|
|
||||||
public function testNoOptionPassed()
|
|
||||||
{
|
|
||||||
$client = new LanguageClient(new MockProtocolStream(), $writer = new MockProtocolStream());
|
|
||||||
$projectIndex = new ProjectIndex($sourceIndex = new Index(), $dependenciesIndex = new DependenciesIndex());
|
|
||||||
$definitionResolver = new DefinitionResolver($projectIndex);
|
|
||||||
$loader = new PhpDocumentLoader(new FileSystemContentRetriever(), $projectIndex, $definitionResolver);
|
|
||||||
$workspace = new Server\Workspace($client, $projectIndex, $dependenciesIndex, $sourceIndex, null, $loader, null);
|
|
||||||
|
|
||||||
$result = $workspace->didChangeConfiguration();
|
|
||||||
$this->assertFalse($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* When the passed options/settings do not differ from the previous, it has nothing to do
|
|
||||||
*/
|
|
||||||
public function testFailsWithInvalidOptionsTypeOrFormat()
|
|
||||||
{
|
|
||||||
$options = new Options;
|
|
||||||
$client = new LanguageClient(new MockProtocolStream(), $writer = new MockProtocolStream());
|
|
||||||
$projectIndex = new ProjectIndex($sourceIndex = new Index(), $dependenciesIndex = new DependenciesIndex());
|
|
||||||
$definitionResolver = new DefinitionResolver($projectIndex);
|
|
||||||
$loader = new PhpDocumentLoader(new FileSystemContentRetriever(), $projectIndex, $definitionResolver);
|
|
||||||
$workspace = new Server\Workspace($client, $projectIndex, $dependenciesIndex, $sourceIndex, null, $loader, null, null, null, null, $options);
|
|
||||||
|
|
||||||
$this->expectException(\Exception::class);
|
|
||||||
$this->workspace->didChangeConfiguration(['invalid' => 'options format']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* When the passed options/settings do not differ from the previous, it has nothing to do
|
|
||||||
*/
|
|
||||||
public function testNoChangedOptions()
|
|
||||||
{
|
|
||||||
$options = new Options;
|
|
||||||
$client = new LanguageClient(new MockProtocolStream(), $writer = new MockProtocolStream());
|
|
||||||
$projectIndex = new ProjectIndex($sourceIndex = new Index(), $dependenciesIndex = new DependenciesIndex());
|
|
||||||
$definitionResolver = new DefinitionResolver($projectIndex);
|
|
||||||
$loader = new PhpDocumentLoader(new FileSystemContentRetriever(), $projectIndex, $definitionResolver);
|
|
||||||
$workspace = new Server\Workspace($client, $projectIndex, $dependenciesIndex, $sourceIndex, null, $loader, null, null, null, null, $options);
|
|
||||||
|
|
||||||
$result = $this->workspace->didChangeConfiguration($options);
|
|
||||||
$this->assertFalse($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verify that the required methods for a reindex are called
|
|
||||||
*/
|
|
||||||
public function testFileTypesOptionTriggersAReindex()
|
|
||||||
{
|
|
||||||
$sourceIndex = new Index;
|
|
||||||
$dependenciesIndex = new DependenciesIndex;
|
|
||||||
$projectIndex = $this->getMockBuilder('LanguageServer\Index\ProjectIndex')
|
|
||||||
->setConstructorArgs([$sourceIndex, $dependenciesIndex])
|
|
||||||
->setMethods(['wipe'])
|
|
||||||
->getMock();
|
|
||||||
$projectIndex->setComplete();
|
|
||||||
|
|
||||||
$rootPath = realpath(__DIR__ . '/../../../fixtures/');
|
|
||||||
$filesFinder = new FileSystemFilesFinder;
|
|
||||||
$cache = new FileSystemCache;
|
|
||||||
|
|
||||||
$definitionResolver = new DefinitionResolver($projectIndex);
|
|
||||||
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
|
|
||||||
$documentLoader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver);
|
|
||||||
$textDocument = new Server\TextDocument($documentLoader, $definitionResolver, $client, $projectIndex);
|
|
||||||
$indexer = $this->getMockBuilder('LanguageServer\Indexer')
|
|
||||||
->setConstructorArgs([$filesFinder, $rootPath, $client, $cache, $dependenciesIndex, $sourceIndex, $documentLoader, null, null, new Options])
|
|
||||||
->setMethods(['index'])
|
|
||||||
->getMock();
|
|
||||||
$workspace = new Server\Workspace($client, $projectIndex, $dependenciesIndex, $sourceIndex, null, $documentLoader, null, $indexer, new Options);
|
|
||||||
|
|
||||||
|
|
||||||
$options = new Options;
|
|
||||||
$options->fileTypes = [
|
|
||||||
'.inc'
|
|
||||||
];
|
|
||||||
|
|
||||||
$projectIndex->expects($this->once())->method('wipe');
|
|
||||||
$indexer->expects($this->once())->method('index');
|
|
||||||
|
|
||||||
// invoke event
|
|
||||||
$result = $workspace->didChangeConfiguration($options);
|
|
||||||
$this->assertTrue($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Be sure that the indexer gets the new options/settings and uses them
|
|
||||||
*/
|
|
||||||
public function testIndexerUsesNewOptions()
|
|
||||||
{
|
|
||||||
$promise = new Promise;
|
|
||||||
$sourceIndex = new Index;
|
|
||||||
$dependenciesIndex = new DependenciesIndex;
|
|
||||||
$projectIndex = new ProjectIndex($sourceIndex, $dependenciesIndex);
|
|
||||||
$projectIndex->setComplete();
|
|
||||||
|
|
||||||
$rootPath = realpath(__DIR__ . '/../../../fixtures/');
|
|
||||||
$filesFinder = new FileSystemFilesFinder;
|
|
||||||
$cache = new FileSystemCache;
|
|
||||||
$initialOptions = new Options;
|
|
||||||
|
|
||||||
$input = new MockProtocolStream;
|
|
||||||
$output = new MockProtocolStream;
|
|
||||||
|
|
||||||
$definitionResolver = new DefinitionResolver($projectIndex);
|
|
||||||
$client = new LanguageClient($input, $output);
|
|
||||||
$documentLoader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver);
|
|
||||||
$textDocument = new Server\TextDocument($documentLoader, $definitionResolver, $client, $projectIndex);
|
|
||||||
$indexer = new Indexer($filesFinder, $rootPath, $client, $cache, $dependenciesIndex, $sourceIndex, $documentLoader, null, null, $initialOptions);
|
|
||||||
$workspace = new Server\Workspace($client, $projectIndex, $dependenciesIndex, $sourceIndex, null, $documentLoader, null, $indexer, $initialOptions);
|
|
||||||
|
|
||||||
$output->on('message', function (Message $msg) use ($promise) {
|
|
||||||
if ($msg->body->method === 'window/logMessage' && $promise->state === Promise::PENDING) {
|
|
||||||
if ($msg->body->params->type === MessageType::ERROR) {
|
|
||||||
$promise->reject(new Exception($msg->body->params->message));
|
|
||||||
} elseif (strpos($msg->body->params->message, 'All 1 PHP files parsed') !== false) {
|
|
||||||
$promise->fulfill();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$options = new Options;
|
|
||||||
$options->fileTypes = [
|
|
||||||
'.inc'
|
|
||||||
];
|
|
||||||
|
|
||||||
$result = $workspace->didChangeConfiguration($options);
|
|
||||||
$this->assertTrue($result);
|
|
||||||
$promise->wait();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue