当python类定义跨越多行时,旺盛的ctags会生成错误的标签,只有最后一行进入搜索模式:

考虑文件test.py

class FirstSubclass(
    LongLineBaseClass, AnotherLongClassName,
    MoreBaseClassWithVeryLongName
):
    pass


class SecondSubclass(
    LongLineBaseClass, AnotherLongClassName,
    MoreBaseClassWithVeryLongName
):
    pass


class OneLineClass(LongLineBaseClass):
    pass


以及tags的结果ctags test.py文件(添加了注释):

FirstSubclass   test.py /^):$/;"    c !PROBLEM
OneLineClass    test.py /^class OneLineClass(LongLineBaseClass):$/;"    c !OK
SecondSubclass  test.py /^):$/;"    c !PROBLEM


FirstSubclassSecondSubclass都收到相同的搜索模式(例如命令):/^):$,即每个类定义的最后一行中只有两个字符。这使得在vim中导航的标签不可用。

丰富的ctags版本和信息:

Exuberant Ctags 5.9~svn20110310, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Oct  7 2014, 13:52:37
  Addresses: <[email protected]>, http://ctags.sourceforge.net
  Optional compiled features: +wildcards, +regex



我尝试过的方法:我使用了带有和不带有language-python kinds,参数且没有内容的ctags。



有任何想法吗 ?
提前致谢。

最佳答案

通用标签(https://ctags.io)是Exuebrante-ctags的非官方分支,可以按预期提取模式:

[yamato@slave]~% cat /tmp/foo.py
cat /tmp/foo.py
class FirstSubclass(
    LongLineBaseClass, AnotherLongClassName,
    MoreBaseClassWithVeryLongName
):
    pass


class SecondSubclass(
    LongLineBaseClass, AnotherLongClassName,
    MoreBaseClassWithVeryLongName
):
    pass


class OneLineClass(LongLineBaseClass):
    pass

[yamato@slave]~% u-ctags -o - /tmp/foo.py
u-ctags -o - /tmp/foo.py
FirstSubclass   /tmp/foo.py /^class FirstSubclass($/;"  c
OneLineClass    /tmp/foo.py /^class OneLineClass(LongLineBaseClass):$/;"    c
SecondSubclass  /tmp/foo.py /^class SecondSubclass($/;" c


此外,它可以填充继承字段:

[yamato@slave]~% u-ctags --fields=+i -o - /tmp/foo.py
u-ctags --fields=+i -o - /tmp/foo.py
FirstSubclass   /tmp/foo.py /^class FirstSubclass($/;"  c   inherits:LongLineBaseClass, AnotherLongClassName, MoreBaseClassWithVeryLongName
OneLineClass    /tmp/foo.py /^class OneLineClass(LongLineBaseClass):$/;"    c   inherits:LongLineBaseClass
SecondSubclass  /tmp/foo.py /^class SecondSubclass($/;" c   inherits:LongLineBaseClass, AnotherLongClassName, MoreBaseClassWithVeryLongName

关于python - 旺盛的ctags错误地标记了python多行类定义,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57331659/

10-12 22:42