universal-ctags / ctags

A maintained ctags implementation
https://ctags.io
GNU General Public License v2.0
6.59k stars 629 forks source link

Lisp: ignore methods #4119

Closed aartaka closed 2 weeks ago

aartaka commented 2 weeks ago

The name of the parser: lisp

The command line you used to run ctags:

$ ctags --options=NONE source/*.lisp source/mode/*.lisp libraries/*/*.lisp

In the root dir of Nyxt browser

The tags output you are not satisfied with:

list-passwords  libraries/password-manager/password-keepassxc.lisp  /^(defmethod list-passwords ((password-interface keepassxc-interface))$/;"  Y
list-passwords  libraries/password-manager/password-pass.lisp   /^(defmethod list-passwords ((password-interface password-store-interface))$/;" Y
list-passwords  libraries/password-manager/password-security.lisp   /^(defmethod list-passwords ((password-interface security-interface))$/;"   Y

The tags output you expect:

Yes, empty output. Because tags should be unique and point to one location, while methods are (by definition) multiple locations. So these should probably be ignored by the parser.

The version of ctags:

$ ctags --version
Universal Ctags 6.1.0(p6.1.20241117.0), Copyright (C) 2015-2023 Universal Ctags Team
Universal Ctags is derived from Exuberant Ctags.
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Nov 18 2024, 17:31:59
  URL: https://ctags.io/
  Output version: 0.0
  Optional compiled features: +wildcards, +regex, +iconv, +option-directory, +xpath, +json, +interactive, +sandbox, +yaml, +packcc, +optscript, +pcre2

How do you get ctags binary: via Arch pacman

masatake commented 2 weeks ago

Because tags should be unique and point to one location, while methods are (by definition) multiple locations. So, these should probably be ignored by the parser.

If you find such a description of tags in our documents, we must fix it. Please let me know if you find it.

ctags is not designed as you think. ctags should enumerate all definitions. ctags assumes dropping unwanted tags should be done on the side of client tools.

BTW Ideal ctags may add signature: field like:

list-passwords  libraries/password-manager/password-keepassxc.lisp  /^(defmethod list-passwords ((password-interface keepassxc-interface))$/;"  Y   signature:((password-interface keepassxc-interface))
list-passwords  libraries/password-manager/password-pass.lisp   /^(defmethod list-passwords ((password-interface password-store-interface))$/;" Y   signature:((password-interface password-store-interface))
list-passwords  libraries/password-manager/password-security.lisp   /^(defmethod list-passwords ((password-interface security-interface))$/;"   Y   signature:((password-interface security-interface))

Here is an example how to drop defmethod in a client tool:

$ cat /tmp/bar.lisp
(defgeneric X)
(defmethod X ((a)))
(defmethod X ((b)))

$ /bin/ctags -o - /tmp/bar.lisp
X   /tmp/bar.lisp   /^(defgeneric X)$/;"    Y
X   /tmp/bar.lisp   /^(defmethod X ((a)))$/;"   Y
X   /tmp/bar.lisp   /^(defmethod X ((b)))$/;"   Y

$ /bin/ctags -o - /tmp/bar.lisp | readtags -et - -Q '(not (#/.*defmethod.*/ $pattern))' -l
X   /tmp/bar.lisp   /^(defgeneric X)$/;"    kind:Y

If you think using a regular expression is awkward, I have a plan to add "deftype" lisp specific field to ctags. (I have a prototype implementation).

$ ~/bin//ctags --version=Lisp
parser/Lisp: 0.1
$ ~/bin/ctags -o - /tmp/bar.lisp
X   /tmp/bar.lisp   /^(defgeneric X)$/;"    Y   deftype:GENERIC
X   /tmp/bar.lisp   /^(defmethod X ((a)))$/;"   Y   deftype:METHOD
X   /tmp/bar.lisp   /^(defmethod X ((b)))$/;"   Y   deftype:METHOD
$ ~/bin//ctags -o - /tmp/bar.lisp | readtags -et - -Q '(not (eq? "METHOD" ($ "deftype")))' -l
X   /tmp/bar.lisp   /^(defgeneric X)$/;"    kind:Y  deftype:GENERIC
aartaka commented 2 weeks ago

If you find such a description of tags in our documents, we must fix it. Please let me know if you find it.

No, it's okay. I was mostly using ex/vi docs for a reference, so they might've confused me, sorry.