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