mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 17:26:01 +02:00
Bug 509731 - Completion between empty parentheses in simple-type-constructor-expression
Change-Id: Ibe87a0fdfb0e7c8dd1a1392bc9643bc03ac73c38
This commit is contained in:
parent
df6ebf09e9
commit
2e642428a4
2 changed files with 27 additions and 2 deletions
|
@ -1394,6 +1394,18 @@ public class CompletionTests extends AbstractContentAssistTest {
|
|||
assertCompletionResults(fCursorOffset, expected, ID);
|
||||
}
|
||||
|
||||
// struct Waldo {
|
||||
// Waldo(int, int);
|
||||
// };
|
||||
//
|
||||
// int main() {
|
||||
// Waldo waldo = Waldo(/*cursor*/)
|
||||
// }
|
||||
public void testConstructorCallWithEmptyParentheses_509731() throws Exception {
|
||||
final String[] expected = { "Waldo(const Waldo &)", "Waldo(int, int)" };
|
||||
assertCompletionResults(fCursorOffset, expected, ID);
|
||||
}
|
||||
|
||||
// template <typename T> struct vector {
|
||||
// typedef T value_type;
|
||||
// void push_back(const value_type& value) {}
|
||||
|
|
|
@ -18,6 +18,7 @@ import java.util.Map;
|
|||
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.ITextViewer;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
|
@ -130,8 +131,20 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont
|
|||
final int invocationOffset = getInvocationOffset();
|
||||
final int parseOffset = getParseOffset();
|
||||
final int bound = Math.max(-1, parseOffset - 1);
|
||||
final CHeuristicScanner scanner = new CHeuristicScanner(getDocument());
|
||||
final int parenthesisOffset = scanner.findOpeningPeer(invocationOffset, bound, '(', ')');
|
||||
final IDocument document = getDocument();
|
||||
final CHeuristicScanner scanner = new CHeuristicScanner(document);
|
||||
int start = invocationOffset;
|
||||
try {
|
||||
// The documentation of CHeuristicScanner.findOpeningPeer() says
|
||||
// "Note that <code>start</code> must not point to the closing peer, but to the first
|
||||
// character being searched."
|
||||
// If we are completing in between two empty parentheses with no space between them,
|
||||
// this condition won't be satisfied, so we start the search one character earlier.
|
||||
if (document.getChar(start) == ')')
|
||||
start -= 1;
|
||||
} catch (BadLocationException e) {
|
||||
}
|
||||
final int parenthesisOffset = scanner.findOpeningPeer(start, bound, '(', ')');
|
||||
return parenthesisOffset != CHeuristicScanner.NOT_FOUND;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue