Moved utility functions to utils.php
parent
1865ce8538
commit
6b28cb6a93
|
@ -34,7 +34,8 @@
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"LanguageServer\\": "src/"
|
"LanguageServer\\": "src/"
|
||||||
}
|
},
|
||||||
|
"files" : ["src/utils.php"]
|
||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|
|
@ -129,13 +129,7 @@ class LanguageServer extends \AdvancedJsonRpc\Dispatcher
|
||||||
*/
|
*/
|
||||||
private function indexProject(string $rootPath)
|
private function indexProject(string $rootPath)
|
||||||
{
|
{
|
||||||
$dir = new \RecursiveDirectoryIterator($rootPath);
|
$fileList = findFilesRecursive($rootPath, '/^.+\.php$/i');
|
||||||
$ite = new \RecursiveIteratorIterator($dir);
|
|
||||||
$files = new \RegexIterator($ite, '/^.+\.php$/i', \RegexIterator::GET_MATCH);
|
|
||||||
$fileList = array();
|
|
||||||
foreach($files as $file) {
|
|
||||||
$fileList = array_merge($fileList, $file);
|
|
||||||
}
|
|
||||||
$numTotalFiles = count($fileList);
|
$numTotalFiles = count($fileList);
|
||||||
|
|
||||||
$startTime = microtime(true);
|
$startTime = microtime(true);
|
||||||
|
@ -143,8 +137,7 @@ class LanguageServer extends \AdvancedJsonRpc\Dispatcher
|
||||||
$processFile = function() use (&$fileList, &$processFile, $rootPath, $numTotalFiles, $startTime) {
|
$processFile = function() use (&$fileList, &$processFile, $rootPath, $numTotalFiles, $startTime) {
|
||||||
if ($file = array_pop($fileList)) {
|
if ($file = array_pop($fileList)) {
|
||||||
|
|
||||||
$uri = 'file://'.($file[0] == '/' || $file[0] == '\\' ? '' : '/').str_replace('\\', '/', $file);
|
$uri = pathToUri($file);
|
||||||
|
|
||||||
$fileNum = $numTotalFiles - count($fileList);
|
$fileNum = $numTotalFiles - count($fileList);
|
||||||
$shortName = substr($file, strlen($rootPath)+1);
|
$shortName = substr($file, strlen($rootPath)+1);
|
||||||
$this->client->window->logMessage(3, "Parsing file $fileNum/$numTotalFiles: $shortName.");
|
$this->client->window->logMessage(3, "Parsing file $fileNum/$numTotalFiles: $shortName.");
|
||||||
|
@ -155,7 +148,8 @@ class LanguageServer extends \AdvancedJsonRpc\Dispatcher
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$duration = (int)(microtime(true) - $startTime);
|
$duration = (int)(microtime(true) - $startTime);
|
||||||
$this->client->window->logMessage(3, "All PHP files parsed in $duration seconds.");
|
$mem = memory_get_usage(true);
|
||||||
|
$this->client->window->logMessage(3, "All PHP files parsed in $duration seconds. $mem bytes allocated.");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace LanguageServer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively Searches files with matching filename, starting at $path.
|
||||||
|
*
|
||||||
|
* @param string $path
|
||||||
|
* @param string $pattern
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function findFilesRecursive(string $path, string $pattern): array {
|
||||||
|
$dir = new \RecursiveDirectoryIterator($path);
|
||||||
|
$ite = new \RecursiveIteratorIterator($dir);
|
||||||
|
$files = new \RegexIterator($ite, $pattern, \RegexIterator::GET_MATCH);
|
||||||
|
$fileList = array();
|
||||||
|
foreach($files as $file) {
|
||||||
|
$fileList = array_merge($fileList, $file);
|
||||||
|
}
|
||||||
|
return $fileList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms an absolute file path into a URI as used by the language server protocol.
|
||||||
|
*
|
||||||
|
* @param string $filepath
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function pathToUri(string $filepath): string {
|
||||||
|
return 'file://'.($filepath[0] == '/' || $filepath[0] == '\\' ? '' : '/').str_replace('\\', '/', $filepath);
|
||||||
|
}
|
Loading…
Reference in New Issue