1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-25 17:23:56 +02:00

Bug 72391 - When completing a function, do not insert parentheses if they are already present

Change-Id: Ia4beb5e7ee288c48f2dbde45b1f34a562b939cab
This commit is contained in:
Nathan Ridge 2017-01-11 20:53:00 -05:00
parent 81cbe87666
commit 07ca5174d5
3 changed files with 28 additions and 2 deletions

View file

@ -1676,4 +1676,12 @@ public class CompletionTests extends CompletionTestBase {
assertCompletionResults(fCursorOffset, expected, ID);
assertDotReplacedWithArrow();
}
// void waldo();
// int main() {
// wal/*cursor*/();
// }
public void testExistingParens_72391() throws Exception {
assertCompletionResults(new String[] { "waldo" }); // expect no parens in replacement
}
}

View file

@ -195,6 +195,17 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont
return token == Symbols.TokenSEMICOLON;
}
};
private final Lazy<Boolean> followedByOpeningParen = new Lazy<Boolean>() {
@Override
protected Boolean calculateValue() {
final IDocument doc = getDocument();
final int offset = getInvocationOffset();
final CHeuristicScanner.TokenStream tokenStream = new CHeuristicScanner.TokenStream(doc, offset);
final int token = tokenStream.nextToken();
return token == Symbols.TokenLPAREN;
}
};
private final Lazy<String> functionParameterDelimiter = new Lazy<String>() {
@Override
@ -452,6 +463,11 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont
assertNotDisposed();
return followedBySemicolon.value();
}
public boolean isFollowedByOpeningParen() {
assertNotDisposed();
return followedByOpeningParen.value();
}
public String getFunctionParameterDelimiter() {
assertNotDisposed();

View file

@ -614,8 +614,10 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
// Instead, emitting a semicolon is useful.
boolean inUsingDeclaration = context.isInUsingDirective();
if (!inUsingDeclaration) {
repStringBuff.append('(');
repStringBuff.append(')');
if (!context.isFollowedByOpeningParen()) {
repStringBuff.append('(');
repStringBuff.append(')');
}
} else if (!context.isFollowedBySemicolon()) {
repStringBuff.append(';');
}