parent
4cf3fefd09
commit
ed922e1d24
|
@ -46,7 +46,7 @@ class ProjectIndex extends AbstractAggregateIndex
|
||||||
*/
|
*/
|
||||||
public function getIndexForUri(string $uri): Index
|
public function getIndexForUri(string $uri): Index
|
||||||
{
|
{
|
||||||
$packageName = getPackageName($this->composerJson, $uri);
|
$packageName = getPackageName($uri, $this->composerJson);
|
||||||
if ($packageName) {
|
if ($packageName) {
|
||||||
return $this->dependenciesIndex->getDependencyIndex($packageName);
|
return $this->dependenciesIndex->getDependencyIndex($packageName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,7 @@ class Indexer
|
||||||
$deps = [];
|
$deps = [];
|
||||||
|
|
||||||
foreach ($uris as $uri) {
|
foreach ($uris as $uri) {
|
||||||
$packageName = getPackageName($this->composerJson, $uri);
|
$packageName = getPackageName($uri, $this->composerJson);
|
||||||
if ($this->composerLock !== null && $packageName) {
|
if ($this->composerLock !== null && $packageName) {
|
||||||
// Dependency file
|
// Dependency file
|
||||||
if (!isset($deps[$packageName])) {
|
if (!isset($deps[$packageName])) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ use LanguageServer\Index\ReadableIndex;
|
||||||
use Sabre\Event\Promise;
|
use Sabre\Event\Promise;
|
||||||
use Sabre\Uri;
|
use Sabre\Uri;
|
||||||
use function Sabre\Event\coroutine;
|
use function Sabre\Event\coroutine;
|
||||||
use function LanguageServer\waitForEvent;
|
use function LanguageServer\{waitForEvent,isVendored};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides method handlers for all textDocument/* methods
|
* Provides method handlers for all textDocument/* methods
|
||||||
|
@ -134,7 +134,7 @@ class TextDocument
|
||||||
public function didOpen(TextDocumentItem $textDocument)
|
public function didOpen(TextDocumentItem $textDocument)
|
||||||
{
|
{
|
||||||
$document = $this->documentLoader->open($textDocument->uri, $textDocument->text);
|
$document = $this->documentLoader->open($textDocument->uri, $textDocument->text);
|
||||||
if (!\LanguageServer\isVendored($document, $this->composerJson)) {
|
if (!isVendored($document, $this->composerJson)) {
|
||||||
$this->client->textDocument->publishDiagnostics($textDocument->uri, $document->getDiagnostics());
|
$this->client->textDocument->publishDiagnostics($textDocument->uri, $document->getDiagnostics());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -409,9 +409,9 @@ class TextDocument
|
||||||
$symbol->$prop = $val;
|
$symbol->$prop = $val;
|
||||||
}
|
}
|
||||||
$symbol->fqsen = $def->fqn;
|
$symbol->fqsen = $def->fqn;
|
||||||
if (preg_match('/\/vendor\/([^\/]+\/[^\/]+)\//', $def->symbolInformation->location->uri, $matches) && $this->composerLock !== null) {
|
$packageName = getPackageName($def->symbolInformation->location->uri, $this->composerJson);
|
||||||
|
if ($packageName && $this->composerLock !== null) {
|
||||||
// Definition is inside a dependency
|
// Definition is inside a dependency
|
||||||
$packageName = $matches[1];
|
|
||||||
foreach (array_merge($this->composerLock->packages, $this->composerLock->{'packages-dev'}) as $package) {
|
foreach (array_merge($this->composerLock->packages, $this->composerLock->{'packages-dev'}) as $package) {
|
||||||
if ($package->name === $packageName) {
|
if ($package->name === $packageName) {
|
||||||
$symbol->package = $package;
|
$symbol->package = $package;
|
||||||
|
|
|
@ -8,8 +8,7 @@ use LanguageServer\Index\{ProjectIndex, DependenciesIndex, Index};
|
||||||
use LanguageServer\Protocol\{SymbolInformation, SymbolDescriptor, ReferenceInformation, DependencyReference, Location};
|
use LanguageServer\Protocol\{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;
|
use function LanguageServer\{waitForEvent,getPackageName};
|
||||||
use function LanguageServer\getPackageName;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides method handlers for all workspace/* methods
|
* Provides method handlers for all workspace/* methods
|
||||||
|
@ -124,7 +123,7 @@ class Workspace
|
||||||
$symbol->$prop = $val;
|
$symbol->$prop = $val;
|
||||||
}
|
}
|
||||||
// Find out package name
|
// Find out package name
|
||||||
$packageName = getPackageName($this->composerJson, $def->symbolInformation->location->uri);
|
$packageName = getPackageName($def->symbolInformation->location->uri, $this->composerJson);
|
||||||
foreach (array_merge($this->composerLock->packages, $this->composerLock->{'packages-dev'}) as $package) {
|
foreach (array_merge($this->composerLock->packages, $this->composerLock->{'packages-dev'}) as $package) {
|
||||||
if ($package->name === $packageName) {
|
if ($package->name === $packageName) {
|
||||||
$symbol->package = $package;
|
$symbol->package = $package;
|
||||||
|
|
|
@ -169,13 +169,13 @@ function isVendored(PhpDocument $document, \stdClass $composerJson = null): bool
|
||||||
* @param \stdClass|null $composerJson
|
* @param \stdClass|null $composerJson
|
||||||
* @param string $uri
|
* @param string $uri
|
||||||
* @param array $matches
|
* @param array $matches
|
||||||
* @return string
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
function getPackageName(\stdClass $composerJson = null, string $uri): ?string
|
function getPackageName(string $uri, \stdClass $composerJson = null): ?string
|
||||||
{
|
{
|
||||||
$vendorDir = str_replace('/', '\/', getVendorDir($composerJson));
|
$vendorDir = str_replace('/', '\/', getVendorDir($composerJson));
|
||||||
preg_match("/\/$vendorDir\/([^\/]+\/[^\/]+)\//", $uri, $matches);
|
preg_match("/\/$vendorDir\/([^\/]+\/[^\/]+)\//", $uri, $matches);
|
||||||
return isset($matches[1]) ? $matches[1] : null;
|
return $matches[1] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -187,7 +187,5 @@ function getPackageName(\stdClass $composerJson = null, string $uri): ?string
|
||||||
*/
|
*/
|
||||||
function getVendorDir(\stdClass $composerJson = null): string
|
function getVendorDir(\stdClass $composerJson = null): string
|
||||||
{
|
{
|
||||||
return isset($composerJson->config->{'vendor-dir'}) ?
|
return $composerJson->config->{'vendor-dir'} ?? 'vendor';
|
||||||
$composerJson->config->{'vendor-dir'}
|
|
||||||
: 'vendor';
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue