use of com.python.pydev.analysis.additionalinfo.IReferenceSearches in project Pydev by fabioz.
the class PySearchIndexQuery method run.
@Override
public IStatus run(IProgressMonitor monitor) throws OperationCanceledException {
SearchIndexResult searchResult = (SearchIndexResult) getSearchResult();
// Remove all so that we don't get duplicates on a search refresh.
searchResult.removeAll();
StringMatcherWithIndexSemantics stringMatcher = createStringMatcher();
Set<String> moduleNamesFilter = scopeAndData.getModuleNamesFilter();
OrderedMap<String, Set<String>> fieldNameToValues = new OrderedMap<>();
if (moduleNamesFilter != null && !moduleNamesFilter.isEmpty()) {
fieldNameToValues.put(IReferenceSearches.FIELD_MODULE_NAME, moduleNamesFilter);
}
Set<String> split = makeTextFieldPatternsToSearchFromText();
fieldNameToValues.put(IReferenceSearches.FIELD_CONTENTS, split);
final List<IPythonNature> pythonNatures = PyScopeAndData.getPythonNatures(scopeAndData);
monitor.beginTask("Search indexes", pythonNatures.size());
try {
for (IPythonNature nature : pythonNatures) {
AbstractAdditionalDependencyInfo info;
try {
info = AdditionalProjectInterpreterInfo.getAdditionalInfoForProject(nature);
} catch (MisconfigurationException e) {
Log.log(e);
continue;
}
IReferenceSearches referenceSearches = info.getReferenceSearches();
List<ModulesKey> search = referenceSearches.search(nature.getProject(), fieldNameToValues, new SubProgressMonitor(monitor, 1));
IFile workspaceFile;
for (ModulesKey modulesKey : search) {
File file = modulesKey.file;
if (file == null || !file.exists()) {
Log.logInfo(StringUtils.format("Ignoring: %s. File no longer exists.", file));
}
workspaceFile = FindWorkspaceFiles.getWorkspaceFile(file, nature.getProject());
if (workspaceFile == null) {
Log.logInfo(StringUtils.format("Ignoring: %s. Unable to resolve to a file in the Eclipse workspace.", file));
continue;
}
IDocument doc = FileUtilsFileBuffer.getDocFromResource(workspaceFile);
String text = doc.get();
createMatches(doc, text, stringMatcher, workspaceFile, searchResult, modulesKey);
}
}
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
Aggregations