Merge branch 'master' into jens1o-support-constuctor
commit
3039d63088
|
@ -180,7 +180,7 @@ Example:
|
||||||
- [VS Code PHP IntelliSense](https://github.com/felixfbecker/vscode-php-intellisense)
|
- [VS Code PHP IntelliSense](https://github.com/felixfbecker/vscode-php-intellisense)
|
||||||
- [Eclipse Che](https://eclipse.org/che/)
|
- [Eclipse Che](https://eclipse.org/che/)
|
||||||
- [Eclipse IDE (LSP4E-PHP)](https://github.com/eclipselabs/lsp4e-php)
|
- [Eclipse IDE (LSP4E-PHP)](https://github.com/eclipselabs/lsp4e-php)
|
||||||
- [Neovim (nvim-cm-php-language-server)](https://github.com/roxma/nvim-cm-php-language-server)
|
- NeoVim: [LanguageServer-php-neovim](https://github.com/roxma/LanguageServer-php-neovim) with [LanguageClient neovim](https://github.com/autozimu/LanguageClient-neovim)
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
"phpdocumentor/reflection-docblock": "^3.0",
|
"phpdocumentor/reflection-docblock": "^3.0",
|
||||||
"sabre/event": "^5.0",
|
"sabre/event": "^5.0",
|
||||||
"felixfbecker/advanced-json-rpc": "^2.0",
|
"felixfbecker/advanced-json-rpc": "^2.0",
|
||||||
"squizlabs/php_codesniffer" : "^3.0",
|
"squizlabs/php_codesniffer" : "3.0.0RC3",
|
||||||
"netresearch/jsonmapper": "^1.0",
|
"netresearch/jsonmapper": "^1.0",
|
||||||
"webmozart/path-util": "^2.3",
|
"webmozart/path-util": "^2.3",
|
||||||
"webmozart/glob": "^4.1",
|
"webmozart/glob": "^4.1",
|
||||||
|
|
|
@ -11,4 +11,7 @@
|
||||||
<directory>./src</directory>
|
<directory>./src</directory>
|
||||||
</whitelist>
|
</whitelist>
|
||||||
</filter>
|
</filter>
|
||||||
|
<php>
|
||||||
|
<ini name="memory_limit" value="256M"/>
|
||||||
|
</php>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|
|
@ -89,8 +89,15 @@ class DefinitionResolver
|
||||||
} else {
|
} else {
|
||||||
$docBlock = $node->getAttribute('docBlock');
|
$docBlock = $node->getAttribute('docBlock');
|
||||||
if ($docBlock !== null) {
|
if ($docBlock !== null) {
|
||||||
|
// check wether we have a description, when true, add a new paragraph
|
||||||
|
// with the description
|
||||||
|
$description = $docBlock->getDescription()->render();
|
||||||
|
|
||||||
|
if (empty($description)) {
|
||||||
return $docBlock->getSummary();
|
return $docBlock->getSummary();
|
||||||
}
|
}
|
||||||
|
return $docBlock->getSummary() . "\n\n" . $description;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,7 +446,7 @@ class DefinitionResolver
|
||||||
// Cannot get type for dynamic function call
|
// Cannot get type for dynamic function call
|
||||||
return new Types\Mixed;
|
return new Types\Mixed;
|
||||||
}
|
}
|
||||||
$fqn = (string)($expr->getAttribute('namespacedName') ?? $expr->name);
|
$fqn = (string)($expr->getAttribute('namespacedName') ?? $expr->name) . '()';
|
||||||
$def = $this->index->getDefinition($fqn, true);
|
$def = $this->index->getDefinition($fqn, true);
|
||||||
if ($def !== null) {
|
if ($def !== null) {
|
||||||
return $def->type;
|
return $def->type;
|
||||||
|
|
|
@ -253,6 +253,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
||||||
}
|
}
|
||||||
if ($this->workspace === null) {
|
if ($this->workspace === null) {
|
||||||
$this->workspace = new Server\Workspace(
|
$this->workspace = new Server\Workspace(
|
||||||
|
$this->client,
|
||||||
$this->projectIndex,
|
$this->projectIndex,
|
||||||
$dependenciesIndex,
|
$dependenciesIndex,
|
||||||
$sourceIndex,
|
$sourceIndex,
|
||||||
|
|
|
@ -20,4 +20,14 @@ class FileEvent
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
public $type;
|
public $type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $uri
|
||||||
|
* @param int $type
|
||||||
|
*/
|
||||||
|
public function __construct(string $uri, int $type)
|
||||||
|
{
|
||||||
|
$this->uri = $uri;
|
||||||
|
$this->type = $type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,15 @@ namespace LanguageServer\Server;
|
||||||
|
|
||||||
use LanguageServer\{LanguageClient, Project, PhpDocumentLoader};
|
use LanguageServer\{LanguageClient, Project, PhpDocumentLoader};
|
||||||
use LanguageServer\Index\{ProjectIndex, DependenciesIndex, Index};
|
use LanguageServer\Index\{ProjectIndex, DependenciesIndex, Index};
|
||||||
use LanguageServer\Protocol\{SymbolInformation, SymbolDescriptor, ReferenceInformation, DependencyReference, Location};
|
use LanguageServer\Protocol\{
|
||||||
|
FileChangeType,
|
||||||
|
FileEvent,
|
||||||
|
SymbolInformation,
|
||||||
|
SymbolDescriptor,
|
||||||
|
ReferenceInformation,
|
||||||
|
DependencyReference,
|
||||||
|
Location
|
||||||
|
};
|
||||||
use Sabre\Event\Promise;
|
use Sabre\Event\Promise;
|
||||||
use function Sabre\Event\coroutine;
|
use function Sabre\Event\coroutine;
|
||||||
use function LanguageServer\{waitForEvent, getPackageName};
|
use function LanguageServer\{waitForEvent, getPackageName};
|
||||||
|
@ -15,6 +23,11 @@ use function LanguageServer\{waitForEvent, getPackageName};
|
||||||
*/
|
*/
|
||||||
class Workspace
|
class Workspace
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var LanguageClient
|
||||||
|
*/
|
||||||
|
public $client;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The symbol index for the workspace
|
* The symbol index for the workspace
|
||||||
*
|
*
|
||||||
|
@ -43,14 +56,16 @@ class Workspace
|
||||||
public $documentLoader;
|
public $documentLoader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param LanguageClient $client LanguageClient instance used to signal updated results
|
||||||
* @param ProjectIndex $index Index that is searched on a workspace/symbol request
|
* @param ProjectIndex $index Index that is searched on a workspace/symbol request
|
||||||
* @param DependenciesIndex $dependenciesIndex Index that is used on a workspace/xreferences request
|
* @param DependenciesIndex $dependenciesIndex Index that is used on a workspace/xreferences request
|
||||||
* @param DependenciesIndex $sourceIndex Index that is used on a workspace/xreferences request
|
* @param DependenciesIndex $sourceIndex Index that is used on a workspace/xreferences request
|
||||||
* @param \stdClass $composerLock The parsed composer.lock of the project, if any
|
* @param \stdClass $composerLock The parsed composer.lock of the project, if any
|
||||||
* @param PhpDocumentLoader $documentLoader PhpDocumentLoader instance to load documents
|
* @param PhpDocumentLoader $documentLoader PhpDocumentLoader instance to load documents
|
||||||
*/
|
*/
|
||||||
public function __construct(ProjectIndex $index, DependenciesIndex $dependenciesIndex, Index $sourceIndex, \stdClass $composerLock = null, PhpDocumentLoader $documentLoader, \stdClass $composerJson = null)
|
public function __construct(LanguageClient $client, ProjectIndex $index, DependenciesIndex $dependenciesIndex, Index $sourceIndex, \stdClass $composerLock = null, PhpDocumentLoader $documentLoader, \stdClass $composerJson = null)
|
||||||
{
|
{
|
||||||
|
$this->client = $client;
|
||||||
$this->sourceIndex = $sourceIndex;
|
$this->sourceIndex = $sourceIndex;
|
||||||
$this->index = $index;
|
$this->index = $index;
|
||||||
$this->dependenciesIndex = $dependenciesIndex;
|
$this->dependenciesIndex = $dependenciesIndex;
|
||||||
|
@ -82,6 +97,21 @@ class Workspace
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The watched files notification is sent from the client to the server when the client detects changes to files watched by the language client.
|
||||||
|
*
|
||||||
|
* @param FileEvent[] $changes
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function didChangeWatchedFiles(array $changes)
|
||||||
|
{
|
||||||
|
foreach ($changes as $change) {
|
||||||
|
if ($change->type === FileChangeType::DELETED) {
|
||||||
|
$this->client->textDocument->publishDiagnostics($change->uri, []);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The workspace references request is sent from the client to the server to locate project-wide references to a symbol given its description / metadata.
|
* The workspace references request is sent from the client to the server to locate project-wide references to a symbol given its description / metadata.
|
||||||
*
|
*
|
||||||
|
|
|
@ -54,7 +54,7 @@ abstract class ServerTestCase extends TestCase
|
||||||
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
|
$client = new LanguageClient(new MockProtocolStream, new MockProtocolStream);
|
||||||
$this->documentLoader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver);
|
$this->documentLoader = new PhpDocumentLoader(new FileSystemContentRetriever, $projectIndex, $definitionResolver);
|
||||||
$this->textDocument = new Server\TextDocument($this->documentLoader, $definitionResolver, $client, $projectIndex);
|
$this->textDocument = new Server\TextDocument($this->documentLoader, $definitionResolver, $client, $projectIndex);
|
||||||
$this->workspace = new Server\Workspace($projectIndex, $dependenciesIndex, $sourceIndex, null, $this->documentLoader);
|
$this->workspace = new Server\Workspace($client, $projectIndex, $dependenciesIndex, $sourceIndex, null, $this->documentLoader);
|
||||||
|
|
||||||
$globalSymbolsUri = pathToUri(realpath(__DIR__ . '/../../fixtures/global_symbols.php'));
|
$globalSymbolsUri = pathToUri(realpath(__DIR__ . '/../../fixtures/global_symbols.php'));
|
||||||
$globalReferencesUri = pathToUri(realpath(__DIR__ . '/../../fixtures/global_references.php'));
|
$globalReferencesUri = pathToUri(realpath(__DIR__ . '/../../fixtures/global_references.php'));
|
||||||
|
|
|
@ -160,7 +160,12 @@ class CompletionTest extends TestCase
|
||||||
'TestClass',
|
'TestClass',
|
||||||
CompletionItemKind::CLASS_,
|
CompletionItemKind::CLASS_,
|
||||||
null,
|
null,
|
||||||
'Pariatur ut laborum tempor voluptate consequat ea deserunt.',
|
'Pariatur ut laborum tempor voluptate consequat ea deserunt.' . "\n\n" .
|
||||||
|
'Deserunt enim minim sunt sint ea nisi. Deserunt excepteur tempor id nostrud' . "\n" .
|
||||||
|
'laboris commodo ad commodo velit mollit qui non officia id. Nulla duis veniam' . "\n" .
|
||||||
|
'veniam officia deserunt et non dolore mollit ea quis eiusmod sit non. Occaecat' . "\n" .
|
||||||
|
'consequat sunt culpa exercitation pariatur id reprehenderit nisi incididunt Lorem' . "\n" .
|
||||||
|
'sint. Officia culpa pariatur laborum nostrud cupidatat consequat mollit.',
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
'\TestClass'
|
'\TestClass'
|
||||||
|
@ -179,7 +184,12 @@ class CompletionTest extends TestCase
|
||||||
'TestClass',
|
'TestClass',
|
||||||
CompletionItemKind::CLASS_,
|
CompletionItemKind::CLASS_,
|
||||||
'TestNamespace',
|
'TestNamespace',
|
||||||
'Pariatur ut laborum tempor voluptate consequat ea deserunt.',
|
'Pariatur ut laborum tempor voluptate consequat ea deserunt.' . "\n\n" .
|
||||||
|
'Deserunt enim minim sunt sint ea nisi. Deserunt excepteur tempor id nostrud' . "\n" .
|
||||||
|
'laboris commodo ad commodo velit mollit qui non officia id. Nulla duis veniam' . "\n" .
|
||||||
|
'veniam officia deserunt et non dolore mollit ea quis eiusmod sit non. Occaecat' . "\n" .
|
||||||
|
'consequat sunt culpa exercitation pariatur id reprehenderit nisi incididunt Lorem' . "\n" .
|
||||||
|
'sint. Officia culpa pariatur laborum nostrud cupidatat consequat mollit.',
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
'TestClass'
|
'TestClass'
|
||||||
|
@ -218,7 +228,12 @@ class CompletionTest extends TestCase
|
||||||
'TestClass',
|
'TestClass',
|
||||||
CompletionItemKind::CLASS_,
|
CompletionItemKind::CLASS_,
|
||||||
'TestNamespace',
|
'TestNamespace',
|
||||||
'Pariatur ut laborum tempor voluptate consequat ea deserunt.'
|
'Pariatur ut laborum tempor voluptate consequat ea deserunt.' . "\n\n" .
|
||||||
|
'Deserunt enim minim sunt sint ea nisi. Deserunt excepteur tempor id nostrud' . "\n" .
|
||||||
|
'laboris commodo ad commodo velit mollit qui non officia id. Nulla duis veniam' . "\n" .
|
||||||
|
'veniam officia deserunt et non dolore mollit ea quis eiusmod sit non. Occaecat' . "\n" .
|
||||||
|
'consequat sunt culpa exercitation pariatur id reprehenderit nisi incididunt Lorem' . "\n" .
|
||||||
|
'sint. Officia culpa pariatur laborum nostrud cupidatat consequat mollit.'
|
||||||
)
|
)
|
||||||
], true), $items);
|
], true), $items);
|
||||||
}
|
}
|
||||||
|
@ -356,7 +371,12 @@ class CompletionTest extends TestCase
|
||||||
'TestClass',
|
'TestClass',
|
||||||
CompletionItemKind::CLASS_,
|
CompletionItemKind::CLASS_,
|
||||||
null,
|
null,
|
||||||
'Pariatur ut laborum tempor voluptate consequat ea deserunt.',
|
'Pariatur ut laborum tempor voluptate consequat ea deserunt.' . "\n\n" .
|
||||||
|
'Deserunt enim minim sunt sint ea nisi. Deserunt excepteur tempor id nostrud' . "\n" .
|
||||||
|
'laboris commodo ad commodo velit mollit qui non officia id. Nulla duis veniam' . "\n" .
|
||||||
|
'veniam officia deserunt et non dolore mollit ea quis eiusmod sit non. Occaecat' . "\n" .
|
||||||
|
'consequat sunt culpa exercitation pariatur id reprehenderit nisi incididunt Lorem' . "\n" .
|
||||||
|
'sint. Officia culpa pariatur laborum nostrud cupidatat consequat mollit.',
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
'TestClass'
|
'TestClass'
|
||||||
|
|
|
@ -22,7 +22,12 @@ class HoverTest extends ServerTestCase
|
||||||
)->wait();
|
)->wait();
|
||||||
$this->assertEquals(new Hover([
|
$this->assertEquals(new Hover([
|
||||||
new MarkedString('php', "<?php\nclass TestClass implements \\TestInterface"),
|
new MarkedString('php', "<?php\nclass TestClass implements \\TestInterface"),
|
||||||
'Pariatur ut laborum tempor voluptate consequat ea deserunt.'
|
'Pariatur ut laborum tempor voluptate consequat ea deserunt.' . "\n\n" .
|
||||||
|
'Deserunt enim minim sunt sint ea nisi. Deserunt excepteur tempor id nostrud' . "\n" .
|
||||||
|
'laboris commodo ad commodo velit mollit qui non officia id. Nulla duis veniam' . "\n" .
|
||||||
|
'veniam officia deserunt et non dolore mollit ea quis eiusmod sit non. Occaecat' . "\n" .
|
||||||
|
'consequat sunt culpa exercitation pariatur id reprehenderit nisi incididunt Lorem' . "\n" .
|
||||||
|
'sint. Officia culpa pariatur laborum nostrud cupidatat consequat mollit.'
|
||||||
], $reference->range), $result);
|
], $reference->range), $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +42,12 @@ class HoverTest extends ServerTestCase
|
||||||
)->wait();
|
)->wait();
|
||||||
$this->assertEquals(new Hover([
|
$this->assertEquals(new Hover([
|
||||||
new MarkedString('php', "<?php\nclass TestClass implements \\TestInterface"),
|
new MarkedString('php', "<?php\nclass TestClass implements \\TestInterface"),
|
||||||
'Pariatur ut laborum tempor voluptate consequat ea deserunt.'
|
'Pariatur ut laborum tempor voluptate consequat ea deserunt.' . "\n\n" .
|
||||||
|
'Deserunt enim minim sunt sint ea nisi. Deserunt excepteur tempor id nostrud' . "\n" .
|
||||||
|
'laboris commodo ad commodo velit mollit qui non officia id. Nulla duis veniam' . "\n" .
|
||||||
|
'veniam officia deserunt et non dolore mollit ea quis eiusmod sit non. Occaecat' . "\n" .
|
||||||
|
'consequat sunt culpa exercitation pariatur id reprehenderit nisi incididunt Lorem' . "\n" .
|
||||||
|
'sint. Officia culpa pariatur laborum nostrud cupidatat consequat mollit.'
|
||||||
], $definition->range), $result);
|
], $definition->range), $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,7 +191,12 @@ class HoverTest extends ServerTestCase
|
||||||
$result = $this->textDocument->hover(new TextDocumentIdentifier($uri), new Position(59, 11))->wait();
|
$result = $this->textDocument->hover(new TextDocumentIdentifier($uri), new Position(59, 11))->wait();
|
||||||
$this->assertEquals(new Hover([
|
$this->assertEquals(new Hover([
|
||||||
new MarkedString('php', "<?php\nclass TestClass implements \\TestInterface"),
|
new MarkedString('php', "<?php\nclass TestClass implements \\TestInterface"),
|
||||||
'Pariatur ut laborum tempor voluptate consequat ea deserunt.'
|
'Pariatur ut laborum tempor voluptate consequat ea deserunt.' . "\n\n" .
|
||||||
|
'Deserunt enim minim sunt sint ea nisi. Deserunt excepteur tempor id nostrud' . "\n" .
|
||||||
|
'laboris commodo ad commodo velit mollit qui non officia id. Nulla duis veniam' . "\n" .
|
||||||
|
'veniam officia deserunt et non dolore mollit ea quis eiusmod sit non. Occaecat' . "\n" .
|
||||||
|
'consequat sunt culpa exercitation pariatur id reprehenderit nisi incididunt Lorem' . "\n" .
|
||||||
|
'sint. Officia culpa pariatur laborum nostrud cupidatat consequat mollit.'
|
||||||
], new Range(new Position(59, 8), new Position(59, 13))), $result);
|
], new Range(new Position(59, 8), new Position(59, 13))), $result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace LanguageServer\Tests\Server\Workspace;
|
||||||
|
|
||||||
|
use LanguageServer\ContentRetriever\FileSystemContentRetriever;
|
||||||
|
use LanguageServer\{DefinitionResolver, LanguageClient, PhpDocumentLoader, Server};
|
||||||
|
use LanguageServer\Index\{DependenciesIndex, Index, ProjectIndex};
|
||||||
|
use LanguageServer\Protocol\{FileChangeType, FileEvent, Message};
|
||||||
|
use LanguageServer\Tests\MockProtocolStream;
|
||||||
|
use LanguageServer\Tests\Server\ServerTestCase;
|
||||||
|
use LanguageServer\Server\Workspace;
|
||||||
|
use Sabre\Event\Loop;
|
||||||
|
|
||||||
|
class DidChangeWatchedFilesTest extends ServerTestCase
|
||||||
|
{
|
||||||
|
public function testDeletingFileClearsAllDiagnostics()
|
||||||
|
{
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$fileEvent = new FileEvent('my uri', FileChangeType::DELETED);
|
||||||
|
|
||||||
|
$isDiagnosticsCleared = false;
|
||||||
|
$writer->on('message', function (Message $message) use ($fileEvent, &$isDiagnosticsCleared) {
|
||||||
|
if ($message->body->method === "textDocument/publishDiagnostics") {
|
||||||
|
$this->assertEquals($message->body->params->uri, $fileEvent->uri);
|
||||||
|
$this->assertEquals($message->body->params->diagnostics, []);
|
||||||
|
$isDiagnosticsCleared = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$workspace->didChangeWatchedFiles([$fileEvent]);
|
||||||
|
Loop\tick(true);
|
||||||
|
|
||||||
|
$this->assertTrue($isDiagnosticsCleared, "Deleting file should clear all diagnostics.");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue