mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-30 20:35:38 +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:
parent
73d5df1550
commit
785b17a064
3 changed files with 25 additions and 1 deletions
|
@ -1734,4 +1734,12 @@ public class CompletionTests extends CompletionTestBase {
|
|||
final String[] expected = { "B", "A", "waldo" };
|
||||
assertCompletionResults(fCursorOffset, expected, ID);
|
||||
}
|
||||
|
||||
// void waldo();
|
||||
// int main() {
|
||||
// wal/*cursor*/();
|
||||
// }
|
||||
public void testExistingParens_72391() throws Exception {
|
||||
assertCompletionResults(new String[] { "waldo" }); // expect no parens in replacement
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -648,7 +648,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
|||
|
||||
boolean inUsingDeclaration = cContext.isInUsingDirective();
|
||||
|
||||
if (canBeCall) {
|
||||
if (canBeCall && !cContext.isFollowedByOpeningParen()) {
|
||||
// If we might be calling the function in this context, assume we are
|
||||
// (since that's the most common case) and emit parentheses.
|
||||
repStringBuff.append('(');
|
||||
|
|
Loading…
Add table
Reference in a new issue