/** IPyDevCompletionParticipant */ @SuppressWarnings("unchecked") public Collection getCompletionsForMethodParameter( ICompletionState state, ILocalScope localScope, Collection<IToken> interfaceForLocal) { ArrayList<IToken> ret = new ArrayList<IToken>(); String qual = state.getQualifier(); if (qual.length() >= CodeCompletionPreferencesPage .getCharsForContextInsensitiveGlobalTokensCompletion()) { // at least n characters List<IInfo> tokensStartingWith; try { tokensStartingWith = AdditionalProjectInterpreterInfo.getTokensStartingWith( qual, state.getNature(), AbstractAdditionalInterpreterInfo.INNER); } catch (MisconfigurationException e) { PydevPlugin.log(e); return ret; } for (IInfo info : tokensStartingWith) { ret.add( new SourceToken( null, info.getName(), null, null, info.getDeclaringModuleName(), info.getType())); } } return ret; }
private void fillNatureCompletionsForConsole( IScriptConsoleViewer viewer, int requestOffset, List<ICompletionProposal> completions, String qual, boolean addAutoImport, int qlen, String lowerQual, IPythonNature nature, boolean getSystem) { AbstractAdditionalInterpreterInfo additionalInfoForProject; if (getSystem) { try { additionalInfoForProject = AdditionalSystemInterpreterInfo.getAdditionalSystemInfo( PydevPlugin.getInterpreterManager(nature), nature.getProjectInterpreter().getExecutableOrJar()); } catch (Exception e) { PydevPlugin.log(e); return; } } else { try { additionalInfoForProject = AdditionalProjectInterpreterInfo.getAdditionalInfoForProject(nature); } catch (Exception e) { PydevPlugin.log(e); return; } } List<IInfo> tokensStartingWith = additionalInfoForProject.getTokensStartingWith( qual, AbstractAdditionalInterpreterInfo.TOP_LEVEL); FastStringBuffer realImportRep = new FastStringBuffer(); FastStringBuffer displayString = new FastStringBuffer(); FastStringBuffer tempBuf = new FastStringBuffer(); for (IInfo info : tokensStartingWith) { // there always must be a declaringModuleName String declaringModuleName = info.getDeclaringModuleName(); boolean hasInit = false; if (declaringModuleName.endsWith(".__init__")) { declaringModuleName = declaringModuleName.substring( 0, declaringModuleName.length() - 9); // remove the .__init__ hasInit = true; } String rep = info.getName(); String lowerRep = rep.toLowerCase(); if (!lowerRep.startsWith(lowerQual)) { continue; } if (addAutoImport) { realImportRep.clear(); realImportRep.append("from "); realImportRep.append( AutoImportsPreferencesPage.removeImportsStartingWithUnderIfNeeded( declaringModuleName, tempBuf)); realImportRep.append(" import "); realImportRep.append(rep); } displayString.clear(); displayString.append(rep); displayString.append(" - "); displayString.append(declaringModuleName); if (hasInit) { displayString.append(".__init__"); } PyConsoleCompletion proposal = new PyConsoleCompletion( rep, requestOffset - qlen, qlen, realImportRep.length(), AnalysisPlugin.getImageForAutoImportTypeInfo(info), displayString.toString(), (IContextInformation) null, "", lowerRep.equals(lowerQual) ? IPyCompletionProposal.PRIORITY_LOCALS_1 : IPyCompletionProposal.PRIORITY_GLOBALS, realImportRep.toString(), viewer); completions.add(proposal); } }
private Collection<CtxInsensitiveImportComplProposal> getThem( CompletionRequest request, ICompletionState state, boolean addAutoImport) throws MisconfigurationException { ArrayList<CtxInsensitiveImportComplProposal> completions = new ArrayList<CtxInsensitiveImportComplProposal>(); if (request.isInCalltip) { return completions; } HashSet<String> importedNames = getImportedNames(state); String qual = request.qualifier; if (qual.length() >= CodeCompletionPreferencesPage .getCharsForContextInsensitiveGlobalTokensCompletion()) { // at least n characters // required... String lowerQual = qual.toLowerCase(); String initialModule = request.resolveModule(); List<IInfo> tokensStartingWith = AdditionalProjectInterpreterInfo.getTokensStartingWith( qual, request.nature, AbstractAdditionalInterpreterInfo.TOP_LEVEL); FastStringBuffer realImportRep = new FastStringBuffer(); FastStringBuffer displayString = new FastStringBuffer(); FastStringBuffer tempBuf = new FastStringBuffer(); for (IInfo info : tokensStartingWith) { // there always must be a declaringModuleName String declaringModuleName = info.getDeclaringModuleName(); if (initialModule != null && declaringModuleName != null) { if (initialModule.equals(declaringModuleName)) { continue; } } boolean hasInit = false; if (declaringModuleName.endsWith(".__init__")) { declaringModuleName = declaringModuleName.substring( 0, declaringModuleName.length() - 9); // remove the .__init__ hasInit = true; } String rep = info.getName(); String lowerRep = rep.toLowerCase(); if (!lowerRep.startsWith(lowerQual) || importedNames.contains(rep)) { continue; } if (addAutoImport) { realImportRep.clear(); realImportRep.append("from "); realImportRep.append( AutoImportsPreferencesPage.removeImportsStartingWithUnderIfNeeded( declaringModuleName, tempBuf)); realImportRep.append(" import "); realImportRep.append(rep); } displayString.clear(); displayString.append(rep); displayString.append(" - "); displayString.append(declaringModuleName); if (hasInit) { displayString.append(".__init__"); } CtxInsensitiveImportComplProposal proposal = new CtxInsensitiveImportComplProposal( rep, request.documentOffset - request.qlen, request.qlen, realImportRep.length(), AnalysisPlugin.getImageForAutoImportTypeInfo(info), displayString.toString(), (IContextInformation) null, "", lowerRep.equals(lowerQual) ? IPyCompletionProposal.PRIORITY_LOCALS_1 : IPyCompletionProposal.PRIORITY_GLOBALS, realImportRep.toString()); completions.add(proposal); } } return completions; }