MCPcopy Create free account
hub / github.com/KDE/kdevelop / importCompletion

Method importCompletion

plugins/qmljs/codecompletion/context.cpp:181–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

179}
180
181QList<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
222QList<CompletionTreeItemPointer> CodeCompletionContext::nodeModuleCompletions()
223{

Callers

nothing calls this directly

Calls 12

sectionMethod · 0.80
existsMethod · 0.80
libraryPathsMethod · 0.80
cdMethod · 0.80
isEmptyMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
appendMethod · 0.45
modulePathMethod · 0.45
urlMethod · 0.45
replaceMethod · 0.45
pathMethod · 0.45

Tested by

no test coverage detected