IDEA-118389 Forbid completion inside guard blocks; honor greediness

This commit is contained in:
peter
2014-01-17 18:03:44 +01:00
parent b7a28d606f
commit 0a359f16ec
3 changed files with 16 additions and 3 deletions
@@ -120,7 +120,8 @@ public class CodeCompletionHandlerBase {
CompletionAssertions.checkEditorValid(editor);
if (editor.isViewer() || editor.getDocument().getOffsetGuard(editor.getCaretModel().getOffset()) != null) {
int offset = editor.getCaretModel().getOffset();
if (editor.isViewer() || editor.getDocument().getRangeGuard(offset, offset) != null) {
editor.getDocument().fireReadOnlyModificationAttempt();
CodeInsightUtilBase.showReadOnlyViewWarning(editor);
return;
@@ -55,7 +55,8 @@ public class HippieWordCompletionHandler implements CodeInsightActionHandler {
public void invoke(@NotNull Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
if (editor.isViewer() || editor.getDocument().getOffsetGuard(editor.getCaretModel().getOffset()) != null) {
int offset = editor.getCaretModel().getOffset();
if (editor.isViewer() || editor.getDocument().getRangeGuard(offset, offset) != null) {
editor.getDocument().fireReadOnlyModificationAttempt();
CodeInsightUtilBase.showReadOnlyViewWarning(editor);
return;
@@ -78,13 +78,24 @@ public class GuardBlockTest extends LightPlatformCodeInsightFixtureTestCase {
public void testNoCompletion() throws Exception {
String text = "abc abd a<caret> abx";
myFixture.configureByText("x.txt", text);
createGuard(0, myFixture.getFile().getTextLength());
int offset = myFixture.getEditor().getCaretModel().getOffset();
createGuard(offset - 1, myFixture.getFile().getTextLength()).setGreedyToRight(true);
assertNull(myFixture.completeBasic());
myFixture.checkResult(text);
//no hippie completion
myFixture.performEditorAction(IdeActions.ACTION_HIPPIE_BACKWARD_COMPLETION);
assertNull(LookupManager.getInstance(getProject()).getActiveLookup());
myFixture.checkResult(text);
//no completion at the file end
myFixture.getEditor().getCaretModel().moveToOffset(myFixture.getFile().getTextLength());
assertNull(myFixture.completeBasic());
myFixture.checkResult("abc abd a abx<caret>");
//completion at the beginning of the guard fragment
myFixture.getEditor().getCaretModel().moveToOffset(offset - 1);
assertNotNull(myFixture.completeBasic());
}
}