Skip to content

Commit

Permalink
Release 2.1.1
Browse files Browse the repository at this point in the history
Merge branch 'develop'.
  • Loading branch information
slazyk committed Sep 13, 2015
2 parents 7548473 + 62d285d commit 841b1b4
Show file tree
Hide file tree
Showing 17 changed files with 305 additions and 105 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## Changelog

#### 2.1.1 - 2015/09/13
**A minor update with improvements and bugfixes, including:**

* Support for Xcode 7
* Nicer list header, now on by default
* Improved Swift support
* Misc bugfixes

#### 2.1.0 - 2014/06/04
**An update with new features, improvements and bugfixes, including:**

Expand Down
8 changes: 6 additions & 2 deletions FuzzyAutocomplete.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
1C56EBE11B2646310001979E /* FAOpenQuicklyPattern.m in Sources */ = {isa = PBXBuildFile; fileRef = 1C56EBE01B2646310001979E /* FAOpenQuicklyPattern.m */; };
580BC1EC181243D600D53F1F /* DVTFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 580BC1EA181243D600D53F1F /* DVTFoundation.framework */; };
580BC1ED181243D600D53F1F /* DVTKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 580BC1EB181243D600D53F1F /* DVTKit.framework */; };
58501C0618165B0600AA3179 /* JRSwizzle.m in Sources */ = {isa = PBXBuildFile; fileRef = 58501C0518165B0600AA3179 /* JRSwizzle.m */; };
Expand All @@ -28,6 +29,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
1C56EBE01B2646310001979E /* FAOpenQuicklyPattern.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FAOpenQuicklyPattern.m; sourceTree = "<group>"; };
1C5CF4601918DB6200AF581C /* NSArray+FirstObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+FirstObject.h"; sourceTree = "<group>"; };
580BC1EA181243D600D53F1F /* DVTFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DVTFoundation.framework; path = ../../../../Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework; sourceTree = "<group>"; };
580BC1EB181243D600D53F1F /* DVTKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DVTKit.framework; path = ../../../../Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework; sourceTree = "<group>"; };
Expand All @@ -51,7 +53,7 @@
58DA96F21813D38A00D0082B /* DVTTextCompletionInlinePreviewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DVTTextCompletionInlinePreviewController.h; sourceTree = "<group>"; };
58DA96F31813D48D00D0082B /* DVTTextCompletionItem-Protocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "DVTTextCompletionItem-Protocol.h"; sourceTree = "<group>"; };
58E391E7181289A100C18DBF /* IDEIndexCompletionItem.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IDEIndexCompletionItem.h; sourceTree = "<group>"; };
58E9F98D18139EC5000928AF /* IDEOpenQuicklyPattern.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IDEOpenQuicklyPattern.h; sourceTree = "<group>"; };
58E9F98D18139EC5000928AF /* FAOpenQuicklyPattern.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FAOpenQuicklyPattern.h; sourceTree = "<group>"; };
58E9F98E1813A0FE000928AF /* IDEKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IDEKit.framework; path = ../../../../Applications/Xcode.app/Contents/Frameworks/IDEKit.framework; sourceTree = "<group>"; };
6503E741190AB08D00017267 /* DVTTextStorage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DVTTextStorage.h; sourceTree = "<group>"; };
6503E742190AB08D00017267 /* DVTTextStorageDelegate-Protocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "DVTTextStorageDelegate-Protocol.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -112,7 +114,6 @@
65E3D500190AAD8400A42F56 /* DVTCompletingTextView.h */,
58BA07BF18124BD50070060D /* DVTTextCompletionSession.h */,
58E391E7181289A100C18DBF /* IDEIndexCompletionItem.h */,
58E9F98D18139EC5000928AF /* IDEOpenQuicklyPattern.h */,
658A7C8218A13279007655E0 /* DVTPreferenceSet-Protocol.h */,
65DB740C18A12FBF001CDD83 /* DVTFontAndColorTheme.h */,
);
Expand Down Expand Up @@ -182,6 +183,8 @@
65599234189FFFD600C44208 /* DVTTextCompletionInlinePreviewController+FuzzyAutocomplete.m */,
655738C618F47F1E003FD40A /* FATextCompletionListHeaderView.h */,
655738C718F47F1E003FD40A /* FATextCompletionListHeaderView.m */,
58E9F98D18139EC5000928AF /* FAOpenQuicklyPattern.h */,
1C56EBE01B2646310001979E /* FAOpenQuicklyPattern.m */,
650C2FA4190B31600021BCD8 /* FAMatchPattern.h */,
650C2FA5190B31600021BCD8 /* FAMatchPattern.m */,
);
Expand Down Expand Up @@ -299,6 +302,7 @@
6540232C18F9F79700D580B3 /* FAItemScoringMethod.m in Sources */,
58501C0618165B0600AA3179 /* JRSwizzle.m in Sources */,
58C3C25A181128140031D9CD /* FuzzyAutocomplete.m in Sources */,
1C56EBE11B2646310001979E /* FAOpenQuicklyPattern.m in Sources */,
650C2FA6190B31600021BCD8 /* FAMatchPattern.m in Sources */,
650D4F5F18E5FCFF00F5DBEE /* FASettings.m in Sources */,
65EAE5DE18ECADF900F0974C /* FATheme.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,39 @@ @implementation FAPreviewItem {
+ (instancetype)previewItemForItem:(id<DVTTextCompletionItem>)item {
FAPreviewItem * ret = [FAPreviewItem new];
ret->_item = item;

NSString * completionText = item.completionText;
completionText = [completionText stringByReplacingOccurrencesOfString:@"<#" withString:@""];
completionText = [completionText stringByReplacingOccurrencesOfString:@"#>" withString:@""];
NSUInteger length = completionText.length;

NSRange searchRange = NSMakeRange(0, length);
NSUInteger closeToken, middleToken, openToken = [completionText rangeOfString: @"<#" options: 0 range: searchRange].location;

if (openToken != NSNotFound) {
NSMutableString * newCompletionText = [NSMutableString stringWithCapacity: length];
while (openToken != NSNotFound) {
searchRange.length = openToken - searchRange.location;
[newCompletionText appendString: [completionText substringWithRange: searchRange]];
searchRange.location = openToken + 2;
searchRange.length = length - openToken - 2;
closeToken = [completionText rangeOfString: @"#>" options: 0 range: searchRange].location;
if (closeToken != NSNotFound) {
searchRange.length = closeToken - openToken - 2;
middleToken = [completionText rangeOfString: @"##" options: 0 range: searchRange].location;
if (middleToken != NSNotFound) {
searchRange.length = middleToken - openToken - 2;
}
[newCompletionText appendString: [completionText substringWithRange: searchRange]];
searchRange.location = closeToken + 2;
searchRange.length = length - closeToken - 2;
}
openToken = [completionText rangeOfString: @"<#" options: 0 range: searchRange].location;
}
if (searchRange.location < length) {
[newCompletionText appendString: [completionText substringWithRange: searchRange]];
}
completionText = newCompletionText;
}

ret->_completionText = completionText;
return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ - (void) _fa_updateCurrentDisplayState {
// We modify titleColumnX with score column's width, so that title column is aligned with typed text
- (CGRect) _fa_preferredWindowFrameForTextFrame: (CGRect) textFrame columnsWidth: (double *) widths titleColumnX: (double) titleX {
NSTableView * tableView = [self valueForKey: @"_completionsTableView"];
return [self _fa_preferredWindowFrameForTextFrame: textFrame columnsWidth: widths titleColumnX: titleX + [self _fa_widthForScoreColumn] + tableView.intercellSpacing.width];
NSTableColumn * scoreColumn = [tableView tableColumnWithIdentifier: @"score"];
CGFloat additionalWidth = scoreColumn ? [self _fa_widthForScoreColumn] + tableView.intercellSpacing.width : 0;
return [self _fa_preferredWindowFrameForTextFrame: textFrame columnsWidth: widths titleColumnX: titleX + additionalWidth];
}


Expand Down Expand Up @@ -226,10 +228,10 @@ - (void) _fa_getTitleColumnWidth:(double *)titleWidth typeColumnWidth:(double *)
- (CGFloat) _fa_widthForScoreColumn {
NSTableView * tableView = [self valueForKey: @"_completionsTableView"];
NSTableColumn * scoreColumn = [tableView tableColumnWithIdentifier: @"score"];
if (scoreColumn && self.session.fa_nonZeroScores) {
DVTFontAndColorTheme * theme = [DVTFontAndColorTheme currentTheme];
if (scoreColumn && self.session.fa_nonZeroScores && theme.sourcePlainTextFont) {
NSNumberFormatter * formatter = ((NSCell *)scoreColumn.dataCell).formatter;
NSString * sampleValue = [formatter stringFromNumber: @0];
DVTFontAndColorTheme * theme = [DVTFontAndColorTheme currentTheme];
NSDictionary * attributes = @{ NSFontAttributeName : theme.sourcePlainTextFont };
return [[NSAttributedString alloc] initWithString: sampleValue attributes: attributes].size.width + 6;
} else {
Expand Down
95 changes: 77 additions & 18 deletions FuzzyAutocomplete/DVTTextCompletionSession+FuzzyAutocomplete.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ @implementation FAFilteringResults

@end

static NSString * _fa_IDESwiftCompletionItem_name(id self, SEL _cmd);

static IMP __fa_IDESwiftCompletionItem_name = (IMP) _fa_IDESwiftCompletionItem_name;

@implementation DVTTextCompletionSession (FuzzyAutocomplete)

+ (void) fa_swizzleMethods {
Expand Down Expand Up @@ -78,6 +82,13 @@ + (void) fa_swizzleMethods {
[self jr_swizzleMethod: @selector(hideCompletionsWithReason:)
withMethod: @selector(_fa_hideCompletionsWithReason:)
error: nil];

Class swiftCompletionClass = NSClassFromString(@"IDESwiftCompletionItem");
if (swiftCompletionClass) {
Method m = class_getInstanceMethod(swiftCompletionClass, NSSelectorFromString(@"name"));
__fa_IDESwiftCompletionItem_name = method_setImplementation(m, __fa_IDESwiftCompletionItem_name);
}

}

#pragma mark - public methods
Expand Down Expand Up @@ -213,10 +224,10 @@ - (void) _fa_selectNextPreviousByPriority: (BOOL) next {
NSArray * sorted = nil;
NSDictionary * filteredScores = self.fa_scoresForFilteredCompletions;
if ([FASettings currentSettings].sortByScore) {
sorted = self.filteredCompletionsAlpha.reverseObjectEnumerator.allObjects;
sorted = self.filteredCompletionsAlpha;
} else if (filteredScores) {
sorted = [self.filteredCompletionsAlpha sortedArrayWithOptions: NSSortConcurrent
usingComparator: [self _fa_itemComparatorByScores: filteredScores reverse: NO]];
usingComparator: [self _fa_itemComparatorByScores: filteredScores]];
}
[self setValue: sorted forKey: @"_filteredCompletionsPriority"];
}
Expand Down Expand Up @@ -409,6 +420,16 @@ - (void)_fa_setFilteringPrefix: (NSString *) prefix forceFilter: (BOOL) forceFil

self.fa_filteringTime = [NSDate timeIntervalSinceReferenceDate] - start;

if (![self _gotUsefulCompletionsToShowInList: results.filteredItems]) {
BOOL shownExplicitly = [[self valueForKey:@"_shownExplicitly"] boolValue];
if ([self.listWindowController showingWindow] && !shownExplicitly) {
[self.listWindowController hideWindowWithReason: 8];
}
if ([self._inlinePreviewController isShowingInlinePreview]) {
[self._inlinePreviewController hideInlinePreviewWithReason: 8];
}
}

NAMED_TIMER_START(SendNotifications);
// send the notifications in the same way the original does
[self willChangeValueForKey:@"filteredCompletionsAlpha"];
Expand All @@ -425,6 +446,14 @@ - (void)_fa_setFilteringPrefix: (NSString *) prefix forceFilter: (BOOL) forceFil
[self didChangeValueForKey:@"selectedCompletionIndex"];
NAMED_TIMER_STOP(SendNotifications);

if ([[NSCharacterSet decimalDigitCharacterSet] characterIsMember: [prefix characterAtIndex:0]]) {
BOOL shownExplicitly = [[self valueForKey:@"_shownExplicitly"] boolValue];
if (!shownExplicitly) {
[self._inlinePreviewController hideInlinePreviewWithReason: 2];
[self.listWindowController hideWindowWithReason: 2];
}
}

if (![FASettings currentSettings].showInlinePreview) {
[self._inlinePreviewController hideInlinePreviewWithReason: 0x0];
}
Expand Down Expand Up @@ -456,7 +485,7 @@ - (NSUInteger) _fa_getSelectionForFilteringResults: (FAFilteringResults *) resul
if (lastRange.location == lastRangePrev.location && lastRange.length >= lastRangePrev.length) {
NSComparator comparator = nil;
if ([FASettings currentSettings].sortByScore) {
comparator = [self _fa_itemComparatorByScores: results.scores reverse: YES];
comparator = [self _fa_itemComparatorByScores: results.scores];
} else {
comparator = [self _fa_itemComparatorByName];
}
Expand Down Expand Up @@ -586,7 +615,7 @@ - (FAFilteringResults *)_fa_calculateResultsForQuery: (NSString *) query {

NAMED_TIMER_START(SortByScore);
if ([FASettings currentSettings].sortByScore) {
[filteredList sortWithOptions: NSSortConcurrent usingComparator: [self _fa_itemComparatorByScores: filteredScores reverse: YES]];
[filteredList sortWithOptions: NSSortConcurrent usingComparator: [self _fa_itemComparatorByScores: filteredScores]];
}
NAMED_TIMER_STOP(SortByScore);

Expand Down Expand Up @@ -857,18 +886,11 @@ - (NSComparator) _fa_itemComparatorByName {
}

// gets a comparator for given scores dictionary
- (NSComparator) _fa_itemComparatorByScores: (NSDictionary *) filteredScores reverse: (BOOL) reverse {
if (!reverse) {
return ^(id<DVTTextCompletionItem> obj1, id<DVTTextCompletionItem> obj2) {
NSComparisonResult result = [filteredScores[obj1.name] compare: filteredScores[obj2.name]];
return result == NSOrderedSame ? [obj2.name caseInsensitiveCompare: obj1.name] : result;
};
} else {
return ^(id<DVTTextCompletionItem> obj1, id<DVTTextCompletionItem> obj2) {
NSComparisonResult result = [filteredScores[obj2.name] compare: filteredScores[obj1.name]];
return result == NSOrderedSame ? [obj1.name caseInsensitiveCompare: obj2.name] : result;
};
}
- (NSComparator) _fa_itemComparatorByScores: (NSDictionary *) filteredScores {
return ^(id<DVTTextCompletionItem> obj1, id<DVTTextCompletionItem> obj2) {
NSComparisonResult result = [filteredScores[obj2.name] compare: filteredScores[obj1.name]];
return result == NSOrderedSame ? [obj1.name caseInsensitiveCompare: obj2.name] : result;
};
}

- (void)_fa_debugCompletionsByScore:(NSArray *)completions withQuery:(NSString *)query {
Expand All @@ -880,8 +902,8 @@ - (void)_fa_debugCompletionsByScore:(NSArray *)completions withQuery:(NSString *
double matchScore = [pattern scoreCandidate: item.name matchedRanges: &ranges];
double factor = [self _priorityFactorForItem: item];
[completionsWithScore addObject:@{
@"item" : item.name,
@"ranges" : ranges ? ranges : @[],
@"item" : item.name ?: @"",
@"ranges" : ranges ?: @[],
@"factor" : @(factor),
@"priority" : @(item.priority),
@"matchScore" : @(matchScore),
Expand Down Expand Up @@ -962,3 +984,40 @@ - (FAFilteringResults *) _fa_lastFilteringResults {
}

@end

static NSString * _fa_IDESwiftCompletionItem_name(id self, SEL _cmd) {
NSString * name = objc_getAssociatedObject(self, _fa_IDESwiftCompletionItem_name);
if (name) {
return name;
}

id <DVTTextCompletionItem> item = self;
name = [item completionText];
NSUInteger length = name.length;

NSRange searchRange = NSMakeRange(0, length);
NSUInteger tokenLocation = [name rangeOfString: @"<#" options: 0 range: searchRange].location;

if (tokenLocation != NSNotFound) {
NSMutableString * newName = [NSMutableString stringWithCapacity: length];
while (tokenLocation != NSNotFound) {
searchRange.length = tokenLocation - searchRange.location;
[newName appendString: [name substringWithRange: searchRange]];
searchRange.location = tokenLocation + 2;
searchRange.length = length - tokenLocation - 2;
tokenLocation = [name rangeOfString: @"#>" options: 0 range: searchRange].location;
if (tokenLocation != NSNotFound) {
searchRange.location = tokenLocation + 2;
searchRange.length = length - tokenLocation - 2;
tokenLocation = [name rangeOfString: @"<#" options: 0 range: searchRange].location;
}
}
if (searchRange.location < length) {
[newName appendString: [name substringWithRange: searchRange]];
}
name = newName;
}

objc_setAssociatedObject(self, _fa_IDESwiftCompletionItem_name, name, OBJC_ASSOCIATION_RETAIN);
return name;
}
4 changes: 2 additions & 2 deletions FuzzyAutocomplete/FAMatchPattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
//
//

#import "IDEOpenQuicklyPattern.h"
#import "FAOpenQuicklyPattern.h"

/// Fuzzy Autocomplete Match Pattern
@interface FAMatchPattern : IDEOpenQuicklyPattern
@interface FAMatchPattern : FAOpenQuicklyPattern

- (instancetype) initWithPattern: (NSString *) patternString;

Expand Down
29 changes: 29 additions & 0 deletions FuzzyAutocomplete/FAOpenQuicklyPattern.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// FAOpenQuicklyPattern.h
// FuzzyAutocomplete
//
// Created by Leszek Ślażyński on 08/06/15.
//
//

/// Dummy class to be switched to real open quickly pattern on runtime
@interface FAOpenQuicklyPattern : NSObject {
NSString *_pattern;
BOOL _patternHasSeparators;
char *_charactersInPattern;
unsigned short *_patternCharacters;
unsigned short *_lowerCasePatternCharacters;
NSUInteger _patternLength;
}

@property(readonly) NSString * pattern;

- (instancetype) initWithPattern: (NSString *) patternString;
+ (instancetype) patternWithInput: (NSString *) input;
- (CGFloat) scoreCandidate: (NSString *) candidate matchedRanges: (NSArray **) rangesPtr;
- (NSArray *) matchedRanges: (NSString *) candidate;
- (CGFloat) scoreCandidate: (NSString *) candidate;
- (BOOL) matchesCandidate: (NSString *) candidate;

@end

42 changes: 42 additions & 0 deletions FuzzyAutocomplete/FAOpenQuicklyPattern.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// FAOpenQuicklyPattern.m
// FuzzyAutocomplete
//
// Created by Leszek Ślażyński on 08/06/15.
//
//

#import "FAOpenQuicklyPattern.h"

@implementation FAOpenQuicklyPattern

- (NSString *) pattern {
return nil;
}

- (instancetype) initWithPattern: (NSString *) patternString {
return nil;
}

+ (instancetype) patternWithInput: (NSString *) input {
return nil;
}

- (CGFloat) scoreCandidate: (NSString *) candidate matchedRanges: (NSArray **) rangesPtr {
return 0;
}

- (NSArray *) matchedRanges: (NSString *) candidate {
return nil;
}

- (CGFloat) scoreCandidate: (NSString *) candidate {
return 0;
}


- (BOOL) matchesCandidate: (NSString *) candidate {
return NO;
}

@end
3 changes: 3 additions & 0 deletions FuzzyAutocomplete/FASettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ extern NSString * FASettingsPluginEnabledDidChangeNotification;
/// Should the list header be visible.
@property (nonatomic, readonly) BOOL showListHeader;

/// Should the list header contain number of matches.
@property (nonatomic, readonly) BOOL showNumMatches;

/// Should the timing in the list header be visible.
@property (nonatomic, readonly) BOOL showTiming;

Expand Down
Loading

0 comments on commit 841b1b4

Please sign in to comment.