| 18 | namespace QodeAssist::Tools { |
| 19 | |
| 20 | FileSearchUtils::FileMatch FileSearchUtils::findBestMatch( |
| 21 | const QString &query, |
| 22 | const QString &filePattern, |
| 23 | int maxResults, |
| 24 | Context::IgnoreManager *ignoreManager) |
| 25 | { |
| 26 | QList<FileMatch> candidates; |
| 27 | auto projects = ProjectExplorer::ProjectManager::projects(); |
| 28 | |
| 29 | if (projects.isEmpty()) { |
| 30 | return FileMatch{}; |
| 31 | } |
| 32 | |
| 33 | QFileInfo queryInfo(query); |
| 34 | if (queryInfo.isAbsolute() && queryInfo.exists() && queryInfo.isFile()) { |
| 35 | FileMatch match; |
| 36 | match.absolutePath = queryInfo.canonicalFilePath(); |
| 37 | |
| 38 | for (auto project : projects) { |
| 39 | if (!project) |
| 40 | continue; |
| 41 | QString projectDir = project->projectDirectory().path(); |
| 42 | if (match.absolutePath.startsWith(projectDir)) { |
| 43 | match.relativePath = QDir(projectDir).relativeFilePath(match.absolutePath); |
| 44 | match.projectName = project->displayName(); |
| 45 | match.matchType = MatchType::ExactName; |
| 46 | return match; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | match.relativePath = queryInfo.fileName(); |
| 51 | match.projectName = "External"; |
| 52 | match.matchType = MatchType::ExactName; |
| 53 | return match; |
| 54 | } |
| 55 | |
| 56 | QString lowerQuery = query.toLower(); |
| 57 | |
| 58 | for (auto project : projects) { |
| 59 | if (!project) |
| 60 | continue; |
| 61 | |
| 62 | auto projectFiles = project->files(ProjectExplorer::Project::SourceFiles); |
| 63 | QString projectDir = project->projectDirectory().path(); |
| 64 | QString projectName = project->displayName(); |
| 65 | |
| 66 | for (const auto &filePath : projectFiles) { |
| 67 | QString absolutePath = filePath.path(); |
| 68 | |
| 69 | if (ignoreManager && ignoreManager->shouldIgnore(absolutePath, project)) |
| 70 | continue; |
| 71 | |
| 72 | QFileInfo fileInfo(absolutePath); |
| 73 | QString fileName = fileInfo.fileName(); |
| 74 | |
| 75 | if (!filePattern.isEmpty() && !matchesFilePattern(fileName, filePattern)) |
| 76 | continue; |
| 77 |
nothing calls this directly
no test coverage detected