| 192 | } |
| 193 | |
| 194 | void SyntaxHighlighter::copyLineToBuffer( const size_t& index, |
| 195 | std::vector<SyntaxTokenPosition>& buffer, |
| 196 | bool mustTokenize ) { |
| 197 | static std::vector<SyntaxTokenPosition> noHighlightVector = { |
| 198 | { SyntaxStyleTypes::Normal, 0, 0 } }; |
| 199 | if ( mDoc->getSyntaxDefinition().getPatterns().empty() ) { |
| 200 | noHighlightVector[0].len = mDoc->getLineLength( index ); |
| 201 | buffer = noHighlightVector; |
| 202 | return; |
| 203 | } |
| 204 | |
| 205 | { |
| 206 | Lock l( mLinesMutex ); |
| 207 | auto it = mLines.find( index ); |
| 208 | bool needsTokenize = |
| 209 | it == mLines.end() || |
| 210 | ( index < mDoc->linesCount() && mDoc->getLineHash( index ) != it->second.hash ); |
| 211 | if ( !needsTokenize ) { |
| 212 | mMaxWantedLine = eemax<Int64>( mMaxWantedLine, index ); |
| 213 | buffer = it->second.tokens; |
| 214 | return; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | if ( !mustTokenize ) { |
| 219 | noHighlightVector[0].len = mDoc->getLineLength( index ); |
| 220 | buffer = noHighlightVector; |
| 221 | return; |
| 222 | } |
| 223 | |
| 224 | SyntaxState prevState; |
| 225 | if ( index > 0 ) { |
| 226 | Lock l( mLinesMutex ); |
| 227 | auto prevIt = mLines.find( index - 1 ); |
| 228 | if ( prevIt != mLines.end() ) |
| 229 | prevState = prevIt->second.state; |
| 230 | } |
| 231 | auto tokenizedLine = tokenizeLine( index, prevState ); |
| 232 | |
| 233 | Lock l( mLinesMutex ); |
| 234 | mLines[index] = std::move( tokenizedLine ); |
| 235 | mTokenizerLines[index] = mLines[index]; |
| 236 | mMaxWantedLine = eemax<Int64>( mMaxWantedLine, index ); |
| 237 | buffer = mLines[index].tokens; |
| 238 | } |
| 239 | |
| 240 | Int64 SyntaxHighlighter::getFirstInvalidLine() const { |
| 241 | return mFirstInvalidLine; |
no test coverage detected