More project search filters WIP.

This commit is contained in:
Martín Lucas Golini
2024-03-14 10:38:46 -03:00
parent 5975174e48
commit b3d0eea6fc
8 changed files with 34 additions and 22 deletions

View File

@@ -401,13 +401,13 @@ class EE_API String {
/** glob matches a string against a glob
** @return True if matches
*/
static bool globMatch( const std::string& text, const std::string_view& glob,
static bool globMatch( const std::string_view& text, const std::string_view& glob,
bool caseInsensitive = false );
/** glob matches a string against a set of globs
** @return True if matches
*/
static bool globMatch( const std::string& text, const std::vector<std::string>& globs,
static bool globMatch( const std::string_view& text, const std::vector<std::string>& globs,
bool caseInsensitive = false );
/** @brief Default constructor

View File

@@ -23,16 +23,16 @@ const std::size_t String::InvalidPos = StringType::npos;
#define PATHSEP '/'
#define CASE( c, caseInsensitive ) ( caseInsensitive ? std::tolower( c ) : ( c ) )
bool String::globMatch( const std::string& text, const std::string_view& glob,
bool String::globMatch( const std::string_view& text, const std::string_view& glob,
bool caseInsensitive ) {
size_t i = 0;
size_t j = 0;
size_t n = text.size();
size_t m = glob.size();
size_t text1_backup = std::string::npos;
size_t glob1_backup = std::string::npos;
size_t text2_backup = std::string::npos;
size_t glob2_backup = std::string::npos;
size_t text1_backup = std::string_view::npos;
size_t glob1_backup = std::string_view::npos;
size_t text2_backup = std::string_view::npos;
size_t glob2_backup = std::string_view::npos;
bool nodot = !DOTGLOB;
// match pathname if glob contains a / otherwise match the basename
if ( j + 1 < m && glob[j] == '/' ) {
@@ -43,9 +43,9 @@ bool String::globMatch( const std::string& text, const std::string_view& glob,
if ( i < n && text[i] == PATHSEP )
i++;
j++;
} else if ( glob.find( '/' ) == std::string::npos ) {
} else if ( glob.find( '/' ) == std::string_view::npos ) {
size_t sep = text.rfind( PATHSEP );
if ( sep != std::string::npos )
if ( sep != std::string_view::npos )
i = sep + 1;
}
while ( i < n ) {
@@ -63,8 +63,8 @@ bool String::globMatch( const std::string& text, const std::string_view& glob,
if ( glob[j] != '/' )
return false;
// new **-loop, discard *-loop
text1_backup = std::string::npos;
glob1_backup = std::string::npos;
text1_backup = std::string_view::npos;
glob1_backup = std::string_view::npos;
text2_backup = i;
glob2_backup = ++j;
continue;
@@ -130,13 +130,13 @@ bool String::globMatch( const std::string& text, const std::string_view& glob,
continue;
}
}
if ( glob1_backup != std::string::npos && text[text1_backup] != PATHSEP ) {
if ( glob1_backup != std::string_view::npos && text[text1_backup] != PATHSEP ) {
// *-loop: backtrack to the last * but do not jump over /
i = ++text1_backup;
j = glob1_backup;
continue;
}
if ( glob2_backup != std::string::npos ) {
if ( glob2_backup != std::string_view::npos ) {
// **-loop: backtrack to the last **
i = ++text2_backup;
j = glob2_backup;
@@ -151,8 +151,8 @@ bool String::globMatch( const std::string& text, const std::string_view& glob,
return j >= m;
}
bool String::globMatch( const std::string& text, const std::vector<std::string>& globs,
bool caseInsensitive ) {
bool String::globMatch( const std::string_view& text, const std::vector<std::string>& globs,
bool caseInsensitive ) {
for ( const auto& glob : globs ) {
if ( globMatch( text, glob, caseInsensitive ) )
return true;

View File

@@ -733,6 +733,7 @@ App::~App() {
delete mFileWatcher;
mFileWatcher = nullptr;
}
mDirTree->resetPluginManager();
mPluginManager.reset();
eeSAFE_DELETE( mSplitter );

View File

@@ -589,7 +589,7 @@ void GlobalSearchController::doGlobalSearch( String text, String filter, bool ca
caseSensitive, wholeWord,
luaPattern ? TextDocument::FindReplaceType::LuaPattern
: TextDocument::FindReplaceType::Normal,
parseGlobMatches( filter ) );
parseGlobMatches( filter ), mApp->getCurrentProject() );
}
}

View File

@@ -323,6 +323,10 @@ void ProjectDirectoryTree::onChange( const ProjectDirectoryTree::Action& action,
}
}
void ProjectDirectoryTree::resetPluginManager() {
mPluginManager = nullptr;
}
void ProjectDirectoryTree::tryAddFile( const FileInfo& file ) {
if ( mIgnoreHidden && file.isHidden() )
return;

View File

@@ -144,6 +144,8 @@ class ProjectDirectoryTree {
const std::string& getPath() const { return mPath; }
void resetPluginManager();
protected:
std::string mPath;
std::shared_ptr<ThreadPool> mPool;

View File

@@ -145,7 +145,7 @@ searchInFileLuaPattern( const std::string& file, const std::string& text, const
void ProjectSearch::find( const std::vector<std::string> files, const std::string& string,
ResultCb result, bool caseSensitive, bool wholeWord,
const TextDocument::FindReplaceType& type,
const std::vector<GlobMatch>& pathFilters ) {
const std::vector<GlobMatch>& pathFilters, std::string basePath ) {
Result res;
const auto occ =
type == TextDocument::FindReplaceType::Normal
@@ -182,9 +182,10 @@ struct FindData {
void ProjectSearch::find( const std::vector<std::string> files, std::string string,
std::shared_ptr<ThreadPool> pool, ResultCb result, bool caseSensitive,
bool wholeWord, const TextDocument::FindReplaceType& type,
const std::vector<GlobMatch>& pathFilters ) {
const std::vector<GlobMatch>& pathFilters, std::string basePath ) {
if ( files.empty() )
result( {} );
FileSystem::dirAddSlashAtEnd( basePath );
FindData* findData = eeNew( FindData, () );
findData->resCount = files.size();
if ( !caseSensitive )
@@ -197,10 +198,14 @@ void ProjectSearch::find( const std::vector<std::string> files, std::string stri
search.resize( files.size() );
size_t pos = 0;
size_t count = 0;
for ( auto& file : files ) {
for ( const auto& file : files ) {
bool skip = false;
std::string_view fsv( file );
if ( !basePath.empty() && String::startsWith( file, basePath ) )
fsv = fsv.substr( basePath.size() );
for ( const auto& filter : pathFilters ) {
bool matches = String::globMatch( file, filter.first );
bool matches = String::globMatch( fsv, filter.first );
if ( ( matches && filter.second ) || ( !matches && !filter.second ) ) {
skip = true;
break;

View File

@@ -212,14 +212,14 @@ class ProjectSearch {
find( const std::vector<std::string> files, const std::string& string, ResultCb result,
bool caseSensitive, bool wholeWord = false,
const TextDocument::FindReplaceType& type = TextDocument::FindReplaceType::Normal,
const std::vector<GlobMatch>& pathFilters = {} );
const std::vector<GlobMatch>& pathFilters = {}, std::string basePath = "" );
static void
find( const std::vector<std::string> files, std::string string,
std::shared_ptr<ThreadPool> pool, ResultCb result, bool caseSensitive,
bool wholeWord = false,
const TextDocument::FindReplaceType& type = TextDocument::FindReplaceType::Normal,
const std::vector<GlobMatch>& pathFilters = {} );
const std::vector<GlobMatch>& pathFilters = {}, std::string basePath = "" );
};
} // namespace ecode