From ccd97ce37745268e024097d7953b097c238f3887 Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Fri, 18 Nov 2016 13:12:40 +0100 Subject: [PATCH] Use file stat --- src/Project.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Project.php b/src/Project.php index 4efcf71..9cebaf4 100644 --- a/src/Project.php +++ b/src/Project.php @@ -103,17 +103,22 @@ class Project public function loadDocument(string $uri): Promise { return coroutine(function () use ($uri) { + $limit = 150000; if ($this->clientCapabilities->xcontentProvider) { $content = (yield $this->client->textDocument->xcontent(new TextDocumentIdentifier($uri)))->text; + $size = strlen($content); + if ($size > $limit) { + throw new ContentTooLargeException($uri, $size, $limit); + } } else { - $content = file_get_contents(uriToPath($uri)); + $path = uriToPath($uri); + $size = filesize($path); + if ($size > $limit) { + throw new ContentTooLargeException($uri, $size, $limit); + } + $content = file_get_contents($path); } // Don't parse large files - $size = strlen($content); - $limit = 150000; - if ($size > $limit) { - throw new ContentTooLargeException($uri, $size, $limit); - } if (isset($this->documents[$uri])) { $document = $this->documents[$uri]; $document->updateContent($content);