Read vendor directory from project's composer.json, if set.
If not set, default to "vendor". Also sort found vendor directories so we obtain the correct composer.json and composer.lock filespull/281/head
parent
5100d89617
commit
f43e0dc34a
|
@ -59,6 +59,11 @@ class Indexer
|
|||
*/
|
||||
private $composerLock;
|
||||
|
||||
/**
|
||||
* @var \stdClasss
|
||||
*/
|
||||
private $composerJson;
|
||||
|
||||
/**
|
||||
* @param FilesFinder $filesFinder
|
||||
* @param string $rootPath
|
||||
|
@ -77,7 +82,8 @@ class Indexer
|
|||
DependenciesIndex $dependenciesIndex,
|
||||
Index $sourceIndex,
|
||||
PhpDocumentLoader $documentLoader,
|
||||
\stdClass $composerLock = null
|
||||
\stdClass $composerLock = null,
|
||||
\stdClass $composerJson = null
|
||||
) {
|
||||
$this->filesFinder = $filesFinder;
|
||||
$this->rootPath = $rootPath;
|
||||
|
@ -87,6 +93,7 @@ class Indexer
|
|||
$this->sourceIndex = $sourceIndex;
|
||||
$this->documentLoader = $documentLoader;
|
||||
$this->composerLock = $composerLock;
|
||||
$this->composerJson = $composerJson;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,8 +116,12 @@ class Indexer
|
|||
$source = [];
|
||||
/** @var string[][] */
|
||||
$deps = [];
|
||||
|
||||
$vendorDir = str_replace('/', '\/', @$this->composerJson->config->{'vendor-dir'} ?: 'vendor');
|
||||
$this->client->window->logMessage(MessageType::INFO, "Vendor dir: $vendorDir");
|
||||
|
||||
foreach ($uris as $uri) {
|
||||
if ($this->composerLock !== null && preg_match('/\/vendor\/([^\/]+\/[^\/]+)\//', $uri, $matches)) {
|
||||
if ($this->composerLock !== null && preg_match("/\/$vendorDir\/([^\/]+\/[^\/]+)\//", $uri, $matches)) {
|
||||
// Dependency file
|
||||
$packageName = $matches[1];
|
||||
if (!isset($deps[$packageName])) {
|
||||
|
@ -174,6 +185,8 @@ class Indexer
|
|||
if ($cacheKey !== null) {
|
||||
$this->client->window->logMessage(MessageType::INFO, "Storing $packageKey in cache");
|
||||
$this->cache->set($cacheKey, $index);
|
||||
} else {
|
||||
$this->client->window->logMessage(MessageType::INFO, "Cannot cache $packageName, cache key was null. Either you are using a 'dev-' version or your composer.lock is missing references.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -206,6 +206,13 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
|||
// Find composer.json
|
||||
if ($this->composerJson === null) {
|
||||
$composerJsonFiles = yield $this->filesFinder->find(Path::makeAbsolute('**/composer.json', $rootPath));
|
||||
|
||||
// If we sort our findings by string length (shortest to longest),
|
||||
// the first entry will be the project's root composer.json.
|
||||
usort($composerJsonFiles, function ($a, $b) {
|
||||
return strlen($a) - strlen($b);
|
||||
});
|
||||
|
||||
if (!empty($composerJsonFiles)) {
|
||||
$this->composerJson = json_decode(yield $this->contentRetriever->retrieve($composerJsonFiles[0]));
|
||||
}
|
||||
|
@ -214,6 +221,13 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
|||
// Find composer.lock
|
||||
if ($this->composerLock === null) {
|
||||
$composerLockFiles = yield $this->filesFinder->find(Path::makeAbsolute('**/composer.lock', $rootPath));
|
||||
|
||||
// If we sort our findings by string length (shortest to longest),
|
||||
// the first entry will be the project's root composer.lock.
|
||||
usort($composerLockFiles, function ($a, $b) {
|
||||
return strlen($a) - strlen($b);
|
||||
});
|
||||
|
||||
if (!empty($composerLockFiles)) {
|
||||
$this->composerLock = json_decode(yield $this->contentRetriever->retrieve($composerLockFiles[0]));
|
||||
}
|
||||
|
@ -230,7 +244,8 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
|||
$dependenciesIndex,
|
||||
$sourceIndex,
|
||||
$this->documentLoader,
|
||||
$this->composerLock
|
||||
$this->composerLock,
|
||||
$this->composerJson
|
||||
);
|
||||
$indexer->index()->otherwise('\\LanguageServer\\crash');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue