Use workspace/xGlob for indexing
parent
6d1f1ff1d3
commit
f2925a2650
|
@ -3,6 +3,8 @@ declare(strict_types = 1);
|
||||||
|
|
||||||
namespace LanguageServer;
|
namespace LanguageServer;
|
||||||
|
|
||||||
|
use JsonMapper;
|
||||||
|
|
||||||
class LanguageClient
|
class LanguageClient
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -29,6 +31,7 @@ class LanguageClient
|
||||||
public function __construct(ProtocolReader $reader, ProtocolWriter $writer)
|
public function __construct(ProtocolReader $reader, ProtocolWriter $writer)
|
||||||
{
|
{
|
||||||
$handler = new ClientHandler($reader, $writer);
|
$handler = new ClientHandler($reader, $writer);
|
||||||
|
$mapper = new JsonMapper;
|
||||||
|
|
||||||
$this->textDocument = new Client\TextDocument($handler);
|
$this->textDocument = new Client\TextDocument($handler);
|
||||||
$this->window = new Client\Window($handler);
|
$this->window = new Client\Window($handler);
|
||||||
|
|
|
@ -14,6 +14,7 @@ use LanguageServer\Protocol\{
|
||||||
};
|
};
|
||||||
use AdvancedJsonRpc;
|
use AdvancedJsonRpc;
|
||||||
use Sabre\Event\Loop;
|
use Sabre\Event\Loop;
|
||||||
|
use function Sabre\Event\coroutine;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
|
@ -38,6 +39,11 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
||||||
public $completionItem;
|
public $completionItem;
|
||||||
public $codeLens;
|
public $codeLens;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ClientCapabilities
|
||||||
|
*/
|
||||||
|
private $clientCapabilities;
|
||||||
|
|
||||||
private $protocolReader;
|
private $protocolReader;
|
||||||
private $protocolWriter;
|
private $protocolWriter;
|
||||||
private $client;
|
private $client;
|
||||||
|
@ -155,38 +161,38 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
||||||
*/
|
*/
|
||||||
private function indexProject()
|
private function indexProject()
|
||||||
{
|
{
|
||||||
$fileList = findFilesRecursive($this->rootPath, '/^.+\.php$/i');
|
coroutine(function () {
|
||||||
$numTotalFiles = count($fileList);
|
$textDocuments = $this->client->workspace->xGlob('**/*.php');
|
||||||
|
$count = count($textDocuments);
|
||||||
|
|
||||||
$startTime = microtime(true);
|
$startTime = microtime(true);
|
||||||
$fileNum = 0;
|
|
||||||
|
|
||||||
$processFile = function () use (&$fileList, &$fileNum, &$processFile, $numTotalFiles, $startTime) {
|
foreach ($textDocuments as $i => $textDocument) {
|
||||||
if ($fileNum < $numTotalFiles) {
|
|
||||||
$file = $fileList[$fileNum];
|
// Give LS to the chance to handle requests while indexing
|
||||||
$uri = pathToUri($file);
|
Loop\tick();
|
||||||
$fileNum++;
|
|
||||||
$shortName = substr($file, strlen($this->rootPath) + 1);
|
try {
|
||||||
|
$shortName = substr(uriToPath($textDocument->uri), strlen($this->rootPath) + 1);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$shortName = $textDocument->uri;
|
||||||
|
}
|
||||||
|
|
||||||
if (filesize($file) > 500000) {
|
if (filesize($file) > 500000) {
|
||||||
$this->client->window->logMessage(MessageType::INFO, "Not parsing $shortName because it exceeds size limit of 0.5MB");
|
$this->client->window->logMessage(MessageType::INFO, "Not parsing $shortName because it exceeds size limit of 0.5MB");
|
||||||
} else {
|
} else {
|
||||||
$this->client->window->logMessage(MessageType::INFO, "Parsing file $fileNum/$numTotalFiles: $shortName.");
|
$this->client->window->logMessage(MessageType::INFO, "Parsing file $i/$count: $shortName.");
|
||||||
try {
|
try {
|
||||||
$this->project->loadDocument($uri);
|
$this->project->loadDocument($textDocument->uri);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->client->window->logMessage(MessageType::ERROR, "Error parsing file $shortName: " . (string)$e);
|
$this->client->window->logMessage(MessageType::ERROR, "Error parsing file $shortName: " . (string)$e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Loop\setTimeout($processFile, 0);
|
|
||||||
} else {
|
|
||||||
$duration = (int)(microtime(true) - $startTime);
|
|
||||||
$mem = (int)(memory_get_usage(true) / (1024 * 1024));
|
|
||||||
$this->client->window->logMessage(MessageType::INFO, "All PHP files parsed in $duration seconds. $mem MiB allocated.");
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
Loop\setTimeout($processFile, 0);
|
$duration = (int)(microtime(true) - $startTime);
|
||||||
|
$mem = (int)(memory_get_usage(true) / (1024 * 1024));
|
||||||
|
$this->client->window->logMessage(MessageType::INFO, "All PHP files parsed in $duration seconds. $mem MiB allocated.");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue