Search in sources :

Example 1 with IReferenceSearches

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;
}
Also used : StringMatcherWithIndexSemantics(org.python.pydev.shared_ui.search.StringMatcherWithIndexSemantics) Set(java.util.Set) IFile(org.eclipse.core.resources.IFile) MisconfigurationException(org.python.pydev.core.MisconfigurationException) IPythonNature(org.python.pydev.core.IPythonNature) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IReferenceSearches(com.python.pydev.analysis.additionalinfo.IReferenceSearches) SearchIndexResult(org.python.pydev.shared_ui.search.SearchIndexResult) ModulesKey(org.python.pydev.core.ModulesKey) OrderedMap(org.python.pydev.shared_core.structure.OrderedMap) AbstractAdditionalDependencyInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

AbstractAdditionalDependencyInfo (com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo)1 IReferenceSearches (com.python.pydev.analysis.additionalinfo.IReferenceSearches)1 File (java.io.File)1 Set (java.util.Set)1 IFile (org.eclipse.core.resources.IFile)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 IDocument (org.eclipse.jface.text.IDocument)1 IPythonNature (org.python.pydev.core.IPythonNature)1 MisconfigurationException (org.python.pydev.core.MisconfigurationException)1 ModulesKey (org.python.pydev.core.ModulesKey)1 OrderedMap (org.python.pydev.shared_core.structure.OrderedMap)1 SearchIndexResult (org.python.pydev.shared_ui.search.SearchIndexResult)1 StringMatcherWithIndexSemantics (org.python.pydev.shared_ui.search.StringMatcherWithIndexSemantics)1