Search in sources :

Example 11 with AbstractAdditionalTokensInfo

use of com.python.pydev.analysis.additionalinfo.AbstractAdditionalTokensInfo in project Pydev by fabioz.

the class CtxParticipant method computeConsoleCompletions.

// Console completions ---------------------------------------------------------------------------------------------
/**
 * IPyDevCompletionParticipant2
 */
@Override
public Collection<ICompletionProposalHandle> computeConsoleCompletions(ActivationTokenAndQualifier tokenAndQual, Set<IPythonNature> naturesUsed, IScriptConsoleViewer viewer, int requestOffset) {
    List<ICompletionProposalHandle> completions = new ArrayList<ICompletionProposalHandle>();
    if (tokenAndQual.activationToken != null && tokenAndQual.activationToken.length() > 0) {
        // we only want
        return completions;
    }
    String qual = tokenAndQual.qualifier;
    if (qual.length() >= PyCodeCompletionPreferences.getCharsForContextInsensitiveGlobalTokensCompletion() && naturesUsed != null && naturesUsed.size() > 0) {
        // at least n characters required...
        boolean addAutoImport = AnalysisPreferences.doAutoImport(null);
        int qlen = qual.length();
        boolean useSubstringMatchInCodeCompletion = PyCodeCompletionPreferences.getUseSubstringMatchInCodeCompletion();
        IFilter nameFilter = PyCodeCompletionUtils.getNameFilter(useSubstringMatchInCodeCompletion, qual);
        for (IPythonNature nature : naturesUsed) {
            AbstractAdditionalTokensInfo additionalInfo;
            try {
                if (nature instanceof SystemPythonNature) {
                    SystemPythonNature systemPythonNature = (SystemPythonNature) nature;
                    additionalInfo = AdditionalSystemInterpreterInfo.getAdditionalSystemInfo(systemPythonNature.getRelatedInterpreterManager(), systemPythonNature.getProjectInterpreter().getExecutableOrJar());
                    fillNatureCompletionsForConsole(viewer, requestOffset, completions, qual, addAutoImport, qlen, nameFilter, nature, additionalInfo, useSubstringMatchInCodeCompletion);
                } else {
                    additionalInfo = AdditionalProjectInterpreterInfo.getAdditionalInfoForProject(nature);
                    fillNatureCompletionsForConsole(viewer, requestOffset, completions, qual, addAutoImport, qlen, nameFilter, nature, additionalInfo, useSubstringMatchInCodeCompletion);
                }
            } catch (MisconfigurationException e) {
                Log.log(e);
            }
        }
    }
    return completions;
}
Also used : IFilter(org.python.pydev.ast.codecompletion.PyCodeCompletionUtils.IFilter) MisconfigurationException(org.python.pydev.core.MisconfigurationException) ArrayList(java.util.ArrayList) IPythonNature(org.python.pydev.core.IPythonNature) SystemPythonNature(org.python.pydev.plugin.nature.SystemPythonNature) ICompletionProposalHandle(org.python.pydev.shared_core.code_completion.ICompletionProposalHandle) AbstractAdditionalTokensInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalTokensInfo)

Example 12 with AbstractAdditionalTokensInfo

use of com.python.pydev.analysis.additionalinfo.AbstractAdditionalTokensInfo in project Pydev by fabioz.

the class GlobalsDialogFactory method create.

/**
 * Creates the dialog according to the Eclipse version we have (on 3.2, the old API is used)
 * @param pythonNatures
 */
public static SelectionDialog create(Shell shell, List<AbstractAdditionalTokensInfo> additionalInfo, String selectedText) {
    boolean expectedError = true;
    try {
        GlobalsTwoPanelElementSelector2 newDialog = new GlobalsTwoPanelElementSelector2(shell, true, selectedText);
        // If we were able to instance it, the error is no longer expected!
        expectedError = false;
        newDialog.setElements(additionalInfo);
        return newDialog;
    } catch (Throwable e) {
        // That's OK: it's only available for Eclipse 3.3 onwards.
        if (expectedError) {
            Log.log(e);
        }
    }
    // If it got here, we were unable to create the new dialog (show the old -- compatible with 3.2)
    GlobalsTwoPaneElementSelector dialog;
    dialog = new GlobalsTwoPaneElementSelector(shell);
    dialog.setMessage("Filter");
    if (selectedText != null && selectedText.length() > 0) {
        dialog.setFilter(selectedText);
    }
    List<IInfo> lst = new ArrayList<IInfo>();
    for (AbstractAdditionalTokensInfo info : additionalInfo) {
        lst.addAll(info.getAllTokens());
    }
    dialog.setElements(lst.toArray());
    return dialog;
}
Also used : IInfo(org.python.pydev.core.IInfo) ArrayList(java.util.ArrayList) AbstractAdditionalTokensInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalTokensInfo)

Example 13 with AbstractAdditionalTokensInfo

use of com.python.pydev.analysis.additionalinfo.AbstractAdditionalTokensInfo in project Pydev by fabioz.

the class AnalysisRequestsTestWorkbench method testRefreshAnalyzesFiles.

public void testRefreshAnalyzesFiles() throws Exception {
    editor.close(false);
    // just to have any parse events consumed
    goToIdleLoopUntilCondition(getInitialParsesCondition(), getParsesDone(), false);
    // give it a bit more time...
    goToManual(TIME_FOR_ANALYSIS);
    PythonNature nature = PythonNature.getPythonNature(mod1);
    AbstractAdditionalTokensInfo info = AdditionalProjectInterpreterInfo.getAdditionalInfoForProject(nature);
    // all modules are empty
    assertEquals(new HashSet<String>(), info.getAllModulesWithTokens());
    ICallback<Object, IResource> analysisCallback = getAnalysisCallback();
    AnalysisBuilderRunnable.analysisBuilderListeners.add(analysisCallback);
    try {
        checkSetInvalidContents();
        checkSetValidContents(info);
        checkSetValidContentsWithFooToken(info);
        checkRename(info);
        checkSetValidContents(info);
        // can analyze when editor is opened
        resourcesAnalyzed.clear();
        print("-------- Opening editor ----------");
        editor = (PyEdit) PyOpenEditor.doOpenEditor(mod1);
        goToIdleLoopUntilCondition(get1ResourceAnalyzed(), getResourcesAnalyzed());
        assertEquals(1, resourcesAnalyzed.size());
        // wait for it to complete (if it's too close it may consider it being the same analysis request even with a different time)
        goToManual(TIME_FOR_ANALYSIS);
        // analyze when forced
        resourcesAnalyzed.clear();
        AnalyzeOnRequestAction analyzeOnRequestAction = new AnalyzeOnRequestSetter.AnalyzeOnRequestAction(editor);
        analyzeOnRequestAction.run();
        // in 1 seconds, 1 analysis should happen
        goToManual(TIME_FOR_ANALYSIS);
        assertEquals(1, resourcesAnalyzed.size());
    } finally {
        AnalysisBuilderRunnable.analysisBuilderListeners.remove(analysisCallback);
    }
    CheckRefreshAnalyzesFilesOnlyOnActiveEditor();
}
Also used : AnalyzeOnRequestAction(com.python.pydev.analysis.actions.AnalyzeOnRequestSetter.AnalyzeOnRequestAction) PythonNature(org.python.pydev.plugin.nature.PythonNature) AbstractAdditionalTokensInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalTokensInfo) IResource(org.eclipse.core.resources.IResource)

Aggregations

AbstractAdditionalTokensInfo (com.python.pydev.analysis.additionalinfo.AbstractAdditionalTokensInfo)13 MisconfigurationException (org.python.pydev.core.MisconfigurationException)7 ArrayList (java.util.ArrayList)6 IInfo (org.python.pydev.core.IInfo)6 IPythonNature (org.python.pydev.core.IPythonNature)5 ModulesKey (org.python.pydev.core.ModulesKey)4 Tuple (org.python.pydev.shared_core.structure.Tuple)4 HashSet (java.util.HashSet)3 List (java.util.List)3 SourceModule (org.python.pydev.ast.codecompletion.revisited.modules.SourceModule)3 IModulesManager (org.python.pydev.core.IModulesManager)3 AdditionalProjectInterpreterInfo (com.python.pydev.analysis.additionalinfo.AdditionalProjectInterpreterInfo)2 File (java.io.File)2 IProject (org.eclipse.core.resources.IProject)2 IResource (org.eclipse.core.resources.IResource)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 PyFileInfo (org.python.pydev.ast.listing_utils.PyFileListing.PyFileInfo)2 ICodeCompletionASTManager (org.python.pydev.core.ICodeCompletionASTManager)2 FastStringBuffer (org.python.pydev.shared_core.string.FastStringBuffer)2