Permalink
Browse files

track changes to completion provider API

  • Loading branch information...
1 parent e0b2ff3 commit 8be3de647a35d82a5189bf3477a90ee968fc0d30 @martinh martinh committed Oct 1, 2011
View
3 Support/lib/nu/complete.nu
@@ -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")
View
10 app/ExCommandCompletion.m
@@ -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);
@@ -38,9 +38,7 @@ @implementation ExCommandCompletion
}
}
- responseCallback(commands, nil);
-
- return nil;
+ return commands;
}
@end
View
10 app/ViBufferCompletion.m
@@ -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);
@@ -42,9 +42,7 @@ @implementation ViBufferCompletion
}
}
- responseCallback(buffers, nil);
-
- return nil;
+ return buffers;
}
@end
View
28 app/ViFileCompletion.m
@@ -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);
@@ -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) {
@@ -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]));
@@ -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
View
10 app/ViSyntaxCompletion.m
@@ -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);
@@ -42,9 +42,7 @@ @implementation ViSyntaxCompletion
}
}
- responseCallback(syntaxes, nil);
-
- return nil;
+ return syntaxes;
}
@end
View
18 app/ViWordCompletion.m
@@ -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;
}
@@ -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

0 comments on commit 8be3de6

Please sign in to comment.