Skip to content

Commit

Permalink
[Bugfix #808] Tooltip for nested call
Browse files Browse the repository at this point in the history
Fix tooltip showing for nested method call.
Calculate number of parentheses to skip instead of looking for the first
one.
  • Loading branch information
robgom committed Jun 5, 2017
1 parent 4f4031e commit f5deaf6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1100,10 +1100,20 @@ private static int calculateProperCalltipOffset(IDocument doc, int calltipOffset
public static int getBeforeParentesisCall(Object doc, int calltipOffset) {
ParsingUtils parsingUtils = ParsingUtils.create(doc);
char c = parsingUtils.charAt(calltipOffset);
int parensBefore = 0;

while (calltipOffset > 0 && c != '(') {
calltipOffset--;
while (calltipOffset > 0) {
c = parsingUtils.charAt(calltipOffset);
if (c == ')') {
parensBefore += 1;
} else if (c == '(') {
if (parensBefore <= 0) {
break;
} else {
parensBefore -= 1;
}
}
calltipOffset--;
}
if (c == '(') {
while (calltipOffset > 0 && Character.isWhitespace(c)) {
Expand Down Expand Up @@ -1471,7 +1481,7 @@ private static boolean isDigit(char c) {
/**
* Return true if the completion is at the dot after a literal number.
* Literal numbers have no valid completions as they can be the first part of floats.
*
*
* @param activationToken this comes from either the console's ActivationTokenAndQual
* or editor's CompletionRequest
* @return true if this completion is for a number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3187,4 +3187,32 @@ public void testSubClassConstructorParams2() throws Exception {
assertEquals("Bar(a, b)", prop.getDisplayString());

}

public void testInsideMethodParams() throws Exception {
String s;
String original = "" +
"def foo(a, b):\n" +
" pass\n" +
"def bar(c, d):\n" +
" pass\n" +
"foo(bar(1, 2), %s";

s = StringUtils.format(original, "");

ICompletionProposal[] proposals = requestCompl(s, s.length() - 1, -1, new String[] {});
assertEquals(1, proposals.length);
ICompletionProposal prop = proposals[0];
assertEquals("foo(a, b)", prop.getDisplayString());

IPyCalltipsContextInformation contextInformation = (IPyCalltipsContextInformation) prop.getContextInformation();
assertEquals("a, b", contextInformation.getContextDisplayString());
assertEquals("a, b", contextInformation.getInformationDisplayString());

Document doc = new Document(s);
prop.apply(doc);
// TODO: code below not working - proposal not applied
String expected = StringUtils.format(original, "");
assertEquals(expected, doc.get());
}

}

0 comments on commit f5deaf6

Please sign in to comment.