Clean up style
parent
6146e6c879
commit
f84b22e05d
|
@ -25,7 +25,6 @@ use Exception;
|
|||
use Throwable;
|
||||
use Webmozart\PathUtil\Path;
|
||||
use Sabre\Uri;
|
||||
use function LanguageServer\sortByLeastSlashes;
|
||||
|
||||
class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
||||
{
|
||||
|
@ -207,9 +206,7 @@ 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 number of slashes (least to greatest),
|
||||
// the first entry will be the project's root composer.json.
|
||||
usort($composerJsonFiles, 'LanguageServer\sortByLeastSlashes');
|
||||
sortUrisLevelOrder($composerJsonFiles);
|
||||
|
||||
if (!empty($composerJsonFiles)) {
|
||||
$this->composerJson = json_decode(yield $this->contentRetriever->retrieve($composerJsonFiles[0]));
|
||||
|
@ -219,10 +216,7 @@ 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 number of slashes (least to greatest),
|
||||
// the first entry will be the project's root composer.lock.
|
||||
usort($composerLockFiles, 'LanguageServer\sortByLeastSlashes');
|
||||
sortUrisLevelOrder($composerLockFiles);
|
||||
|
||||
if (!empty($composerLockFiles)) {
|
||||
$this->composerLock = json_decode(yield $this->contentRetriever->retrieve($composerLockFiles[0]));
|
||||
|
|
|
@ -7,7 +7,7 @@ use Throwable;
|
|||
use InvalidArgumentException;
|
||||
use PhpParser\Node;
|
||||
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.
|
||||
|
@ -137,14 +137,12 @@ function stripStringOverlap(string $a, string $b): string
|
|||
* Use for sorting an array of URIs by number of segments
|
||||
* in ascending order.
|
||||
*
|
||||
* Example:
|
||||
* usort($uriList, 'LanguageServer\sortByLeastSlashes');
|
||||
*
|
||||
* @param $a string
|
||||
* @param $b string
|
||||
* @return integer
|
||||
* @param array
|
||||
* @return array
|
||||
*/
|
||||
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