Clean up style
parent
6146e6c879
commit
f84b22e05d
|
@ -25,7 +25,6 @@ use Exception;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
use Webmozart\PathUtil\Path;
|
use Webmozart\PathUtil\Path;
|
||||||
use Sabre\Uri;
|
use Sabre\Uri;
|
||||||
use function LanguageServer\sortByLeastSlashes;
|
|
||||||
|
|
||||||
class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
||||||
{
|
{
|
||||||
|
@ -207,9 +206,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
||||||
// Find composer.json
|
// Find composer.json
|
||||||
if ($this->composerJson === null) {
|
if ($this->composerJson === null) {
|
||||||
$composerJsonFiles = yield $this->filesFinder->find(Path::makeAbsolute('**/composer.json', $rootPath));
|
$composerJsonFiles = yield $this->filesFinder->find(Path::makeAbsolute('**/composer.json', $rootPath));
|
||||||
// If we sort our findings by number of slashes (least to greatest),
|
sortUrisLevelOrder($composerJsonFiles);
|
||||||
// the first entry will be the project's root composer.json.
|
|
||||||
usort($composerJsonFiles, 'LanguageServer\sortByLeastSlashes');
|
|
||||||
|
|
||||||
if (!empty($composerJsonFiles)) {
|
if (!empty($composerJsonFiles)) {
|
||||||
$this->composerJson = json_decode(yield $this->contentRetriever->retrieve($composerJsonFiles[0]));
|
$this->composerJson = json_decode(yield $this->contentRetriever->retrieve($composerJsonFiles[0]));
|
||||||
|
@ -219,10 +216,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
||||||
// Find composer.lock
|
// Find composer.lock
|
||||||
if ($this->composerLock === null) {
|
if ($this->composerLock === null) {
|
||||||
$composerLockFiles = yield $this->filesFinder->find(Path::makeAbsolute('**/composer.lock', $rootPath));
|
$composerLockFiles = yield $this->filesFinder->find(Path::makeAbsolute('**/composer.lock', $rootPath));
|
||||||
|
sortUrisLevelOrder($composerLockFiles);
|
||||||
// If we sort our findings by number of slashes (least to greatest),
|
|
||||||
// the first entry will be the project's root composer.lock.
|
|
||||||
usort($composerLockFiles, 'LanguageServer\sortByLeastSlashes');
|
|
||||||
|
|
||||||
if (!empty($composerLockFiles)) {
|
if (!empty($composerLockFiles)) {
|
||||||
$this->composerLock = json_decode(yield $this->contentRetriever->retrieve($composerLockFiles[0]));
|
$this->composerLock = json_decode(yield $this->contentRetriever->retrieve($composerLockFiles[0]));
|
||||||
|
|
|
@ -7,7 +7,7 @@ use Throwable;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use Sabre\Event\{Loop, Promise, EmitterInterface};
|
use Sabre\Event\{Loop, Promise, EmitterInterface};
|
||||||
use function Sabre\Uri\parse;
|
use Sabre\Uri;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms an absolute file path into a URI as used by the language server protocol.
|
* Transforms an absolute file path into a URI as used by the language server protocol.
|
||||||
|
@ -137,14 +137,12 @@ function stripStringOverlap(string $a, string $b): string
|
||||||
* Use for sorting an array of URIs by number of segments
|
* Use for sorting an array of URIs by number of segments
|
||||||
* in ascending order.
|
* in ascending order.
|
||||||
*
|
*
|
||||||
* Example:
|
* @param array
|
||||||
* usort($uriList, 'LanguageServer\sortByLeastSlashes');
|
* @return array
|
||||||
*
|
|
||||||
* @param $a string
|
|
||||||
* @param $b string
|
|
||||||
* @return integer
|
|
||||||
*/
|
*/
|
||||||
function sortByLeastSlashes($a, $b)
|
function sortUrisLevelOrder(&$uriList)
|
||||||
{
|
{
|
||||||
return substr_count(parse($a)['path'], '/') - substr_count(parse($b)['path'], '/');
|
usort($uriList, function ($a, $b) {
|
||||||
|
return substr_count(Uri\parse($a)['path'], '/') - substr_count(Uri\parse($b)['path'], '/');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue