mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-26 19:06:24 +07:00
WEB-7112 Emmet: completion for results of the fuzzy search
WEB-8369 Allow user configured order of auto completion suggestions
This commit is contained in:
+15
-12
@@ -67,8 +67,8 @@ public class LiveTemplateCompletionContributor extends CompletionContributor {
|
||||
|
||||
if (parameters.getInvocationCount() > 0) return; //only in autopopups for now
|
||||
|
||||
final String prefix = result.getPrefixMatcher().getPrefix();
|
||||
final TemplateImpl template = findApplicableTemplate(file, offset, prefix, parameters.getLookup().getEditor());
|
||||
String templatePrefix = findLiveTemplatePrefix(file, parameters.getLookup().getEditor(), result.getPrefixMatcher().getPrefix());
|
||||
final TemplateImpl template = findApplicableTemplate(file, offset, templatePrefix);
|
||||
if (template != null) {
|
||||
result = result.withPrefixMatcher(template.getKey());
|
||||
result.addElement(new LiveTemplateLookupElement(template, true));
|
||||
@@ -108,22 +108,25 @@ public class LiveTemplateCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static TemplateImpl findApplicableTemplate(final PsiFile file, int offset, final String key, final Editor editor) {
|
||||
final Set<String> possiblePrefixes = ContainerUtil.newLinkedHashSet(key);
|
||||
public static TemplateImpl findApplicableTemplate(final PsiFile file, int offset, @NotNull final String possiblePrefix) {
|
||||
return ContainerUtil.find(listApplicableTemplates(file, offset), new Condition<TemplateImpl>() {
|
||||
@Override
|
||||
public boolean value(TemplateImpl template) {
|
||||
return possiblePrefix.equals(template.getKey());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String findLiveTemplatePrefix(@NotNull PsiFile file, @NotNull Editor editor, @NotNull String defaultValue) {
|
||||
final CustomTemplateCallback callback = new CustomTemplateCallback(editor, file, false);
|
||||
for (CustomLiveTemplate customLiveTemplate : CustomLiveTemplate.EP_NAME.getExtensions()) {
|
||||
final String customKey = customLiveTemplate.computeTemplateKey(callback);
|
||||
if (customKey != null) {
|
||||
possiblePrefixes.add(customKey);
|
||||
return customKey;
|
||||
}
|
||||
}
|
||||
|
||||
return ContainerUtil.find(listApplicableTemplates(file, offset), new Condition<TemplateImpl>() {
|
||||
@Override
|
||||
public boolean value(TemplateImpl template) {
|
||||
return possiblePrefixes.contains(template.getKey());
|
||||
}
|
||||
});
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public static class Skipper extends CompletionPreselectSkipper {
|
||||
|
||||
+7
-1
@@ -31,11 +31,17 @@ public class LiveTemplateLookupElement extends LookupElement {
|
||||
private final String myPrefix;
|
||||
private final TemplateImpl myTemplate;
|
||||
public final boolean sudden;
|
||||
private final boolean myWorthShowingInAutoPopup;
|
||||
|
||||
public LiveTemplateLookupElement(TemplateImpl template, boolean sudden) {
|
||||
this(template, sudden, false);
|
||||
}
|
||||
|
||||
public LiveTemplateLookupElement(TemplateImpl template, boolean sudden, boolean worthShowingInAutoPopup) {
|
||||
this.sudden = sudden;
|
||||
myPrefix = template.getKey();
|
||||
myTemplate = template;
|
||||
myWorthShowingInAutoPopup = worthShowingInAutoPopup;
|
||||
}
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -75,6 +81,6 @@ public class LiveTemplateLookupElement extends LookupElement {
|
||||
|
||||
@Override
|
||||
public boolean isWorthShowingInAutoPopup() {
|
||||
return false;
|
||||
return myWorthShowingInAutoPopup;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class ZenCodingTemplate implements CustomLiveTemplate {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static ZenCodingNode parse(@NotNull String text,
|
||||
public static ZenCodingNode parse(@NotNull String text,
|
||||
@NotNull CustomTemplateCallback callback,
|
||||
@NotNull ZenCodingGenerator generator, @Nullable String surroundedText) {
|
||||
List<ZenCodingToken> tokens = new EmmetLexer().lex(text);
|
||||
@@ -154,12 +154,14 @@ public class ZenCodingTemplate implements CustomLiveTemplate {
|
||||
}
|
||||
|
||||
|
||||
private static void expand(String key,
|
||||
public static void expand(String key,
|
||||
@NotNull CustomTemplateCallback callback,
|
||||
String surroundedText,
|
||||
@NotNull ZenCodingGenerator defaultGenerator) {
|
||||
ZenCodingNode node = parse(key, callback, defaultGenerator, surroundedText);
|
||||
assert node != null;
|
||||
if (node == null) {
|
||||
return;
|
||||
}
|
||||
if (surroundedText == null) {
|
||||
if (node instanceof TemplateNode) {
|
||||
if (key.equals(((TemplateNode)node).getTemplateToken().getKey()) &&
|
||||
|
||||
Reference in New Issue
Block a user