コード例 #1
0
  private List<ICompletionProposal> getInternalProposals(LuaVariableDetector wordPart) {
    LuaState L = LuaScriptsSpecs.getDefault().getLuaState();

    if (L == null) {
      return Collections.emptyList();
    }

    try {
      if (wordPart.getVariable() != null) {
        L.LdoString("return " + wordPart.getVariable());
      } else {
        L.getGlobal("_G");
      }
    } catch (Throwable e) {
      e.printStackTrace();
      return Collections.emptyList();
    }

    if (!L.isTable(-1)) {
      L.pop(1);
      return Collections.emptyList();
    }

    String stem = wordPart.getString();
    int wordOffset = wordPart.getOffset();

    ImageRegistry imageRegistry = BaseExtsPlugin.getDefault().getImageRegistry();

    ArrayList<ICompletionProposal> internalList = new ArrayList<ICompletionProposal>();

    L.pushNil();
    while (L.next(-2) != 0) {
      String key = L.toString(-2);

      if (!key.startsWith(wordPart.getString())) {

        String contextKey = null;
        if (wordPart.getVariable() != null) {
          contextKey = wordPart.getVariable() + "." + key;
        } else {
          contextKey = key;
        }

        String strLuaType = L.typeName(L.type(-1));
        // load function.gif, table.gif or string.gif
        Image image = imageRegistry.get(strLuaType);

        int cursorLocation = key.length();

        // To functions, use de ().
        if (FUNCTION_TYPE_NAME.equals(strLuaType)) {
          key += "()";
          cursorLocation += 1; // Put cursor inside "()"
        }

        IContextInformation info;
        info = new ContextInformation(contextKey, getContentInfoString(contextKey));

        ICompletionProposal proposal =
            new CompletionProposal(
                key, // Replacement string
                wordOffset,
                stem.length(), // Replacement offset & length
                cursorLocation, // Cursor location relative to offset
                image, // Display image
                key, // Display string
                info, // Context information
                getContentInfoString(key)); // Extra string information

        internalList.add(proposal);
      }
      L.pop(1); // removes `value'; keeps `key' for next iteration
    }
    L.pop(1);

    return internalList;
  }