mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Middle Matching Disrupts My Workflow (IDEA-89279)
This commit is contained in:
+2
-37
@@ -243,7 +243,7 @@ public class CompletionServiceImpl extends CompletionService{
|
||||
for (final Weigher weigher : WeighingService.getWeighers(CompletionService.RELEVANCE_KEY)) {
|
||||
final String id = weigher.toString();
|
||||
if ("prefix".equals(id)) {
|
||||
sorter = sorter.withClassifier(CompletionSorterImpl.weighingFactory(new PrefixMatchingClassifier(location)));
|
||||
sorter = sorter.withClassifier(CompletionSorterImpl.weighingFactory(new RealPrefixMatchingWeigher(location)));
|
||||
}
|
||||
else if ("stats".equals(id)) {
|
||||
sorter = sorter.withClassifier(CompletionSorterImpl.weighingFactory(new StatisticsWeigher.LookupStatisticsWeigher(location)));
|
||||
@@ -276,25 +276,11 @@ public class CompletionServiceImpl extends CompletionService{
|
||||
return new CompletionSorterImpl(new ArrayList<ClassifierFactory<LookupElement>>());
|
||||
}
|
||||
|
||||
private static class PreferStartMatching extends LookupElementWeigher {
|
||||
private final CompletionLocation myLocation;
|
||||
|
||||
public PreferStartMatching(CompletionLocation location) {
|
||||
super("middleMatching", false, true);
|
||||
myLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparable weigh(@NotNull LookupElement element) {
|
||||
return !isStartMatch(element, myLocation.getCompletionParameters().getLookup());
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isStartMatch(LookupElement element, Lookup lookup) {
|
||||
return getItemMatcher(element, lookup).isStartMatch(element);
|
||||
}
|
||||
|
||||
private static PrefixMatcher getItemMatcher(LookupElement element, Lookup lookup) {
|
||||
static PrefixMatcher getItemMatcher(LookupElement element, Lookup lookup) {
|
||||
PrefixMatcher itemMatcher = lookup.itemMatcher(element);
|
||||
String pattern = lookup.itemPattern(element);
|
||||
if (!pattern.equals(itemMatcher.getPrefix())) {
|
||||
@@ -302,25 +288,4 @@ public class CompletionServiceImpl extends CompletionService{
|
||||
}
|
||||
return itemMatcher;
|
||||
}
|
||||
|
||||
private static class PrefixMatchingClassifier extends LookupElementWeigher {
|
||||
private final CompletionLocation myLocation;
|
||||
|
||||
public PrefixMatchingClassifier(CompletionLocation location) {
|
||||
super("prefix", false, true);
|
||||
myLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparable weigh(@NotNull LookupElement element) {
|
||||
final PrefixMatcher matcher = getItemMatcher(element, myLocation.getCompletionParameters().getLookup());
|
||||
|
||||
int max = Integer.MIN_VALUE;
|
||||
for (String lookupString : element.getAllLookupStrings()) {
|
||||
max = Math.max(max, matcher.matchingDegree(lookupString));
|
||||
}
|
||||
return -max;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.intellij.codeInsight.completion.impl;
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionLocation;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupElementWeigher;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Peter
|
||||
*/
|
||||
public class PreferStartMatching extends LookupElementWeigher {
|
||||
private final CompletionLocation myLocation;
|
||||
|
||||
public PreferStartMatching(CompletionLocation location) {
|
||||
super("middleMatching", false, true);
|
||||
myLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparable weigh(@NotNull LookupElement element) {
|
||||
return !CompletionServiceImpl.isStartMatch(element, myLocation.getCompletionParameters().getLookup());
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.intellij.codeInsight.completion.impl;
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionLocation;
|
||||
import com.intellij.codeInsight.completion.PrefixMatcher;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupElementWeigher;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Peter
|
||||
*/
|
||||
public class RealPrefixMatchingWeigher extends LookupElementWeigher {
|
||||
private final CompletionLocation myLocation;
|
||||
|
||||
public RealPrefixMatchingWeigher(CompletionLocation location) {
|
||||
super("prefix", false, true);
|
||||
myLocation = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comparable weigh(@NotNull LookupElement element) {
|
||||
final PrefixMatcher matcher = CompletionServiceImpl.getItemMatcher(element, myLocation.getCompletionParameters().getLookup());
|
||||
|
||||
int max = Integer.MIN_VALUE;
|
||||
for (String lookupString : element.getAllLookupStrings()) {
|
||||
max = Math.max(max, matcher.matchingDegree(lookupString));
|
||||
}
|
||||
return -max;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user