universal-ctags / ctags

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

Disable python namespace kind #683

Closed masatake closed 8 years ago

masatake commented 8 years ago
import X

This line defines nothing. In stead it refers X. This should be captured as a reference tag. Ideally we should implement code for capturing X as reference tag. But as an initial step, disabling the kind is enough for 1.0.0.

ffes commented 8 years ago

Not a real Python developer myself (use it every now and then to write a small script) so my knowledge of the language is limited.

But I noticed that at line 42 there is "namespace" and "import" at the same line. I looking at the commit message for that line, it reads that the code was synchronized with Geany back then.

Knowing there are differences between ctags and Geany. We know that Geany alters the names of the kinds for their internal usage.

Just a short look at the same code in the Geany parser we can see that in Geany it is now called "externvar".

So I think (see my disclaimer in the first line of this comment ;-) that we can safely rename the literal "namespace" to "import".

I don't know if we have a real Python dev on our team (don't see anyone mentioning it in developers.rst) who can answer the question what the best solution for this. Do we need to tag the "imports" anyway? Do we tag #include in C/C++?

masatake commented 8 years ago

@ffes, thank you. I have to look at geany's code.

Here is my private memo about how ctags should handle the import lines:

+/* Role releated to namespace
+
+
+   import X,...          X = (namespace, role:module)
+   from X import Y,...   X = (namespace, role:module), Y = (namespace, role:object)
+                         fullQufalified: X.Y = (namespace, role:object)
+   from X import *       X = (namespace, role:module)
+   from X import Y as Z  X = (namespace, role:module), Y = (namespace, role:object)
+                        Z = (namespace, defintion)
+                        fullQufalified: X.Y = (namespace, role:object)
+                        TODO: provide the way to represent the association between Z and X.Y.
+   import X as Z         X = (namespace, role:module), Z = (namespace, defintion)
+                        TODO: provide the way to represent the association between Z and X. */
masatake commented 8 years ago

Instead of extending kind as doing in geany, I introduce reference and roles.

import X as Z

A user may want to jump to Z because Z is definition. A user mya not want to jump to X because X is not definition. Here X is reference.

(I should show expected.tags for better discussion.)

masatake commented 8 years ago

I don't know if we have a real Python dev on our team (don't see anyone mentioning it in developers.rst) who can answer the question what the best solution for this. Do we need to tag the "imports" anyway? Do we tag #include in C/C++?

Yes, but they should be tagged as reference tag (with role).

These are all tagged as reference tag. Reference tags are recorded in tags only when --extra=+r is given. So ctags can make people using tags for jumping be happy. People using tags for completion, navigation and querying may want the reference tags.

vhda commented 8 years ago

I think I have misunderstood the discussion about reference tags and now my spider sense is tingling all over the place. Need to re-read everything but free time has not been common lately.

masatake commented 8 years ago

I'm sorry that I have not explained reference tags well. Please, look at #680. I showed a simple example.

masatake commented 8 years ago

I found the "externvar" is already defined in C parser.

    { FALSE, 'x', "externvar",  "external and forward variable declarations"},

I would like to treat this as a reference with declaration role. Kinds disabled by default will be candidates of refernce tag. The exceptions I know is local variable and goto label of C.

Converting them is really big change. But releasing the initial version of universal ctags is really good timing for introducing such change.


% u-ctags --_list-kinds-full | grep off
u-ctags --_list-kinds-full | grep off
Ada T   typespec    type specifications off
Ada U   subspec subtype specifications  off
Ada V   varspec variable specifications off
Ada E   entryspec   task/protected data entry specifications    off
Ada a   autovar automatic variables off
Ada y   annon   loops and blocks with no identifier off
BETA    p   pattern all patterns    off
C   h   header  included header files   off
C   l   local   local variables off
C   p   prototype   function prototypes off
C   x   externvar   external and forward variable declarations  off
C   L   label   goto label  off
C++ h   header  included header files   off
C++ l   local   local variables off
C++ p   prototype   function prototypes off
C++ x   externvar   external and forward variable declarations  off
C++ L   label   goto label  off
C#  l   local   local variables off
D   x   externvar   external variable declarations  off
D   l   local   local variables off
D   p   prototype   function prototypes off
DTS h   header  included header files   off
Eiffel  l   local   local entities  off
Fortran L   local   local, common block, and namelist variables off
Fortran P   prototype   subprogram prototypes   off
Java    l   local   local variables off
Make    I   include includes    off
Perl    d   subroutineDeclaration   subroutine declarations off
PHP l   local   local variables off
Sh  s   source  read files  off
SQL d   prototype   prototypes  off
SQL l   local   local variables off
SQL r   record  records off
Vera    l   local   local variables off
Vera    P   prototype   function prototypes off
Vera    x   externvar   external variable declarations  off
Vera    h   header  included header files   off
SystemVerilog   Q   prototype   prototypes  off
VHDL    C   component   component declarations  off
VHDL    d   prototype   prototypes  off
VHDL    l   local   local definitions   off
Zephir  l   local   local variables off
masatake commented 8 years ago

I'm working this issue now. Very exciting.

masatake commented 8 years ago

Revised.

/* Roles releated to `import'

   import X :X = (kind:module,  role:imported)

   import X as Y: X = (kind:module,  role:indirectly-imported), Y = (kind:namespace)

   from X import *: X = (kind:module,  role:namespace)

   from X import Y: X = (kind:module,  role:namespace), Y = (kind:unknown, role:imported)

   from X import Y as Z: X = (kind:module,  role:namespace), Y = (kind:unknown, role:indirectly-imported), Z = (kind:unknown) */