From 1bae4a4a9ab6b61c5b0330f784f82fd37991a2a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sat, 7 Oct 2023 02:41:32 -0300 Subject: [PATCH] Fix TextDocument load error with big source files. --- src/eepp/ui/doc/textdocument.cpp | 21 +++++++++---------- .../ecode/plugins/lsp/lspdocumentclient.cpp | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/eepp/ui/doc/textdocument.cpp b/src/eepp/ui/doc/textdocument.cpp index bac1a2faf..c2302e2a0 100644 --- a/src/eepp/ui/doc/textdocument.cpp +++ b/src/eepp/ui/doc/textdocument.cpp @@ -165,7 +165,7 @@ TextDocument::LoadStatus TextDocument::loadFromStream( IOStream& file, std::stri size_t lineBufferSize = lineBuffer.size(); char lastChar = lineBuffer[lineBufferSize - 1]; - if ( lastChar == '\n' || lastChar == '\r' || !consume ) { + if ( lastChar == '\n' || lastChar == '\r' ) { if ( mLines.empty() ) { if ( lineBufferSize > 1 && lineBuffer[lineBufferSize - 2] == '\r' && lastChar == '\n' ) { @@ -196,15 +196,6 @@ TextDocument::LoadStatus TextDocument::loadFromStream( IOStream& file, std::stri } } - if ( !mLines.empty() ) { - const String& lastLine = mLines[mLines.size() - 1].getText(); - if ( lastLine[lastLine.size() - 1] == '\n' ) { - mLines.push_back( String( "\n" ) ); - } else { - mLines[mLines.size() - 1].append( "\n" ); - } - } - if ( !read ) break; pending -= read; @@ -212,8 +203,16 @@ TextDocument::LoadStatus TextDocument::loadFromStream( IOStream& file, std::stri }; } - if ( mLines.empty() ) + if ( !mLines.empty() ) { + const String& lastLine = mLines[mLines.size() - 1].getText(); + if ( lastLine[lastLine.size() - 1] == '\n' ) { + mLines.push_back( String( "\n" ) ); + } else { + mLines[mLines.size() - 1].append( "\n" ); + } + } else { mLines.push_back( String( "\n" ) ); + } if ( mAutoDetectIndentType ) guessIndentType(); diff --git a/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp b/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp index 42bfd7589..9111b10dc 100644 --- a/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp +++ b/src/tools/ecode/plugins/lsp/lspdocumentclient.cpp @@ -298,7 +298,7 @@ void LSPDocumentClient::highlight() { const auto& caps = mServer->getCapabilities().semanticTokenProvider; Uint32 currentLine = 0; Uint32 start = 0; - std::unordered_map tokenizerLines; + UnorderedMap tokenizerLines; Int64 lastLine = 0; TokenizedLine* lastLinePtr = nullptr; Time diff;