xcode 使用 Objective-c 替代 Ctags/Cscope?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2968522/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:25:08  来源:igfitidea点击:

Alternatives to Ctags/Cscope with Objective-c?

objective-cxcodevimctagscscope

提问by esiegel

Are there any alternatives to ctags and cscope with Objective-c support. This does pertain to cocoa development, so inevitably it seems I will be using Xcode (and probably should). I was just wondering what are my Vim options.

是否有任何具有 Objective-c 支持的 ctags 和 cscope 的替代品。这确实与可可开发有关,因此我似乎不可避免地将使用 Xcode(并且可能应该使用)。我只是想知道我的 Vim 选项是什么。

Maybe there is some type of plugin system like eclim, but for xcode?

也许有某种类型的插件系统,比如 eclim,但对于 xcode?

EDIT

编辑

So it seems that other than updating ctags to support objective-c, I'm out of luck. Does anyone know if cscope is the same?

因此,除了更新 ctags 以支持 Objective-c 之外,我似乎运气不佳。有谁知道 cscope 是否相同?

回答by Vincent Guerci

a long time after this question, "playing" with vim, I wanted ObjC support, especially with taglist plugin. I found that question, then digged a bit, and here is a not so dirtysolution:

在这个问题之后很长一段时间,“”vim,我想要 ObjC 支持,尤其是 taglist 插件。我发现了这个问题,然后挖掘了一下,这是一个不太脏的解决方案:

  1. An ObjectiveC parser has been added to Exuberant CTags trunk, it is not released (yet?)
  2. You can easily install it on OSX via homebrew:

    $ brew install ctags --HEAD

  3. Note that when using ctags, .mis treated as Matlab and .his treated as C++. To override, use:

    $ ctags --langmap=ObjectiveC:.m.h

  4. Then I added something like this to my .vimrcfor taglist support:

    let tlist_objc_settings = 'ObjectiveC;P:protocols;i:interfaces;types(...)'

    add any type interests you from that list:

    ctags --list-kinds=all
    ObjectiveC
        i  class interface
        I  class implementation
        p  Protocol
        m  Object's method
        c  Class' method
        v  Global variable
        F  Object field
        f  A function
        p  A property
        t  A type alias
        s  A type structure
        e  An enumeration
        M  A preprocessor macro
    
  1. 一个 ObjectiveC 解析器已添加到 Exuberant CTags 主干,它还没有发布(还没有?)
  2. 您可以通过自制软件轻松地在 OSX 上安装它:

    $ brew install ctags --HEAD

  3. 注意,当使用 ctags 时,.m被视为 Matlab,.h被视为 C++。要覆盖,请使用:

    $ ctags --langmap=ObjectiveC:.m.h

  4. 然后我在我.vimrc的标签列表支持中添加了这样的东西:

    let tlist_objc_settings = 'ObjectiveC;P:protocols;i:interfaces;types(...)'

    从该列表中添加您感兴趣的任何类型:

    ctags --list-kinds=all
    ObjectiveC
        i  class interface
        I  class implementation
        p  Protocol
        m  Object's method
        c  Class' method
        v  Global variable
        F  Object field
        f  A function
        p  A property
        t  A type alias
        s  A type structure
        e  An enumeration
        M  A preprocessor macro
    

I hope that will help someone!

我希望这会帮助某人!

回答by Vincent

AFAIK, ctags support you to define some rules for a new language, I did that when I did some development using laszlo(similiar to flex). You can read the manpage of ctags to get more details, that is not hard to do.

AFAIK,ctags 支持您为新语言定义一些规则,当我使用 laszlo(类似于 flex)进行一些开发时,我这样做了。您可以阅读 ctags 的联机帮助页以获取更多详细信息,这并不难。

I find there is a vim filetype plugin that support development under cocoa here, hope it is helpful for you.

我觉得有一个VIM文件类型插件在可可的支持发展在这里,希望对你们有用。

回答by Harry Hacker

There is an option to use ctags for objective-c. You can use etags in ctags mode. etags derived from ctags some time ago, and in its source code ctags compatible tags will be generated by defining a certain macro switch.

可以选择将 ctags 用于 Objective-c。您可以在 ctags 模式下使用 etags。前段时间从ctags派生出来的etags,在其源代码中会通过定义某个宏开关来生成ctags兼容的标签。

In fact the man page in Mac Os already documents etags and ctags in the same page. It states that objective-c is supported in ctags. You should be able to generate a tag file using the following command: ctags -l objc *.[mh]

事实上,Mac Os 中的手册页已经在同一页面中记录了 etags 和 ctags。它指出ctags 支持objective-c。您应该能够使用以下命令生成标签文件:ctags -l objc *.[mh]

Unfortunately the ctags program in Mac OS behaves not as documented since Apple messed it up. I however managed to install this kind of ctags using Ubuntu Linux and it works great!!! There you have to install the emacs22-bin-common package.

不幸的是,Mac OS 中的 ctags 程序表现得不像文档那样,因为 Apple 把它搞砸了。然而,我设法使用 Ubuntu Linux 安装了这种 ctags 并且效果很好!!!在那里你必须安装 emacs22-bin-common 包。

So under Mac OS all you have to do is to compile this package for yourself.

所以在 Mac OS 下,你所要做的就是自己编译这个包。

  • Download the corresponding source package e.g. from the Debian server (link).
  • exctract it and change to the source directory
  • run ./configure
  • configure returns with an error because it cannot find lispref
  • I deleted all targets in varible config_files in the created file config.status despite the ones with lib-src
  • run ./config.status
  • cd lib-src
  • make
  • Copy ctags e.g. to /usr/local/bin and change permissions
    • sudo cp ctags /usr/local/bin
    • chmod a+rx /usr/local/bin/ctags
  • 例如从 Debian 服务器(链接)下载相应的源包。
  • 解压并切换到源目录
  • 运行 ./configure
  • configure 返回错误,因为它找不到 lispref
  • 我在创建的文件 config.status 中删除了变量 config_files 中的所有目标,尽管有 lib-src
  • 运行 ./config.status
  • cd lib-src
  • 制作
  • 复制 ctags 例如到 /usr/local/bin 并更改权限
    • 须藤cp ctags /usr/local/bin
    • chmod a+rx /usr/local/bin/ctags

You are done. Happy tagging!!!

你完成了。标记快乐!!!

回答by Aaron Elkins

You can also try objcscope which is written by me.

你也可以试试我写的objcscope。

objcsope

物镜

回答by Masatake YAMATO

Universal-ctags(https://ctags.io) can capture properties of Objective-C.

Universal-ctags( https://ctags.io) 可以捕获 Objective-C 的属性。

[jet@localhost objectivec_property.h.d]$ cat input.h 

@interface Person : NSObject {
    @public
        NSString *m_name;
    @private
        int m_age;
}

@property(copy) NSString *personName;
@property(readonly) int personAge;

-(id)initWithAge:(int)age;
@end
[jet@localhost objectivec_property.h.d]$ ../../../ctags -x -o - input.h 
Person           interface     2 input.h          @interface Person : NSObject {
initWithAge:     method       12 input.h          -(id)initWithAge:(int)age;
m_age            field         6 input.h          int m_age;
m_name           field         4 input.h          NSString *m_name;
personAge        property     10 input.h          @property(readonly) int personAge;
personName       property      9 input.h          @property(copy) NSString *personName;

回答by Andrew-Dufresne

You can try Fishman fork of Exuberant Ctagswhich has Objective C and CSS support.

您可以尝试使用支持 Objective C 和 CSS的 Exuberant Ctags 的 Fishman 分支

回答by snowbound

I found it difficult getting ctags to generate tags for tagbar. It was easier to use a vim plugin for the Objective-C editor. XVimworks with XCode. If you use Appcode like me, IdeaVimis well integrated.

我发现很难让 ctags 为标签栏生成标签。为 Objective-C 编辑器使用 vim 插件更容易。 XVim与 XCode一起工作。如果你像我一样使用 Appcode,IdeaVim集成很好。

Though you won't get to full Vi/Vim functionality with the plugin. I find mix usage with native IDE commands is enough to compensate.

虽然您不会使用该插件获得完整的 Vi/Vim 功能。我发现混合使用本机 IDE 命令足以弥补。

回答by HonanLi

If I am not wrong :

如果我没有错:

Latest ctagsby now parsing the @propertykeyword incorrectly, which could cause that all the words after @propertyin the source code are parsed to be properties, leading to a mess in file tags.

ctags现在最新的@property关键字解析错误,可能导致@property源代码后面的所有单词都被解析为属性,导致文件tags.

I have to recompile ctags (https://sourceforge.net/p/ctags/code/HEAD/tree/) by commenting all of the property keyword processing in ObjC.cas a workaround. Even though, it only helps to get a little better for reading source code in the Taglist.

我必须通过注释所有属性关键字处理来重新编译 ctags ( https://sourceforge.net/p/ctags/code/HEAD/tree/)ObjC.c作为一种解决方法。尽管如此,它只会有助于更好地阅读 Taglist 中的源代码。

It still can't jump (e.g. to the implementation methods with parameters) correctly.

它仍然无法正确跳转(例如跳转到带参数的实现方法)。

I also tried this(https://github.com/mcormier/ctags-ObjC-5.8.1), but unfortunately this can't jump at all.

我也试过这个(https://github.com/mcormier/ctags-ObjC-5.8.1),但不幸的是这根本无法跳转。

Summary :there seems no ctags for ObjC as workable as for C/C++.

总结:似乎没有像 C/C++ 那样适用于 ObjC 的 ctags。

回答by Seth Kingsley

Apropos the other answer: you can install EMACS with MacPorts fairly easily and it will include a version of etags at /opt/local/bin that has Objective-C support compiled in.

另一个答案是:您可以很容易地使用 MacPorts 安装 EMACS,它将在 /opt/local/bin 包含一个编译了 Objective-C 支持的 etags 版本。

% sudo port install emacs
% find . -name ‘*.[hm]' -print0 | xargs ?0 /opt/local/bin/etags

And then inside vim:

然后在 vim 中:

:setlocal tags=TAGS

This works well for me with MacVim.

这对我使用 MacVim 很有效。