diff --git a/src/PhpDocument.php b/src/PhpDocument.php index 75badca..214f97b 100644 --- a/src/PhpDocument.php +++ b/src/PhpDocument.php @@ -19,6 +19,7 @@ use phpDocumentor\Reflection\DocBlockFactory; use function LanguageServer\Fqn\{getDefinedFqn, getVariableDefinition, getReferencedFqn}; use Sabre\Event\Promise; use function Sabre\Event\coroutine; +use Sabre\Uri; class PhpDocument { @@ -208,7 +209,20 @@ class PhpDocument $this->stmts = $stmts; } - $this->client->textDocument->publishDiagnostics($this->uri, $diagnostics); + if (!$this->isVendored()) { + $this->client->textDocument->publishDiagnostics($this->uri, $diagnostics); + } + } + + /** + * Returns true if the document is a dependency + * + * @return bool + */ + public function isVendored(): bool + { + $path = Uri\parse($this->uri)['path']; + return strpos($path, '/vendor/') !== false; } /** diff --git a/tests/PhpDocumentTest.php b/tests/PhpDocumentTest.php index 5cdc8c8..057551e 100644 --- a/tests/PhpDocumentTest.php +++ b/tests/PhpDocumentTest.php @@ -37,4 +37,22 @@ class PhpDocumentTest extends TestCase $this->assertInstanceOf(Node\Name\FullyQualified::class, $node); $this->assertEquals('SomeClass', (string)$node); } + + public function testIsVendored() + { + $document = $this->project->openDocument('file:///dir/vendor/x.php', "assertEquals(true, $document->isVendored()); + + $document = $this->project->openDocument('file:///c:/dir/vendor/x.php', "assertEquals(true, $document->isVendored()); + + $document = $this->project->openDocument('file:///vendor/x.php', "assertEquals(true, $document->isVendored()); + + $document = $this->project->openDocument('file:///dir/vendor.php', "assertEquals(false, $document->isVendored()); + + $document = $this->project->openDocument('file:///dir/x.php', "assertEquals(false, $document->isVendored()); + } }