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

Add support for Objective-C #193

Closed
keith opened this Issue Feb 14, 2014 · 5 comments

Comments

Projects
None yet
2 participants
@keith

keith commented Feb 14, 2014

This seems to be the conventional wisdom on how to get TagBar working with ObjC.

http://bastibe.de/2011-12-04-how-to-make-tagbar-work-with-objective-c.html

Mainly you have to install the trunk version of Ctags and then add this to your vimrc:

" add a definition for Objective-C to tagbar
let g:tagbar_type_objc = {
    \ 'ctagstype' : 'ObjectiveC',
    \ 'kinds'     : [
        \ 'i:interface',
        \ 'I:implementation',
        \ 'p:Protocol',
        \ 'm:Object_method',
        \ 'c:Class_method',
        \ 'v:Global_variable',
        \ 'F:Object field',
        \ 'f:function',
        \ 'p:property',
        \ 't:type_alias',
        \ 's:type_structure',
        \ 'e:enumeration',
        \ 'M:preprocessor_macro',
    \ ],
    \ 'sro'        : ' ',
    \ 'kind2scope' : {
        \ 'i' : 'interface',
        \ 'I' : 'implementation',
        \ 'p' : 'Protocol',
        \ 's' : 'type_structure',
        \ 'e' : 'enumeration'
    \ },
    \ 'scope2kind' : {
        \ 'interface'      : 'i',
        \ 'implementation' : 'I',
        \ 'Protocol'       : 'p',
        \ 'type_structure' : 's',
        \ 'enumeration'    : 'e'
    \ }
\ }

Unfortunately this has the side effect of producing a ton of incorrectly interpreted duplicates.
screen shot 2014-02-14 at 12 35 35 pm

I was hoping someone who understood what was going on a little more could point me in the right direction for how to get this functioning as expected.

Thanks!

@keith

This comment has been minimized.

Show comment
Hide comment
@keith

keith Feb 14, 2014

Here's the output from running:

ctags -f - --format=2 --excmd=pattern --extra= --fields=nksaSmt KBSPinboardUser.m

As told in the docs.

KBSPinboardUser KBSPinboardUser.m   /^@interface KBSPinboardUser ()$/;" i   line:13 interface:
block   KBSPinboardUser.m   /^                block(NO, [NSError errorWithDomain:KBSPinboardAPIErrorDomain code:KBSPinboardInvalidCredentials userInfo:nil]);$/;"   p   line:77 interface:KBSPinboardUser
block   KBSPinboardUser.m   /^                block(NO, error);$/;" p   line:75 interface:KBSPinboardUser
block   KBSPinboardUser.m   /^            block(NO, error);$/;" p   line:85 interface:KBSPinboardUser
block   KBSPinboardUser.m   /^            block(valid, error);$/;"  p   line:57 interface:KBSPinboardUser
block   KBSPinboardUser.m   /^            block(valid, error);$/;"  p   line:61 interface:KBSPinboardUser
block   KBSPinboardUser.m   /^        block(YES, nil);$/;"  p   line:91 interface:KBSPinboardUser
built   KBSPinboardUser.m   /^    self.token = built;$/;"   p   line:97 interface:KBSPinboardUser
componentsSeparatedByString KBSPinboardUser.m   /^    NSArray *components = [_token componentsSeparatedByString:@":"];$/;"  p   line:48 interface:KBSPinboardUser
copy    KBSPinboardUser.m   /^    _password = [password copy];$/;"  p   line:36 interface:KBSPinboardUser
copy    KBSPinboardUser.m   /^    _token = [token copy];$/;"    p   line:47 interface:KBSPinboardUser
copy    KBSPinboardUser.m   /^    _username = [username copy];$/;"  p   line:35 interface:KBSPinboardUser
error   KBSPinboardUser.m   /^        id JSONObject = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];$/;"   p   line:83 interface:KBSPinboardUser
firstObject KBSPinboardUser.m   /^    _username = [components firstObject];$/;" p   line:49 interface:KBSPinboardUser
format  KBSPinboardUser.m   /^    return [NSURL URLWithString:format];$/;"  p   line:102    interface:KBSPinboardUser
format  KBSPinboardUser.m   /^    return [NSURL URLWithString:format];$/;"  p   line:107    interface:KBSPinboardUser
init    KBSPinboardUser.m   /^    self = [super init];$/;"  p   line:30 interface:KBSPinboardUser
init    KBSPinboardUser.m   /^    self = [super init];$/;"  p   line:42 interface:KBSPinboardUser
key KBSPinboardUser.m   /^        [self buildAndSetToken:key];$/;"  p   line:90 interface:KBSPinboardUser
key KBSPinboardUser.m   /^    NSString *built = [NSString stringWithFormat:@"%@:%@", self.username, key];$/;"   p   line:96 interface:KBSPinboardUser
nil KBSPinboardUser.m   /^        return nil;$/;"   p   line:32 interface:KBSPinboardUser
nil KBSPinboardUser.m   /^        return nil;$/;"   p   line:44 interface:KBSPinboardUser
objectForKey    KBSPinboardUser.m   /^        NSString *key = [JSONObject objectForKey:@"result"];$/;"  p   line:89 interface:KBSPinboardUser
password    KBSPinboardUser.m   /^    NSString *format = [NSString stringWithFormat:kPinboardHTTPAuthFormat, self.username, self.password];$/;" p   line:101    interface:KBSPinboardUser
password    KBSPinboardUser.m   /^    return [[KBSPinboardUser alloc] initWithUsername:username password:password];$/;" p   line:22 interface:KBSPinboardUser
response    KBSPinboardUser.m   /^        NSHTTPURLResponse *r = (NSHTTPURLResponse *)response;$/;" p   line:72 interface:KBSPinboardUser
resume  KBSPinboardUser.m   /^    }] resume];$/;"   p   line:92 interface:KBSPinboardUser
return  KBSPinboardUser.m   /^            return;$/;"   p   line:80 interface:KBSPinboardUser
return  KBSPinboardUser.m   /^            return;$/;"   p   line:86 interface:KBSPinboardUser
self    KBSPinboardUser.m   /^    return self;$/;"  p   line:38 interface:KBSPinboardUser
self    KBSPinboardUser.m   /^    return self;$/;"  p   line:51 interface:KBSPinboardUser
session KBSPinboardUser.m   /^    return _session;$/;"  p   line:117    interface:KBSPinboardUser
session KBSPinboardUser.m   /^@property (nonatomic, strong) NSURLSession *session;$/;"  p   line:15 interface:KBSPinboardUser
sharedSession   KBSPinboardUser.m   /^        _session = [NSURLSession sharedSession];$/;"  p   line:114    interface:KBSPinboardUser
token   KBSPinboardUser.m   /^    NSString *format = [NSString stringWithFormat:kPinboardTokenAuthFormat, self.token];$/;"  p   line:106    interface:KBSPinboardUser
token   KBSPinboardUser.m   /^    return [[KBSPinboardUser alloc] initWithToken:token];$/;" p   line:26 interface:KBSPinboardUser

keith commented Feb 14, 2014

Here's the output from running:

ctags -f - --format=2 --excmd=pattern --extra= --fields=nksaSmt KBSPinboardUser.m

As told in the docs.

KBSPinboardUser KBSPinboardUser.m   /^@interface KBSPinboardUser ()$/;" i   line:13 interface:
block   KBSPinboardUser.m   /^                block(NO, [NSError errorWithDomain:KBSPinboardAPIErrorDomain code:KBSPinboardInvalidCredentials userInfo:nil]);$/;"   p   line:77 interface:KBSPinboardUser
block   KBSPinboardUser.m   /^                block(NO, error);$/;" p   line:75 interface:KBSPinboardUser
block   KBSPinboardUser.m   /^            block(NO, error);$/;" p   line:85 interface:KBSPinboardUser
block   KBSPinboardUser.m   /^            block(valid, error);$/;"  p   line:57 interface:KBSPinboardUser
block   KBSPinboardUser.m   /^            block(valid, error);$/;"  p   line:61 interface:KBSPinboardUser
block   KBSPinboardUser.m   /^        block(YES, nil);$/;"  p   line:91 interface:KBSPinboardUser
built   KBSPinboardUser.m   /^    self.token = built;$/;"   p   line:97 interface:KBSPinboardUser
componentsSeparatedByString KBSPinboardUser.m   /^    NSArray *components = [_token componentsSeparatedByString:@":"];$/;"  p   line:48 interface:KBSPinboardUser
copy    KBSPinboardUser.m   /^    _password = [password copy];$/;"  p   line:36 interface:KBSPinboardUser
copy    KBSPinboardUser.m   /^    _token = [token copy];$/;"    p   line:47 interface:KBSPinboardUser
copy    KBSPinboardUser.m   /^    _username = [username copy];$/;"  p   line:35 interface:KBSPinboardUser
error   KBSPinboardUser.m   /^        id JSONObject = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];$/;"   p   line:83 interface:KBSPinboardUser
firstObject KBSPinboardUser.m   /^    _username = [components firstObject];$/;" p   line:49 interface:KBSPinboardUser
format  KBSPinboardUser.m   /^    return [NSURL URLWithString:format];$/;"  p   line:102    interface:KBSPinboardUser
format  KBSPinboardUser.m   /^    return [NSURL URLWithString:format];$/;"  p   line:107    interface:KBSPinboardUser
init    KBSPinboardUser.m   /^    self = [super init];$/;"  p   line:30 interface:KBSPinboardUser
init    KBSPinboardUser.m   /^    self = [super init];$/;"  p   line:42 interface:KBSPinboardUser
key KBSPinboardUser.m   /^        [self buildAndSetToken:key];$/;"  p   line:90 interface:KBSPinboardUser
key KBSPinboardUser.m   /^    NSString *built = [NSString stringWithFormat:@"%@:%@", self.username, key];$/;"   p   line:96 interface:KBSPinboardUser
nil KBSPinboardUser.m   /^        return nil;$/;"   p   line:32 interface:KBSPinboardUser
nil KBSPinboardUser.m   /^        return nil;$/;"   p   line:44 interface:KBSPinboardUser
objectForKey    KBSPinboardUser.m   /^        NSString *key = [JSONObject objectForKey:@"result"];$/;"  p   line:89 interface:KBSPinboardUser
password    KBSPinboardUser.m   /^    NSString *format = [NSString stringWithFormat:kPinboardHTTPAuthFormat, self.username, self.password];$/;" p   line:101    interface:KBSPinboardUser
password    KBSPinboardUser.m   /^    return [[KBSPinboardUser alloc] initWithUsername:username password:password];$/;" p   line:22 interface:KBSPinboardUser
response    KBSPinboardUser.m   /^        NSHTTPURLResponse *r = (NSHTTPURLResponse *)response;$/;" p   line:72 interface:KBSPinboardUser
resume  KBSPinboardUser.m   /^    }] resume];$/;"   p   line:92 interface:KBSPinboardUser
return  KBSPinboardUser.m   /^            return;$/;"   p   line:80 interface:KBSPinboardUser
return  KBSPinboardUser.m   /^            return;$/;"   p   line:86 interface:KBSPinboardUser
self    KBSPinboardUser.m   /^    return self;$/;"  p   line:38 interface:KBSPinboardUser
self    KBSPinboardUser.m   /^    return self;$/;"  p   line:51 interface:KBSPinboardUser
session KBSPinboardUser.m   /^    return _session;$/;"  p   line:117    interface:KBSPinboardUser
session KBSPinboardUser.m   /^@property (nonatomic, strong) NSURLSession *session;$/;"  p   line:15 interface:KBSPinboardUser
sharedSession   KBSPinboardUser.m   /^        _session = [NSURLSession sharedSession];$/;"  p   line:114    interface:KBSPinboardUser
token   KBSPinboardUser.m   /^    NSString *format = [NSString stringWithFormat:kPinboardTokenAuthFormat, self.token];$/;"  p   line:106    interface:KBSPinboardUser
token   KBSPinboardUser.m   /^    return [[KBSPinboardUser alloc] initWithToken:token];$/;" p   line:26 interface:KBSPinboardUser
@keith

This comment has been minimized.

Show comment
Hide comment
@keith

keith Feb 14, 2014

This other method works by defining the rules of Objective-C using regex. https://gist.github.com/yamaya/5598909

keith commented Feb 14, 2014

This other method works by defining the rules of Objective-C using regex. https://gist.github.com/yamaya/5598909

@keith

This comment has been minimized.

Show comment
Hide comment
@keith

keith Feb 14, 2014

With added properties. https://gist.github.com/Keithbsmiley/9006450

I'm going to assume the issue is Ctags' implementation of ObjC tags or just incompatibility with the flags passed to the command. But otherwise let me know!

keith commented Feb 14, 2014

With added properties. https://gist.github.com/Keithbsmiley/9006450

I'm going to assume the issue is Ctags' implementation of ObjC tags or just incompatibility with the flags passed to the command. But otherwise let me know!

@keith keith closed this Feb 14, 2014

@majutsushi

This comment has been minimized.

Show comment
Hide comment
@majutsushi

majutsushi Feb 15, 2014

Owner

Well, as you can see in the ctags output the duplicate tags are actually reported by ctags itself, so Tagbar can't really do anything about that. The parser in ctags seems to have some bugs, as the reported tags clearly don't seem right. I would recommend filing an issue on the ctags website.

Owner

majutsushi commented Feb 15, 2014

Well, as you can see in the ctags output the duplicate tags are actually reported by ctags itself, so Tagbar can't really do anything about that. The parser in ctags seems to have some bugs, as the reported tags clearly don't seem right. I would recommend filing an issue on the ctags website.

@keith

This comment has been minimized.

Show comment
Hide comment
@keith

keith Feb 15, 2014

Yep, totally reasonable. Based off their release schedule I don't think I'll spend the time on their issue tracker. Thanks though.

keith commented Feb 15, 2014

Yep, totally reasonable. Based off their release schedule I don't think I'll spend the time on their issue tracker. Thanks though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment