Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

ctags

From MoodleDocs
Example of auto-completion menu provided by the PHP omnicomplete extension in ViM

Ctags is a tool that generates a tag file of names found in source files. In Moodle, it can be used to index PHP functions, variables, classes and so on. These tags allow definitions to be quickly and easily located by a text editor such as vim.

In the past, the Moodle source code contained a generated tags file to be used directly. If you use this utility these days, you have to generate (and keep up-to-date) the tags file yourself. Please note that most modern IDEs do not need this to provide the functionality.

Obtaining ctags

There are several implementations of the original ctags available these days. Most Moodle developers who use ctags, found https://ctags.io/ a good one.

Generating a tags file

Example of how the tags file can be generated, tuned for Moodle development:

# cd /path/to/moodle/dirroot/
# ctags -R --fields=+aimS --php-kinds=cdfint --languages=php --extras=+q --tag-relative=yes --exclude=".git" --exclude="vendor" \
       --exclude="node_modules" --exclude="composer.phar" --totals=yes

but there are alternative ways too - such as this one.

Using in ViM

The vim editor provides the support for tags file. If you have the tags file generated in the root of the Moodle code, you will probably want something like this in your vimrc file.

set tags=tags,../tags,../../tags,../../../tags,../../../../tags,../../../../../tags,../../../../../../tags,../../../../../../../tags

Once loaded, you can use the tags file to quickly jump and navigate over the Moodle code base:

  • Place the cursor over the tag (e.g., function name) and press CTRL+].
  • Type the command :tag <tagname>
  • To return to your previous location, press CTRL+t

Please refer to your editor help for details and other options.

Integration with PHP omnicomplete

Ctags also play well the the ViM omnicomplete.

See also