Compare commits
2 Commits
9dc1656592
...
fb48c70ce2
Author | SHA1 | Date |
---|---|---|
|
fb48c70ce2 | |
|
3fc105717d |
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "felixfbecker/language-server",
|
"name": "icedream/language-server",
|
||||||
"description": "PHP Implementation of the Visual Studio Code Language Server Protocol",
|
"description": "PHP Implementation of the Visual Studio Code Language Server Protocol",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
@ -40,6 +40,9 @@
|
||||||
"phan/phan": "1.1.4",
|
"phan/phan": "1.1.4",
|
||||||
"squizlabs/php_codesniffer": "^3.1"
|
"squizlabs/php_codesniffer": "^3.1"
|
||||||
},
|
},
|
||||||
|
"replace": {
|
||||||
|
"felixfbecker/language-server": "self.version"
|
||||||
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"LanguageServer\\": "src/"
|
"LanguageServer\\": "src/"
|
||||||
|
|
|
@ -3,7 +3,6 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer\FilesFinder;
|
namespace LanguageServer\FilesFinder;
|
||||||
|
|
||||||
use Webmozart\Glob\Iterator\GlobIterator;
|
|
||||||
use Sabre\Event\Promise;
|
use Sabre\Event\Promise;
|
||||||
use function Sabre\Event\coroutine;
|
use function Sabre\Event\coroutine;
|
||||||
use function LanguageServer\{pathToUri, timeout};
|
use function LanguageServer\{pathToUri, timeout};
|
||||||
|
@ -23,7 +22,7 @@ class FileSystemFilesFinder implements FilesFinder
|
||||||
$uris = [];
|
$uris = [];
|
||||||
foreach (new GlobIterator($glob) as $path) {
|
foreach (new GlobIterator($glob) as $path) {
|
||||||
// Exclude any directories that also match the glob pattern
|
// Exclude any directories that also match the glob pattern
|
||||||
if (!is_dir($path)) {
|
if (!is_dir($path) || !is_readable($path)) {
|
||||||
$uris[] = pathToUri($path);
|
$uris[] = pathToUri($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
<?php
|
||||||
|
declare (strict_types = 1);
|
||||||
|
|
||||||
|
namespace LanguageServer\FilesFinder;
|
||||||
|
|
||||||
|
use ArrayIterator;
|
||||||
|
use EmptyIterator;
|
||||||
|
use IteratorIterator;
|
||||||
|
use RecursiveIteratorIterator;
|
||||||
|
use Webmozart\Glob\Glob;
|
||||||
|
use Webmozart\Glob\Iterator\GlobFilterIterator;
|
||||||
|
use Webmozart\Glob\Iterator\RecursiveDirectoryIterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns filesystem paths matching a glob.
|
||||||
|
*
|
||||||
|
* @since 1.0
|
||||||
|
*
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*
|
||||||
|
* @see Glob
|
||||||
|
*/
|
||||||
|
class GlobIterator extends IteratorIterator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Creates a new iterator.
|
||||||
|
*
|
||||||
|
* @param string $glob The glob pattern.
|
||||||
|
* @param int $flags A bitwise combination of the flag constants in
|
||||||
|
* {@link Glob}.
|
||||||
|
*/
|
||||||
|
public function __construct($glob, $flags = 0)
|
||||||
|
{
|
||||||
|
$basePath = Glob::getBasePath($glob, $flags);
|
||||||
|
if (!Glob::isDynamic($glob) && file_exists($glob)) {
|
||||||
|
// If the glob is a file path, return that path
|
||||||
|
$innerIterator = new ArrayIterator(array($glob));
|
||||||
|
} elseif (is_dir($basePath)) {
|
||||||
|
// Use the system's much more efficient glob() function where we can
|
||||||
|
if (
|
||||||
|
// glob() does not support /**/
|
||||||
|
false === strpos($glob, '/**/') &&
|
||||||
|
// glob() does not support stream wrappers
|
||||||
|
false === strpos($glob, '://') &&
|
||||||
|
// glob() does not support [^...] on Windows
|
||||||
|
('\\' !== DIRECTORY_SEPARATOR || false === strpos($glob, '[^'))
|
||||||
|
) {
|
||||||
|
$results = glob($glob, GLOB_BRACE);
|
||||||
|
|
||||||
|
// $results may be empty or false if $glob is invalid
|
||||||
|
if (empty($results)) {
|
||||||
|
// Parse glob and provoke errors if invalid
|
||||||
|
Glob::toRegEx($glob);
|
||||||
|
|
||||||
|
// Otherwise return empty result set
|
||||||
|
$innerIterator = new EmptyIterator();
|
||||||
|
} else {
|
||||||
|
$innerIterator = new ArrayIterator($results);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Otherwise scan the glob's base directory for matches
|
||||||
|
$innerIterator = new GlobFilterIterator(
|
||||||
|
$glob,
|
||||||
|
new RecursiveIteratorIterator(
|
||||||
|
new RecursiveDirectoryIterator(
|
||||||
|
$basePath,
|
||||||
|
RecursiveDirectoryIterator::CURRENT_AS_PATHNAME,
|
||||||
|
RecursiveDirectoryIterator::SKIP_DOTS
|
||||||
|
),
|
||||||
|
RecursiveIteratorIterator::SELF_FIRST,
|
||||||
|
RecursiveIteratorIterator::CATCH_GET_CHILD
|
||||||
|
),
|
||||||
|
GlobFilterIterator::FILTER_VALUE,
|
||||||
|
$flags
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// If the glob's base directory does not exist, return nothing
|
||||||
|
$innerIterator = new EmptyIterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::__construct($innerIterator);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue