use of com.jetbrains.python.console.pydev.PydevCompletionVariant in project intellij-community by JetBrains.
the class PydevConsoleReference method getVariants.
@NotNull
public Object[] getVariants() {
Map<String, LookupElement> variants = Maps.newHashMap();
try {
final List<PydevCompletionVariant> completions = myCommunication.getCompletions(getText(), myPrefix);
for (PydevCompletionVariant completion : completions) {
final PsiManager manager = myElement.getManager();
final String name = completion.getName();
final int type = completion.getType();
LookupElementBuilder builder = LookupElementBuilder.create(new PydevConsoleElement(manager, name, completion.getDescription())).withIcon(PyCodeCompletionImages.getImageForType(type));
String args = completion.getArgs();
if (args.equals("(%)")) {
builder.withPresentableText("%" + completion.getName());
builder = builder.withInsertHandler(new InsertHandler<LookupElement>() {
@Override
public void handleInsert(InsertionContext context, LookupElement item) {
final Editor editor = context.getEditor();
final Document document = editor.getDocument();
int offset = context.getStartOffset();
if (offset == 0 || !"%".equals(document.getText(TextRange.from(offset - 1, 1)))) {
document.insertString(offset, "%");
}
}
});
args = "";
} else if (!StringUtil.isEmptyOrSpaces(args)) {
builder = builder.withTailText(args);
}
// Set function insert handler
if (type == IToken.TYPE_FUNCTION || args.endsWith(")")) {
builder = builder.withInsertHandler(ParenthesesInsertHandler.WITH_PARAMETERS);
}
variants.put(name, builder);
}
} catch (Exception e) {
//LOG.error(e);
}
return variants.values().toArray();
}
use of com.jetbrains.python.console.pydev.PydevCompletionVariant in project intellij-community by JetBrains.
the class PydevXmlUtils method decodeCompletions.
public static List<PydevCompletionVariant> decodeCompletions(Object fromServer, String actTok) {
final List<PydevCompletionVariant> ret = new ArrayList<>();
List completionList = objectToList(fromServer);
for (Object o : completionList) {
List comp = objectToList(o);
//name, doc, args, type
final int type = extractInt(comp.get(3));
final String args = AbstractPyCodeCompletion.getArgs((String) comp.get(2), type, AbstractPyCodeCompletion.LOOKING_FOR_INSTANCED_VARIABLE);
String name = (String) comp.get(0);
if (name.contains(".") && name.startsWith(actTok)) {
name = name.substring(actTok.length());
}
ret.add(new PydevCompletionVariant(name, (String) comp.get(1), args, type));
}
return ret;
}
Aggregations