Exemplo n.º 1
0
  /** 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;
  }
Exemplo n.º 2
0
  /** IPyDevCompletionParticipant2 */
  public Collection<ICompletionProposal> computeConsoleCompletions(
      ActivationTokenAndQual tokenAndQual,
      List<IPythonNature> naturesUsed,
      IScriptConsoleViewer viewer,
      int requestOffset) {
    List<ICompletionProposal> completions = new ArrayList<ICompletionProposal>();
    if (tokenAndQual.activationToken != null && tokenAndQual.activationToken.length() > 0) {
      // we only want
      return completions;
    }

    String qual = tokenAndQual.qualifier;
    if (qual.length()
            >= CodeCompletionPreferencesPage.getCharsForContextInsensitiveGlobalTokensCompletion()
        && naturesUsed != null
        && naturesUsed.size() > 0) { // at least n characters required...
      boolean addAutoImport = AutoImportsPreferencesPage.doAutoImport();
      int qlen = qual.length();
      String lowerQual = qual.toLowerCase();

      for (IPythonNature nature : naturesUsed) {
        fillNatureCompletionsForConsole(
            viewer,
            requestOffset,
            completions,
            qual,
            addAutoImport,
            qlen,
            lowerQual,
            nature,
            false);
      }

      // and at last, get from the system
      fillNatureCompletionsForConsole(
          viewer,
          requestOffset,
          completions,
          qual,
          addAutoImport,
          qlen,
          lowerQual,
          naturesUsed.get(0),
          true);
    }
    return completions;
  }
Exemplo n.º 3
0
  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;
  }