Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow option to score code snippets above anything else #63

Open
robertjpayne opened this issue Feb 6, 2015 · 3 comments
Open

Allow option to score code snippets above anything else #63

robertjpayne opened this issue Feb 6, 2015 · 3 comments

Comments

@robertjpayne
Copy link

It would be nice if it fuzzy autocomplete would score code snippets above anything else if the snippet's completion text is an exact match.

@robertjpayne
Copy link
Author

Poking around I couldn't see anything that would give us the ability to check the completion is backed by a snippet/macro.

However, I implemented this by adding a bonus for exact matches:

- (double) scoreItem: (id<DVTTextCompletionItem>) item
        searchString: (NSString *) query
         matchedName: (NSString *) matchedName
          matchScore: (double) matchScore
       matchedRanges: (NSArray *) rangesArray
      priorityFactor: (double) priorityFactor
{
    double invertedPriority = (10.0 / MAX(item.priority, 1.0));
    priorityFactor = MAX(priorityFactor, 1.0);
    NSRange range = [[rangesArray firstObject] rangeValue];
    double prefixBonus = range.location ? 1.0 : 1.0 + (_maxPrefixBonus * range.length) / query.length;
    double matchBonus = [query isEqualToString:matchedName] ? 10.0 : 1.0;
    return matchBonus * pow(matchScore, _matchScorePower) * pow(priorityFactor, _priorityFactorPower) * pow(invertedPriority, _priorityPower) * prefixBonus;
}

I'll see how I go with coding now and if it's a good fit or not.

@slazyk
Copy link
Member

slazyk commented Feb 20, 2015

Actually you can, you just need to check [item class]. For snippets it is IDECodeSnippetCompletionItem.

But snippets have low item.priority giving high invertedPriority which you can make more important in scoring by simply increasing _priorityPower which in the Advanced Settings is called 'Context'.

Also, matchScore already contains bonus for exact matches from IDEOpenQuicklyPattern. And you can increase bonus of prefix matches over non-prefix matches by adjusting _maxPrefixBonus called 'Prefix' in Advanced Settings.

If it turns out this kind of bonus is really needed, it is also a good idea to try to keep the scoring function as continuous as possible, with the bonus increasing as the match approaches exact match, for example by adding a power to prefix bonus rather than introducing bonus just for exact match.

@HiveHicks
Copy link

+1 for this option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants