Skip to content

Commit

Permalink
track changes to completion provider API
Browse files Browse the repository at this point in the history
  • Loading branch information
martinh committed Jul 8, 2012
1 parent e0b2ff3 commit 8be3de6
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 39 deletions.
3 changes: 1 addition & 2 deletions Support/lib/nu/complete.nu
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
(set @completions anArray)
(self))

(- (void) completionsForString:(id) aString options:(id) options target:(id)target action:(SEL)action is
(target performSelector:action withObject:@completions withObject:nil) ))
(- (id)completionsForString:(id)aString options:(id)options is @completions))

(unless (defined choices)
(shellCommand log:"missing choices")
Expand Down
10 changes: 4 additions & 6 deletions app/ExCommandCompletion.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

@implementation ExCommandCompletion

- (id<ViDeferred>)completionsForString:(NSString *)word
options:(NSString *)options
onResponse:(void (^)(NSArray *, NSError *))responseCallback
- (NSArray *)completionsForString:(NSString *)word
options:(NSString *)options
error:(NSError **)outError
{
BOOL fuzzySearch = ([options rangeOfString:@"f"].location != NSNotFound);
BOOL fuzzyTrigger = ([options rangeOfString:@"F"].location != NSNotFound);
Expand Down Expand Up @@ -38,9 +38,7 @@ @implementation ExCommandCompletion
}
}

responseCallback(commands, nil);

return nil;
return commands;
}

@end
Expand Down
10 changes: 4 additions & 6 deletions app/ViBufferCompletion.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

@implementation ViBufferCompletion

- (id<ViDeferred>)completionsForString:(NSString *)word
options:(NSString *)options
onResponse:(void (^)(NSArray *, NSError *))responseCallback
- (NSArray *)completionsForString:(NSString *)word
options:(NSString *)options
error:(NSError **)outError
{
BOOL fuzzySearch = ([options rangeOfString:@"f"].location != NSNotFound);
BOOL fuzzyTrigger = ([options rangeOfString:@"F"].location != NSNotFound);
Expand Down Expand Up @@ -42,9 +42,7 @@ @implementation ViBufferCompletion
}
}

responseCallback(buffers, nil);

return nil;
return buffers;
}

@end
28 changes: 18 additions & 10 deletions app/ViFileCompletion.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ - (void)appendFilter:(NSString *)string toPattern:(NSMutableString *)pattern
}
}

- (id<ViDeferred>)completionsForString:(NSString *)path
options:(NSString *)options
onResponse:(void (^)(NSArray *, NSError *))responseCallback
- (NSArray *)completionsForString:(NSString *)path
options:(NSString *)options
error:(NSError **)outError
{
NSURL *relURL = [[ViWindowController currentWindowController] baseURL];
DEBUG(@"relURL is %@", relURL);
Expand All @@ -32,8 +32,8 @@ - (void)appendFilter:(NSString *)string toPattern:(NSMutableString *)pattern
url = [NSURL URLWithString:
[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if (url == nil) {
responseCallback(nil, [ViError errorWithFormat:
@"failed to parse url %@", path]);
if (outError)
*outError = [ViError errorWithFormat:@"failed to parse url %@", path];
return nil;
}
if ([[url path] length] == 0) {
Expand Down Expand Up @@ -97,13 +97,17 @@ - (void)appendFilter:(NSString *)string toPattern:(NSMutableString *)pattern

ViURLManager *um = [ViURLManager defaultManager];

return [um contentsOfDirectoryAtURL:url onCompletion:^(NSArray *directoryContents, NSError *error) {
if (error) {
responseCallback(nil, error);
__block NSMutableArray *matches = nil;
__block NSError *error = nil;

id<ViDeferred> deferred = [um contentsOfDirectoryAtURL:url
onCompletion:^(NSArray *directoryContents, NSError *err) {
if (err) {
error = [err retain];
return;
}

NSMutableArray *matches = [NSMutableArray array];
matches = [[NSMutableArray alloc] init];
for (ViFile *file in directoryContents) {
NSRange r = NSIntersectionRange(NSMakeRange(0, [suffix length]),
NSMakeRange(0, [file.name length]));
Expand Down Expand Up @@ -138,8 +142,12 @@ - (void)appendFilter:(NSString *)string toPattern:(NSMutableString *)pattern
[matches addObject:c];
}
}
responseCallback(matches, nil);
}];

[deferred wait];
if (outError && error)
*outError = [error autorelease];
return [matches autorelease];
}

@end
10 changes: 4 additions & 6 deletions app/ViSyntaxCompletion.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

@implementation ViSyntaxCompletion

- (id<ViDeferred>)completionsForString:(NSString *)word
options:(NSString *)options
onResponse:(void (^)(NSArray *, NSError *))responseCallback
- (NSArray *)completionsForString:(NSString *)word
options:(NSString *)options
error:(NSError **)outError
{
BOOL fuzzySearch = ([options rangeOfString:@"f"].location != NSNotFound);
BOOL fuzzyTrigger = ([options rangeOfString:@"F"].location != NSNotFound);
Expand Down Expand Up @@ -42,9 +42,7 @@ @implementation ViSyntaxCompletion
}
}

responseCallback(syntaxes, nil);

return nil;
return syntaxes;
}

@end
18 changes: 9 additions & 9 deletions app/ViWordCompletion.m
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#import "ViWordCompletion.h"
#import "ViWindowController.h"
#import "ViError.h"
#include "logging.h"

@implementation ViWordCompletion

- (id<ViDeferred>)completionsForString:(NSString *)word
options:(NSString *)options
onResponse:(void (^)(NSArray *, NSError *))responseCallback
- (NSArray *)completionsForString:(NSString *)word
options:(NSString *)options
error:(NSError **)outError
{
ViTextView *text = (ViTextView *)[[[ViWindowController currentWindowController] currentView] innerView];
if (![text isKindOfClass:[ViTextView class]]) {
responseCallback(nil, nil);
ViTextView *text = [[[ViWindowController currentWindowController] currentDocumentView] textView];
if (text == nil) {
if (outError)
*outError = [ViError message:@"Word completion only defined for text views"];
return nil;
}

Expand Down Expand Up @@ -82,10 +84,8 @@ @implementation ViWordCompletion
}
return (NSComparisonResult)NSOrderedSame;
};
NSArray *completions = [[uniq allObjects] sortedArrayUsingComparator:sortByLocation];

responseCallback(completions, nil);
return nil;
return [[uniq allObjects] sortedArrayUsingComparator:sortByLocation];
}

@end
Expand Down

0 comments on commit 8be3de6

Please sign in to comment.