| 792 | } |
| 793 | |
| 794 | void LinterPlugin::lintDoc( std::shared_ptr<TextDocument> doc ) { |
| 795 | if ( mShuttingDown ) |
| 796 | return; |
| 797 | |
| 798 | if ( !mLanguagesDisabled.empty() && |
| 799 | mLanguagesDisabled.find( doc->getSyntaxDefinition().getLSPName() ) != |
| 800 | mLanguagesDisabled.end() ) |
| 801 | return; |
| 802 | |
| 803 | ScopedOp op( |
| 804 | [this, doc]() { |
| 805 | std::lock_guard l( mWorkMutex ); |
| 806 | mWorkersCount++; |
| 807 | }, |
| 808 | [this]() { |
| 809 | { |
| 810 | std::lock_guard l( mWorkMutex ); |
| 811 | mWorkersCount--; |
| 812 | } |
| 813 | mWorkerCondition.notify_all(); |
| 814 | } ); |
| 815 | |
| 816 | if ( !mReady || mShuttingDown ) |
| 817 | return; |
| 818 | auto linter = supportsLinter( doc ); |
| 819 | if ( linter.command.empty() ) |
| 820 | return; |
| 821 | |
| 822 | bool binaryFound = linter.isNative; |
| 823 | if ( !linter.isNative ) { |
| 824 | auto parts = String::split( linter.command, ' ' ); |
| 825 | if ( !parts.empty() ) { |
| 826 | if ( parts[0].find_first_of( "\\/" ) != std::string::npos ) { |
| 827 | binaryFound = FileSystem::fileExists( parts[0] ); |
| 828 | } else { |
| 829 | binaryFound = !Sys::which( parts[0] ).empty(); |
| 830 | } |
| 831 | } |
| 832 | } |
| 833 | if ( !binaryFound ) |
| 834 | return; |
| 835 | |
| 836 | IOStreamString fileString; |
| 837 | mClock.restart(); |
| 838 | if ( doc->isDirty() || !doc->hasFilepath() ) { |
| 839 | std::string tmpPath; |
| 840 | if ( !doc->hasFilepath() ) { |
| 841 | tmpPath = |
| 842 | Sys::getTempPath() + ".ecode-" + doc->getFilename() + "." + String::randString( 8 ); |
| 843 | } else if ( linter.useTmpFolder ) { |
| 844 | tmpPath = Sys::getTempPath() + doc->getFilename(); |
| 845 | if ( FileSystem::fileExists( tmpPath ) ) { |
| 846 | tmpPath = Sys::getTempPath() + ".ecode-" + doc->getFilename() + "." + |
| 847 | String::randString( 8 ); |
| 848 | } |
| 849 | } else { |
| 850 | std::string fileDir( FileSystem::fileRemoveFileName( doc->getFilePath() ) ); |
| 851 | FileSystem::dirAddSlashAtEnd( fileDir ); |
nothing calls this directly
no test coverage detected