Plain completion contributor: better api

use a boolean key to indicate plain prefix matcher need.
This commit is contained in:
Kirill Likhodedov
2014-07-07 17:12:54 +04:00
parent 3c8c2f559e
commit 9804bfcc8c
2 changed files with 6 additions and 7 deletions
@@ -40,13 +40,9 @@ public class ComboEditorCompletionContributor extends CompletionContributor{
final Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
if (document != null) {
JComboBox comboBox = document.getUserData(StringComboboxEditor.COMBO_BOX_KEY);
boolean plainPrefixMatcher = false;
if (comboBox == null) {
comboBox = document.getUserData(StringComboboxEditor.PLAIN_COMBO_BOX_KEY);
plainPrefixMatcher = true;
}
if (comboBox != null) {
String substring = document.getText().substring(0, parameters.getOffset());
boolean plainPrefixMatcher = Boolean.TRUE.equals(document.getUserData(StringComboboxEditor.USE_PLAIN_PREFIX_MATCHER));
final CompletionResultSet resultSet = plainPrefixMatcher ?
result.withPrefixMatcher(new PlainPrefixMatcher(substring)) :
result.withPrefixMatcher(substring);
@@ -39,7 +39,7 @@ import javax.swing.*;
*/
public class StringComboboxEditor extends EditorComboBoxEditor {
public static final Key<JComboBox> COMBO_BOX_KEY = Key.create("COMBO_BOX_KEY");
public static final Key<JComboBox> PLAIN_COMBO_BOX_KEY = Key.create("PLAIN_COMBO_BOX_KEY");
public static final Key<Boolean> USE_PLAIN_PREFIX_MATCHER = Key.create("USE_PLAIN_PREFIX_MATCHER");
private static final Logger LOG = Logger.getInstance("#com.intellij.ui.StringComboboxEditor");
private final Project myProject;
@@ -54,7 +54,10 @@ public class StringComboboxEditor extends EditorComboBoxEditor {
final PsiFile file = PsiFileFactory.getInstance(project).createFileFromText("a.dummy", StdFileTypes.PLAIN_TEXT, "", 0, true);
final Document document = PsiDocumentManager.getInstance(project).getDocument(file);
assert document != null;
document.putUserData(usePlainMatcher ? PLAIN_COMBO_BOX_KEY : COMBO_BOX_KEY, comboBox);
document.putUserData(COMBO_BOX_KEY, comboBox);
if (usePlainMatcher) {
document.putUserData(USE_PLAIN_PREFIX_MATCHER, true);
}
document.putUserData(UndoConstants.DONT_RECORD_UNDO, true);
super.setItem(document);
}