使用 cscope 通过 VIM 浏览 Python 代码?

发布于 2024-09-19 09:38:18 字数 265 浏览 10 评论 0原文

有没有人成功地使用 cscope 和 Python 代码进行管理?我安装了 VIM 7.2 和最新版本的 cscope,但是它无法正确获取我的代码标签(总是偏离几行)。我尝试了 pycscope 脚本,但现代版本的 cscope 不支持其输出。

有什么想法吗?或者使用 VIM 浏览 Python 代码的替代方案? (我对 cscope 除了 ctags 的简单标签之外提供的额外功能特别感兴趣)

Has anyone managed successfully using cscope with Python code? I have VIM 7.2 and the latest version of cscope installed, however it doesn't get my code's tags correctly (always off by a couple of lines). I tried the pycscope script but its output isn't supported by the modern version of cscope.

Any ideas? Or an alternative for browsing Python code with VIM? (I'm specifically interested in the extra features cscope offers beyond the simple tags of ctags)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

夏日落 2024-09-26 09:38:19

我有同样的问题,浏览互联网后,我找到了解决此问题的方法:

创建一个 python 脚本: cscope_scan.py

import os

codeRootDir = os.getcwd()

__revision__ = '0.1'
__author__ = 'lxd'

FILE_TYPE_LIST= ['py']

if __name__ == '__main__':
    import os
    f = open('cscope.files','w')
    for root,dirs,files in os.walk(codeRootDir):
        for file in files:
            for file_type in FILE_TYPE_LIST:
                if file.split('.')[-1] == file_type:
                    f.write('%s\n' %os.path.join(root,file))
    f.close()
    cmd = 'cscope -bk'
    os.system(cmd)

在代码的根文件夹下执行此脚本,这将生成 < code>cscope.files 然后执行 cscope -b 我不知道我的计算机会发生什么,最后两行效果不佳,但我认为手动输入 < code>cscope -bk 是可以接受的:)

I got the same question you got, after browsing the internet, I found a way to fix this:

create a python script: cscope_scan.py

import os

codeRootDir = os.getcwd()

__revision__ = '0.1'
__author__ = 'lxd'

FILE_TYPE_LIST= ['py']

if __name__ == '__main__':
    import os
    f = open('cscope.files','w')
    for root,dirs,files in os.walk(codeRootDir):
        for file in files:
            for file_type in FILE_TYPE_LIST:
                if file.split('.')[-1] == file_type:
                    f.write('%s\n' %os.path.join(root,file))
    f.close()
    cmd = 'cscope -bk'
    os.system(cmd)

excute this script under you code's root folder, this will generate the cscope.files and then excute cscope -b I don't know what happens to my computer, the last two lines aren't working well, but I think manually type a cscope -bk is acceptable:)

烟酒忠诚 2024-09-26 09:38:19

此 hack 似乎还强制 cscope 浏览 Python 文件:

cscope -Rb -s *

如果您接受 cscope显然不适合与 Python 一起使用

超集任何语言任何工具问题:如何查找所有出现的情况Vim 中的变量?

This hack also seems to force cscope to go through Python files:

cscope -Rb -s *

If you accept that cscope is apparently not designed to work with Python.

Superset any language any tool question: How to find all occurrences of a variable in Vim?

合约呢 2024-09-26 09:38:18

编辑:我将逐步完成该过程:

准备源:

exhuberant ctags,有一个选项:-x

   Alternatively,  ctags  can generate a cross reference file which lists,
   in human readable form, information about the  various  source  objects
   found in a set of language files.

这是问题的关键:

 ctags -x $(ls **/*.py);                  # replace with find if no zsh

将以已知的格式为您提供源对象的数据库, Gnu Global中描述的

 man ctags;                               # make sure you use exuberant ctags!

不仅限于“开箱即用”类型的文件。任何常规文件格式都可以。

此外,您还可以使用 gtags-cscope(如手册第 3.7 节中所述,它带有全局)作为使用 gtags 的可能快捷方式。您最终将得到一个 ctags 表格文件的输入,Global/gtags 可以解析该文件以获取您的对象,或者您可以将 pycscope 的源代码与已知格式的 ctags 文件一起使用,以获取 vim cscope 命令的输入

if_cscope.txt。

不管怎样,这都是可行的。

也许您更喜欢 idutils?

绝对有可能,因为

pypi 上的z3c.recipe.tags

使用 ctags 和 idutils 来为构建创建标记文件,这是我将很快研究的一种方法。

当然,您始终可以使用下面的 greputils 脚本,它支持 idutils ,我们知道 idutils 可以与 python 一起使用,如果失败,今年还有一个名为 vimentry 的东西也使用 python、idutils 和 vim。

参考链接(不完整列表):

  • gtags vimscript,使用 Gnu 全局。更新 2008
  • greputils vimscript,包含对 *id idutils 的支持,2005
  • < a href="http://www.vim.org/scripts/script.php?script_id=251" rel="noreferrer">lid vimscript,古老,但这家伙相当不错,他的标签和缓冲区howtos 非常棒,2002 年
  • 更新版本pyscope,2010

希望这可以帮助您解决您的问题,我当然也帮助了我。今晚如果有蛆虫望远镜的话我会感到非常难过。

EDIT: I'm going to run through the process step by step:

Preparing the sources:

exhuberant ctags, has an option: -x

   Alternatively,  ctags  can generate a cross reference file which lists,
   in human readable form, information about the  various  source  objects
   found in a set of language files.

This is the key to the problem:

 ctags -x $(ls **/*.py);                  # replace with find if no zsh

will give you your database of source objects in a known, format, described under

 man ctags;                               # make sure you use exuberant ctags!

Gnu Global is not limited to only the "out of the box" type of files. Any regular file format will serve.

Also, you can use gtags-cscope, which comes with global as mentioned in section 3.7 of the manual, for a possible shortcut using gtags. You'll end up with an input of a ctags tabular file which Global/gtags can parse to get your objects, or you can use the source for pycscope together with your ctags file of known format to get an input for the vim cscope commands in

if_cscope.txt.

Either way it's quite doable.

Perhaps you'd prefer idutils?

Definintely possible since

z3c.recipe.tags

on pypi makes use of both ctags and idutils to create tag files for a buildout, which is a method I shall investigate in short while.

Of course, you could always use the greputils script below, it has support for idutils , we know idutils works with python, and if that fails, there is also something called vimentry from this year that also uses python, idutils and vim.

Reference links (not complete list):

Hopefully this helps you with your problem, I certainly helped me. I would have been quite sad tonight with a maggoty pycscope.

许仙没带伞 2024-09-26 09:38:18

这似乎对我有用:

更改为 python 代码的顶级目录。创建一个名为 cscope.files 的文件:

find . -name '*.py' > cscope.files

cscope -R

如果未正确构建交叉引用,您可能需要首先执行 cscope -b

This seems to work for me:

Change to the top directory of your python code. Create a file called cscope.files:

find . -name '*.py' > cscope.files

cscope -R

You may need to perform a cscope -b first if the cross references don't get built properly.

银河中√捞星星 2024-09-26 09:38:18
  1. 根据与 cscope 维护者的通信,该工具并非设计用于与 Python 配合使用,并且没有计划实现该兼容性。无论现在起作用的是什么,显然都是错误的,并且没有任何承诺它会继续起作用。
  2. 看来我一直在使用过时版本的 pycscopecscope DB 支持最新版本 0.3。 pycscope 的作者告诉我,他通过阅读 cscope 的源代码弄清楚了 cscope DB 的输出格式。该格式没有被故意记录,但它目前可以与 pycsope 0.3 一起使用,这是我将使用的解决方案。

我将接受这个答案,因为不幸的是,即使在宣布赏金后也没有其他答案提供帮助。没有答案得到赞成,所以老实说我不知道​​赏金会去哪里。

  1. From a correspondence with the maintainer of cscope, this tool isn't designed to work with Python, and there are no plans to implement that compatibility. Whatever works now, apparently works by mistake, and there is no promise whatsoever that it will keep working.
  2. It appears I've been using an out-of-date version of pycscope. The latest version 0.3 is supported by the cscope DB. The author of pycscope told me that he figured out the output format for the cscope DB from reading the source code of cscope. That format isn't documented, on purpose, but nevertheless it currently works with pycsope 0.3, which is the solution I'll be using.

I'm going to accept this answer since unfortunately no other answer provided help even after bounty was declared. No answers are upvoted, so I honestly have no idea where the bounty will go.

跨年 2024-09-26 09:38:18

有一个很棒的 Python-mode-klen 插件。如果您安装了它并安装了 rod(python 重构库),那么转到特定术语的定义就像 grag 一样简单> (第一个是文件类型映射,第二个是全局映射)。还有更多有用的功能,有些对我来说没用。所有这些都是可禁用的。 cscope-in​​tro 中的问题列表中的功能:

  1. 这个符号用在什么地方? f。但相当令人困惑,因为快速修复列表中的结果确实显示 - 而不是实际的行(尽管它们指向正确的位置)。也许它会被修复。
  2. 它在哪里定义的?这个全局符号的定义是什么?这个函数在源文件中的什么位置? ;g
  3. 什么是<...>全局符号的定义? raj

不是很多,但我不是有经验的 Ropevim 用户。

There is a wonderful Python-mode-klen plugin. If you have it and rope (python refactoring library) installed, then going to the definition of a particular term is as simple as <C-c>g or <C-c>rag (first is filetype mapping, second is a global one). There are much more useful features, some useless for me. All of them are disableable. Features from list of questions found at cscope-intro:

  1. Where is this symbol used? <C-c>f. Rather confusing though, as results in quickfix list do show - instead of the actual lines (though they point to the correct location). Maybe it will be fixed.
  2. Where is it defined?, What is this global symbol's definition?, Where is this function in the source files? <C-c>g
  3. What is <...> global symbol's definition? <C-c>raj

Not very much, but I am not too experienced user of ropevim.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文