content-limit become configurable
parent
b210c37d57
commit
89763896d3
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
|
||||
use LanguageServer\{LanguageServer, ProtocolStreamReader, ProtocolStreamWriter, StderrLogger};
|
||||
use LanguageServer\{LanguageServer, ProtocolStreamReader, ProtocolStreamWriter, StderrLogger, ContentTooLargeException};
|
||||
use Sabre\Event\Loop;
|
||||
use Composer\XdebugHandler\XdebugHandler;
|
||||
|
||||
$options = getopt('', ['tcp::', 'tcp-server::', 'memory-limit::']);
|
||||
$options = getopt('', ['tcp::', 'tcp-server::', 'memory-limit::', "content-limit::"]);
|
||||
|
||||
ini_set('memory_limit', $options['memory-limit'] ?? '4G');
|
||||
|
||||
|
@ -39,6 +39,10 @@ $xdebugHandler->setLogger($logger);
|
|||
$xdebugHandler->check();
|
||||
unset($xdebugHandler);
|
||||
|
||||
if (is_integer($options['content-limit'] ?? null)) {
|
||||
ContentTooLargeException::$limit = (int)$options['content-limit'];
|
||||
}
|
||||
|
||||
if (!empty($options['tcp'])) {
|
||||
// Connect to a TCP server
|
||||
$address = $options['tcp'];
|
||||
|
|
|
@ -20,12 +20,10 @@ class FileSystemContentRetriever implements ContentRetriever
|
|||
*/
|
||||
public function retrieve(string $uri): Promise
|
||||
{
|
||||
$limit = 150000;
|
||||
|
||||
$path = uriToPath($uri);
|
||||
$size = filesize($path);
|
||||
if ($size > $limit) {
|
||||
return Promise\reject(new ContentTooLargeException($uri, $size, $limit));
|
||||
if ($size > ContentTooLargeException::$limit) {
|
||||
return Promise\reject(new ContentTooLargeException($uri, $size));
|
||||
}
|
||||
return Promise\resolve(file_get_contents($path));
|
||||
}
|
||||
|
|
|
@ -8,6 +8,13 @@ namespace LanguageServer;
|
|||
*/
|
||||
class ContentTooLargeException extends \Exception
|
||||
{
|
||||
/**
|
||||
* The limit of content
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public static $limit = 1000000;
|
||||
|
||||
/**
|
||||
* The URI of the file that exceeded the limit
|
||||
*
|
||||
|
@ -22,24 +29,16 @@ class ContentTooLargeException extends \Exception
|
|||
*/
|
||||
public $size;
|
||||
|
||||
/**
|
||||
* The limit that was exceeded in bytes
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $limit;
|
||||
|
||||
/**
|
||||
* @param string $uri The URI of the file that exceeded the limit
|
||||
* @param int $size The size of the file in bytes
|
||||
* @param int $limit The limit that was exceeded in bytes
|
||||
* @param \Throwable $previous The previous exception used for the exception chaining.
|
||||
*/
|
||||
public function __construct(string $uri, int $size, int $limit, \Throwable $previous = null)
|
||||
public function __construct(string $uri, int $size, \Throwable $previous = null)
|
||||
{
|
||||
$this->uri = $uri;
|
||||
$this->size = $size;
|
||||
$this->limit = $limit;
|
||||
$limit = self::$limit;
|
||||
parent::__construct("$uri exceeds size limit of $limit bytes ($size)", 0, $previous);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -218,9 +218,10 @@ class Indexer
|
|||
$this->client->textDocument->publishDiagnostics($uri, $document->getDiagnostics());
|
||||
}
|
||||
} catch (ContentTooLargeException $e) {
|
||||
$limit = ContentTooLargeException::$limit;
|
||||
$this->client->window->logMessage(
|
||||
MessageType::INFO,
|
||||
"Ignoring file {$uri} because it exceeds size limit of {$e->limit} bytes ({$e->size})"
|
||||
"Ignoring file {$uri} because it exceeds size limit of {$limit} bytes ({$e->size})"
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$this->client->window->logMessage(MessageType::ERROR, "Error parsing $uri: " . (string)$e);
|
||||
|
|
Loading…
Reference in New Issue