| 247 | } |
| 248 | |
| 249 | void SpellCheckerPlugin::spellCheckDoc( std::shared_ptr<TextDocument> doc ) { |
| 250 | if ( ( !mLanguagesDisabled.empty() && |
| 251 | mLanguagesDisabled.find( doc->getSyntaxDefinition().getLSPName() ) != |
| 252 | mLanguagesDisabled.end() ) || |
| 253 | doc->isHuge() ) |
| 254 | return; |
| 255 | |
| 256 | ScopedOp op( |
| 257 | [this, doc]() { |
| 258 | std::lock_guard l( mWorkMutex ); |
| 259 | mWorkersCount++; |
| 260 | }, |
| 261 | [this]() { |
| 262 | { |
| 263 | std::lock_guard l( mWorkMutex ); |
| 264 | mWorkersCount--; |
| 265 | } |
| 266 | mWorkerCondition.notify_all(); |
| 267 | } ); |
| 268 | if ( !mReady ) |
| 269 | return; |
| 270 | |
| 271 | mTyposFound = !Sys::which( SPELL_CHECKER_CMD ).empty(); |
| 272 | |
| 273 | if ( !mTyposFound ) |
| 274 | return; |
| 275 | |
| 276 | IOStreamString fileString; |
| 277 | mClock.restart(); |
| 278 | if ( doc->isDirty() || !doc->hasFilepath() ) { |
| 279 | std::string tmpPath = |
| 280 | Sys::getTempPath() + ".ecode-" + doc->getFilename() + "." + String::randString( 8 ); |
| 281 | |
| 282 | doc->save( fileString, true ); |
| 283 | FileSystem::fileWrite( tmpPath, (Uint8*)fileString.getStreamPointer(), |
| 284 | fileString.getSize() ); |
| 285 | FileSystem::fileHide( tmpPath ); |
| 286 | runSpellChecker( doc, tmpPath ); |
| 287 | FileSystem::fileRemove( tmpPath ); |
| 288 | } else { |
| 289 | runSpellChecker( doc, doc->getFilePath() ); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | void SpellCheckerPlugin::runSpellChecker( std::shared_ptr<TextDocument> doc, |
| 294 | const std::string& path ) { |
nothing calls this directly
no test coverage detected