| 179 | } |
| 180 | |
| 181 | QList<CompletionTreeItemPointer> CodeCompletionContext::importCompletion() |
| 182 | { |
| 183 | QList<CompletionTreeItemPointer> items; |
| 184 | const auto fragment = m_text.section(QLatin1Char(' '), -1, -1); |
| 185 | |
| 186 | auto addModules = [&items, &fragment](const QString& dataDir) { |
| 187 | if (dataDir.isEmpty()) |
| 188 | return; |
| 189 | |
| 190 | QDir dir(dataDir); |
| 191 | if (!dir.exists()) |
| 192 | return; |
| 193 | |
| 194 | const auto dirEntries = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name); |
| 195 | items.reserve(dirEntries.size()); |
| 196 | for (const QString& entry : dirEntries) { |
| 197 | items.append(CompletionTreeItemPointer(new ModuleCompletionItem( |
| 198 | fragment + entry.section(QLatin1Char('.'), 0, 0), |
| 199 | ModuleCompletionItem::Import |
| 200 | ))); |
| 201 | } |
| 202 | }; |
| 203 | |
| 204 | // Use the cache to find the directory corresponding to the fragment |
| 205 | // (org.kde is, for instance, /usr/lib64/kde4/imports/org/kde), and list |
| 206 | // its subdirectories |
| 207 | addModules(Cache::instance().modulePath(m_duContext->url(), fragment)); |
| 208 | |
| 209 | if (items.isEmpty()) { |
| 210 | // fallback to list all directories we can find |
| 211 | const auto paths = Cache::instance().libraryPaths(m_duContext->url()); |
| 212 | auto fragmentPath = fragment; |
| 213 | fragmentPath.replace(QLatin1Char('.'), QLatin1Char('/')); |
| 214 | for (const auto& path : paths) { |
| 215 | addModules(path.cd(fragmentPath).path()); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | return items; |
| 220 | } |
| 221 | |
| 222 | QList<CompletionTreeItemPointer> CodeCompletionContext::nodeModuleCompletions() |
| 223 | { |
nothing calls this directly
no test coverage detected