xref: /Universal-ctags/docs/contributions.rst (revision 29820e887b2a3ad705ba45a88fbbbe7ec3d0aa8a)
1171c0577SHiroo HAYASHI.. _contributions:
2171c0577SHiroo HAYASHI
3eae71684SMasatake YAMATO======================================================================
4eae71684SMasatake YAMATOContributions
5eae71684SMasatake YAMATO======================================================================
6eae71684SMasatake YAMATO
7eae71684SMasatake YAMATO:Maintainer: Masatake YAMATO <yamato@redhat.com>
8eae71684SMasatake YAMATO
9eae71684SMasatake YAMATO.. contents:: `Table of contents`
10eae71684SMasatake YAMATO	:depth: 3
11eae71684SMasatake YAMATO	:local:
12eae71684SMasatake YAMATO
13eae71684SMasatake YAMATO----
14eae71684SMasatake YAMATO
15eae71684SMasatake YAMATOYou are welcome.
16eae71684SMasatake YAMATO
172cd4ac56SHiroo HAYASHISupporting many parsers with few developers is impossible.  We invite
182cd4ac56SHiroo HAYASHIthe person who contributes a parser to u-ctags team, especially if the
192cd4ac56SHiroo HAYASHItarget language is updated frequently. TypeScript is a typical
202cd4ac56SHiroo HAYASHIfrequently updated language.
21eae71684SMasatake YAMATO
22ea05728cSDoug KearnsThis is what we would like potential contributors to know. In this
23eae71684SMasatake YAMATOsection "you" means a contributor, and "we" means reviewers. "I" means
24eae71684SMasatake YAMATOMasatake YAMATO, the author of this section.
25eae71684SMasatake YAMATO
262cd4ac56SHiroo HAYASHIThis page gathers random notes for newly joined members.
27eae71684SMasatake YAMATO
282cd4ac56SHiroo HAYASHIBasic rules
292cd4ac56SHiroo HAYASHI---------------------------------------------------------------------
302cd4ac56SHiroo HAYASHI
312cd4ac56SHiroo HAYASHIYou are the maintainer of your parser, of course.
322cd4ac56SHiroo HAYASHI
332cd4ac56SHiroo HAYASHIYou may update your parser as you want under the rules described
342cd4ac56SHiroo HAYASHIlater.
352cd4ac56SHiroo HAYASHI
362cd4ac56SHiroo HAYASHIYou may review pull requests changing your parser.
372cd4ac56SHiroo HAYASHI
382cd4ac56SHiroo HAYASHIA parser exists and is maintained independently form other
392cd4ac56SHiroo HAYASHIparsers. However, considering the consistency between parsers are not
402cd4ac56SHiroo HAYASHIbad.
412cd4ac56SHiroo HAYASHI
422cd4ac56SHiroo HAYASHIYou can put your name to docs/developers.rst.
432cd4ac56SHiroo HAYASHI
442cd4ac56SHiroo HAYASHIRead docs.ctags.io.
452cd4ac56SHiroo HAYASHI
462cd4ac56SHiroo HAYASHIBefore You Start
472cd4ac56SHiroo HAYASHI---------------------------------------------------------------------
482cd4ac56SHiroo HAYASHI
492cd4ac56SHiroo HAYASHI .. Specific to add new parser and/or new kind/role
502cd4ac56SHiroo HAYASHI
512cd4ac56SHiroo HAYASHIWhen working on ctags I take into account the following uses for
522cd4ac56SHiroo HAYASHItags:
532cd4ac56SHiroo HAYASHI
542cd4ac56SHiroo HAYASHI1. inserting the name with completion,
552cd4ac56SHiroo HAYASHI2. jumping to the definition of the name (in an editor or similar tool),
562cd4ac56SHiroo HAYASHI3. navigating the source code tree,
572cd4ac56SHiroo HAYASHI4. summarizing the source code tree, and
582cd4ac56SHiroo HAYASHI5. answering a query about the source code tree.
592cd4ac56SHiroo HAYASHI
602cd4ac56SHiroo HAYASHIWhen I review new parser code, I expect the parser to contribute to
612cd4ac56SHiroo HAYASHIthese purposes.
622cd4ac56SHiroo HAYASHI
632cd4ac56SHiroo HAYASHIWhat should be tagged?
642cd4ac56SHiroo HAYASHI~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
652cd4ac56SHiroo HAYASHI
6604cce070SHiroo HAYASHIThere are two classes of tags. The primary class is a *definition tag*.
672cd4ac56SHiroo HAYASHIIf a name is defined in a file, the name and the line and the file
682cd4ac56SHiroo HAYASHIwhere the name is defined should be tagged (recorded). However, in
692cd4ac56SHiroo HAYASHIsome languages answering, "What is a definition?" is not so obvious.
702cd4ac56SHiroo HAYASHIYou may have to decide what is tagged in your parser thoughtfully.
712cd4ac56SHiroo HAYASHIThe purposes listed at the top of this subsection should help you
722cd4ac56SHiroo HAYASHIdecide.
732cd4ac56SHiroo HAYASHI
7404cce070SHiroo HAYASHIThe secondary class is a *reference tag*. This is newly introduced in
75bb84f88aSHiroo HAYASHIUniversal Ctags and is not available in Exuberant Ctags. If a name is
762cd4ac56SHiroo HAYASHIused (or referenced) in a file, it can be tagged as a reference tag.
772cd4ac56SHiroo HAYASHI
782cd4ac56SHiroo HAYASHIDon't be confused by the two tag classes.
792cd4ac56SHiroo HAYASHI
802cd4ac56SHiroo HAYASHIDefining kinds and roles
812cd4ac56SHiroo HAYASHI~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
822cd4ac56SHiroo HAYASHI
832cd4ac56SHiroo HAYASHIDefining kinds is the most important task in writing a new parser.
842cd4ac56SHiroo HAYASHIOnce a kind is introduced, we cannot change it because it breaks
852cd4ac56SHiroo HAYASHItags file compatibility.
862cd4ac56SHiroo HAYASHI
8704cce070SHiroo HAYASHISee :ref:`tag_entries` in :ref:`ctags(1) <ctags(1)>` for more details of kinds
8804cce070SHiroo HAYASHIand roles.
8904cce070SHiroo HAYASHI
902cd4ac56SHiroo HAYASHIScope information and full qualified tags
912cd4ac56SHiroo HAYASHI~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
922cd4ac56SHiroo HAYASHI
932cd4ac56SHiroo HAYASHIOptional.
942cd4ac56SHiroo HAYASHITBW.
952cd4ac56SHiroo HAYASHI
962cd4ac56SHiroo HAYASHIDeveloping a parser
97eae71684SMasatake YAMATO---------------------------------------------------------------------
98eae71684SMasatake YAMATO
99eae71684SMasatake YAMATOOrigin of changes and license
100eae71684SMasatake YAMATO~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
101eae71684SMasatake YAMATO
102eae71684SMasatake YAMATOMake clear where the patches come from and who wrote them.
103eae71684SMasatake YAMATO
104ea05728cSDoug KearnsIf you backport patches from Geany or some other project, their
105ea05728cSDoug Kearnscommit IDs should be logged, too.
106eae71684SMasatake YAMATO
107ea05728cSDoug KearnsInclude a copyright notice when adding a new
108ea05728cSDoug Kearns``{parsers,main}/*.[ch]`` file.
109ea05728cSDoug KearnsA new file also requires a license notice at the head of the file.
110eae71684SMasatake YAMATO
111ea05728cSDoug KearnsWe expect your change (or new code) to be provided under the terms of
112ea05728cSDoug Kearnsthe General Public License version 2 or any later version. We would
113ea05728cSDoug Kearnslike you to express "version 2 or any later version".
114eae71684SMasatake YAMATO
1152cd4ac56SHiroo HAYASHIReference
116eae71684SMasatake YAMATO~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117eae71684SMasatake YAMATO
1182cd4ac56SHiroo HAYASHIIn the comment at the head of your source file, include a URL for a
1192cd4ac56SHiroo HAYASHIweb page that explains the language your parser deals with.
1202cd4ac56SHiroo HAYASHIEspecially if the language is not well known.
121eae71684SMasatake YAMATO
1222cd4ac56SHiroo HAYASHIHere is an example.
123ea05728cSDoug Kearns
1242cd4ac56SHiroo HAYASHI.. code-block:: C
125eae71684SMasatake YAMATO
1262cd4ac56SHiroo HAYASHI    /*
1272cd4ac56SHiroo HAYASHI    *
1282cd4ac56SHiroo HAYASHI    *   Copyright (c) 2016, Masatake YAMATO
1292cd4ac56SHiroo HAYASHI    *   Copyright (c) 2016, Red Hat, K.K.
1302cd4ac56SHiroo HAYASHI    *
1312cd4ac56SHiroo HAYASHI    *   This source code is released for free distribution under the terms of the
1322cd4ac56SHiroo HAYASHI    *   GNU General Public License version 2 or (at your option) any later version.
1332cd4ac56SHiroo HAYASHI    *
1342cd4ac56SHiroo HAYASHI    *   This module contains functions for generating tags for property list defined
1352cd4ac56SHiroo HAYASHI    *   in http://www.apple.com/DTDs/PropertyList-1.0.dtd.
1362cd4ac56SHiroo HAYASHI    */
137eae71684SMasatake YAMATO
138eae71684SMasatake YAMATOC language
139eae71684SMasatake YAMATO~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
140eae71684SMasatake YAMATO
141ea05728cSDoug KearnsDon't forget to use `static` modifiers. Don't introduce unnecessary
142eae71684SMasatake YAMATOglobal variables.
143eae71684SMasatake YAMATO
144eae71684SMasatake YAMATORemove unused variables and types. If you want to keep them in your
145ea05728cSDoug Kearnssource code, include a descriptive comment.
146eae71684SMasatake YAMATO
147ea05728cSDoug KearnsUse the available facilities provided by the ctags core. If the
148ea05728cSDoug Kearnsfacilities are not enough for writing a parser, consider extending
149ea05728cSDoug Kearnsthe core first.
150eae71684SMasatake YAMATO
151eae71684SMasatake YAMATOUse underscores in names only in file scope objects.
152ea05728cSDoug KearnsDon't use them in function declarations, variable declarations or
153ea05728cSDoug Kearnsmacro names in header files.
154eae71684SMasatake YAMATO
155ad29a2fdSDoug KearnsBasic whitespace settings are specified in the `EditorConfig
1562b8661bbSK.Takata<https://editorconfig.org/>`_ configuration file (`.editorconfig`).
1572b8661bbSK.TakataThere are `plugins <https://editorconfig.org/#download>`_ available
1581f9cdae0SDoug Kearnsfor most popular editors to automatically configure these settings.
159eae71684SMasatake YAMATO
160ad29a2fdSDoug KearnsStyle guidelines are largely captured in the `Uncrustify
161ad29a2fdSDoug Kearns<http://uncrustify.sourceforge.net/>`_ configuration file
162ad29a2fdSDoug Kearns(`.uncrustify.cfg`). Formatting can be checked with:
163ad29a2fdSDoug Kearns
164ad29a2fdSDoug Kearns.. code-block:: console
165ad29a2fdSDoug Kearns
166ad29a2fdSDoug Kearns    $ uncrustify -c .uncrustify.cfg -f parsers/awk.c | diff -u parsers/awk.c -
167ad29a2fdSDoug Kearns
168ea05728cSDoug KearnsDon't mix `whitespace cleanup` fixes and other improvements in one
169ea05728cSDoug Kearnscommit when changing the existing code. Style fixes, including
170ea05728cSDoug Kearns`whitespace cleanup`, should be in a separate commit. Mixing
171ea05728cSDoug Kearnsfunctional changes with style fixes makes reviewing harder.
172eae71684SMasatake YAMATO
173ea05728cSDoug KearnsIf possible, don't use file static variables. Find an alternative way
174ea05728cSDoug Kearnsthat uses parameters.
175ea05728cSDoug Kearns
1760293b7a2SMasatake YAMATO
1770293b7a2SMasatake YAMATO.. NOT REVIEWED YET
1780293b7a2SMasatake YAMATO
1790293b7a2SMasatake YAMATONotes for GNU emacs users
1800293b7a2SMasatake YAMATO.........................................................................
1810293b7a2SMasatake YAMATO
1820293b7a2SMasatake YAMATOIf you use GNU emacs, utilize the `.editorconfig` configuration based
1830293b7a2SMasatake YAMATOon non-GNU C style. Here non-GNU C style means
1840293b7a2SMasatake YAMATO"align a keyword for control flow and `{` of the block start".
1850293b7a2SMasatake YAMATO
1860293b7a2SMasatake YAMATOGNU style:
187fdd4220dSMasatake YAMATO
1880293b7a2SMasatake YAMATO.. code-block:: C
1890293b7a2SMasatake YAMATO
1900293b7a2SMasatake YAMATO	if (...)
1910293b7a2SMasatake YAMATO	    {
1920293b7a2SMasatake YAMATO		...
1930293b7a2SMasatake YAMATO
1940293b7a2SMasatake YAMATOnon-GNU style:
19577bb1ef2SMasatake YAMATO
1960293b7a2SMasatake YAMATO.. code-block:: C
1970293b7a2SMasatake YAMATO
1980293b7a2SMasatake YAMATO	if (...)
1990293b7a2SMasatake YAMATO	{
2000293b7a2SMasatake YAMATO		...
2010293b7a2SMasatake YAMATO
2020293b7a2SMasatake YAMATOFor combining the style and `.editorconfig` configuration, put
2030293b7a2SMasatake YAMATOfollowing code snippet to your .emacs:
2040293b7a2SMasatake YAMATO
2050293b7a2SMasatake YAMATO.. code-block:: emacs
2060293b7a2SMasatake YAMATO
2070293b7a2SMasatake YAMATO	(add-hook 'hack-local-variables-hook
2080293b7a2SMasatake YAMATO		(lambda () (editorconfig-apply)))
2090293b7a2SMasatake YAMATO
2100293b7a2SMasatake YAMATO`.dir-locals.el` in ctags source tree applies "linux" style of `cc-mode`.
2110293b7a2SMasatake YAMATOAbove code snippet applies the `.editorconfig` configuration AFTER
2120293b7a2SMasatake YAMATOinstalling the "linux" style to the current buffer.
2130293b7a2SMasatake YAMATO
2140293b7a2SMasatake YAMATOI like GNU style, but for keeping consistency in existing code of
215bb84f88aSHiroo HAYASHIExuberant Ctags, the origin of Universal Ctags, I introduced the style
2160293b7a2SMasatake YAMATOand configuration to my .emacs.  Please, do the same.
2170293b7a2SMasatake YAMATO
218cacd2675SHiroo HAYASHICompatibility
219cacd2675SHiroo HAYASHI~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
220cacd2675SHiroo HAYASHI
221cacd2675SHiroo HAYASHIWe are trying to maintain compatibility with Exuberant-ctags in the
222cacd2675SHiroo HAYASHIfollowing two areas.
223cacd2675SHiroo HAYASHI
224cacd2675SHiroo HAYASHI* Command line option
225cacd2675SHiroo HAYASHI* Tag file compatibility
226eae71684SMasatake YAMATO
227eae71684SMasatake YAMATOCommand line options
228eae71684SMasatake YAMATO~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
229eae71684SMasatake YAMATO
230ea05728cSDoug KearnsDon't introduce `--<LANG>-foo=...` style options. They are less
231ea05728cSDoug Kearnssuitable for command-line completion by the zsh/bash completion
232ea05728cSDoug Kearnsengines. Instead, introduce `--foo-<LANG>=...` style options.
233eae71684SMasatake YAMATO
234ea05728cSDoug KearnsAdd an entry to docs/news.rst if you change the behavior of an option
235ea05728cSDoug Kearnsor introduce a new option. If you think the option is stable enough,
236ea05728cSDoug Kearnsadd it to ctags.1.in, too.
237eae71684SMasatake YAMATO
238ea05728cSDoug KearnsUse underscore as a prefix for experimental options. Once an option
239ea05728cSDoug Kearnsis introduced, it must be maintained. We don't want to remove it
240ea05728cSDoug Kearnslater. If you are not sure of the usefulness of the option, use an
241ea05728cSDoug Kearnsunderscore at the start of a long option name like: `--_echo`.
242eae71684SMasatake YAMATO
243eae71684SMasatake YAMATOWrite a test case for Tmain or Units.
244eae71684SMasatake YAMATO
245bb84f88aSHiroo HAYASHIDon't remove an option, especially if it exists in Exuberant Ctags.
246eae71684SMasatake YAMATO
247171c0577SHiroo HAYASHIWriting parser
248eae71684SMasatake YAMATO~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
249171c0577SHiroo HAYASHIThere are two ways to write a parser, writing in C and using *optlib parser*.
250eae71684SMasatake YAMATO
251171c0577SHiroo HAYASHIUniversal Ctags extends the *optlib parser* feature so extensively that it can
252171c0577SHiroo HAYASHIimplement most of functions of a parser.
253171c0577SHiroo HAYASHI*optlib parser* is also suitable for prototyping.
254eae71684SMasatake YAMATO
255171c0577SHiroo HAYASHISee :ref:`ctags-optlib(7) <ctags-optlib(7)>` and :ref:`optlib` for details.
256171c0577SHiroo HAYASHISee :ref:`optlib2c` how to add a optlib parser on ``ctags``.
257eae71684SMasatake YAMATO
258171c0577SHiroo HAYASHIFor writing a parser in C see :ref:`writing_parser_in_c`.
259eae71684SMasatake YAMATO
2602cd4ac56SHiroo HAYASHIBuild script
2612cd4ac56SHiroo HAYASHI~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
262171c0577SHiroo HAYASHITo add your optlib parser, ``foo.ctags``, into ``ctags`` do the following steps;
2632cd4ac56SHiroo HAYASHI
264171c0577SHiroo HAYASHI* put ``foo.ctags`` file on ``optlib/`` directory
26579059629SHiroo HAYASHI* add ``foo.ctags`` on ``OPTLIB2C_INPUT`` variable in ``source.mak``
266171c0577SHiroo HAYASHI* add ``fooParser`` on ``PARSER_LIST`` macro variable in ``main/parser_p.h``
267171c0577SHiroo HAYASHI* add ``foo`` on the list in the section "New parsers" in ``docs/news.rst``
268171c0577SHiroo HAYASHI* add ``"..\optlib\foo.c"`` in ``win32/ctags_vs2013.vcxproj``
269171c0577SHiroo HAYASHI* add ``"..\optlib\foo.c"`` in  ``win32/ctags_vs2013.vcxproj.filters``
2702cd4ac56SHiroo HAYASHI
271171c0577SHiroo HAYASHITranslated C code is also committed to our git repository. The translated code
272171c0577SHiroo HAYASHIis useful for building ctags on the platforms where optlib2c doesn't run.
273171c0577SHiroo HAYASHI
274171c0577SHiroo HAYASHITo add your parser file, ``foo.c``, into ``ctags`` do the following steps;
275171c0577SHiroo HAYASHI
276171c0577SHiroo HAYASHI* put ``foo.c`` file on ``parsers/`` directory
277171c0577SHiroo HAYASHI* add ``foo.c`` on ``PARSER_SRCS`` variable in ``sources.mak``
278171c0577SHiroo HAYASHI* add ``foo`` on the list in the section "New parsers" in ``docs/news.rst``
279171c0577SHiroo HAYASHI* add ``"..\parsers\foo.c"`` in ``win32/ctags_vs2013.vcxproj``
280171c0577SHiroo HAYASHI* add ``"..\parsers\foo.c"`` in  ``win32/ctags_vs2013.vcxproj.filters``
281171c0577SHiroo HAYASHI
282*29820e88SHiroo HAYASHIIf you have GNU make, ``make -C win32`` updates the win32 files described above
283*29820e88SHiroo HAYASHIfrom ``makefile.mak``.
284*29820e88SHiroo HAYASHIWithout updating win32 files our CI process run on
285*29820e88SHiroo HAYASHIAppveyor will fail.
286171c0577SHiroo HAYASHI
287171c0577SHiroo HAYASHISee `this pull request <https://github.com/universal-ctags/ctags/pull/2765>`_
288171c0577SHiroo HAYASHIfor the `Meson` parser as an example of optlib parser.
2892cd4ac56SHiroo HAYASHI
2902cd4ac56SHiroo HAYASHITesting
2912cd4ac56SHiroo HAYASHI---------------------------------------------------------------------
2922cd4ac56SHiroo HAYASHI
2932cd4ac56SHiroo HAYASHIAdd test cases, and run both existing cases and your new cases.
2942cd4ac56SHiroo HAYASHI
2952cd4ac56SHiroo HAYASHIIf you add a new parser or modify an existing parser, add new test
2962cd4ac56SHiroo HAYASHIcases to "Units". If you modify the core, add new test cases to
29704cce070SHiroo HAYASHI"Tmain". The way to write and run test cases is described in
29804cce070SHiroo HAYASHI:ref:`testing_ctags` and :ref:`testing_parser` section of this guide.
2992cd4ac56SHiroo HAYASHI
3002cd4ac56SHiroo HAYASHIWith the exception of the tmain test harness, you can specify VG=1
3012cd4ac56SHiroo HAYASHIfor running test cases under the Valgrind memory debugger.
3022cd4ac56SHiroo HAYASHI
3032cd4ac56SHiroo HAYASHIA parse should not enter an infinite loop for bad input.
3042cd4ac56SHiroo HAYASHIA parse should not crash for bad input.
3052cd4ac56SHiroo HAYASHIA parse should return control to its caller for bad input.
3062cd4ac56SHiroo HAYASHI
3072cd4ac56SHiroo HAYASHIDescribe what kind of tests are passed in the commit message.
3082cd4ac56SHiroo HAYASHIe.g. ::
3092cd4ac56SHiroo HAYASHI
3102cd4ac56SHiroo HAYASHI  make units LANGUAGES=TTCN VG=1 is passed.
3112cd4ac56SHiroo HAYASHI  make fuzz LANGUAGES=TTCN VG=1  is passed.
3122cd4ac56SHiroo HAYASHI  make chop LANGUAGES=TTCN VG=1  is passed.
3132cd4ac56SHiroo HAYASHI
3142cd4ac56SHiroo HAYASHITest cases
3152cd4ac56SHiroo HAYASHI~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3162cd4ac56SHiroo HAYASHI
3172cd4ac56SHiroo HAYASHIAdd a test case to Unit when creating or modifying a parser.
3182cd4ac56SHiroo HAYASHI
3192cd4ac56SHiroo HAYASHIAdd a test case to Tmain when modifying the core.
3202cd4ac56SHiroo HAYASHI
3212cd4ac56SHiroo HAYASHIAdd a test case to Tinst when modifying the install target in the
3222cd4ac56SHiroo HAYASHIMakefile.
3232cd4ac56SHiroo HAYASHI
3242cd4ac56SHiroo HAYASHITesting your parser
3252cd4ac56SHiroo HAYASHI~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3262cd4ac56SHiroo HAYASHI
3272cd4ac56SHiroo HAYASHIIf possible, prepare a simple test and a complex one. The simple one
3282cd4ac56SHiroo HAYASHIfor helping us, the maintainers, understand the intent of the
3292cd4ac56SHiroo HAYASHImodification.
3302cd4ac56SHiroo HAYASHI
3312cd4ac56SHiroo HAYASHIIf there are more than 3 test cases for a parser, a parser specific
3322cd4ac56SHiroo HAYASHItest case directory should be prepared like `Units/parser-c.r`.
3332cd4ac56SHiroo HAYASHI
3343b89b8acSMasatake YAMATOAdd realistic examples for you parser to *codebase*
3353b89b8acSMasatake YAMATO~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3363b89b8acSMasatake YAMATO
3373b89b8acSMasatake YAMATOAt `codebase <https://github.com/universal-ctags/codebase>`_, we
3383b89b8acSMasatake YAMATOcollect realistic examples that can be used for evaluating your parser
3393b89b8acSMasatake YAMATOespecially about its performance aspect. Consider contributing to the
3403b89b8acSMasatake YAMATOrepository when adding a new parser to Universal Ctags.
3413b89b8acSMasatake YAMATO
3422cd4ac56SHiroo HAYASHIWriting Documents
3432cd4ac56SHiroo HAYASHI---------------------------------------------------------------------
3442cd4ac56SHiroo HAYASHI
34576676929SHiroo HAYASHI* ``man/*.rst`` files are the source files of our man pages.
34676676929SHiroo HAYASHI  The man pages are for users. See "`How to add a new man page for your parser`_".
34776676929SHiroo HAYASHI
34876676929SHiroo HAYASHI* ``docs/*.rst`` files explain experimental
3492cd4ac56SHiroo HAYASHI  new features. The files are for developers. The parts of contents
35004cce070SHiroo HAYASHI  of ``docs/*.rst`` should be moved to ``man/*.rst`` in the future.
3512cd4ac56SHiroo HAYASHI
35204cce070SHiroo HAYASHI* Update ``docs/news.rst`` especially if you add a new parser.
3532cd4ac56SHiroo HAYASHI
35404cce070SHiroo HAYASHI* Write ``docs/parser-<NAME-OF-YOUR-PARSER>.rst`` as you want.
3552cd4ac56SHiroo HAYASHI  A FAQ and the design or your parser are common topics.
3562cd4ac56SHiroo HAYASHI  Consider the maintenance of your parser after you left the
3572cd4ac56SHiroo HAYASHI  project for some reason.
3582cd4ac56SHiroo HAYASHI
35976676929SHiroo HAYASHIHow to add a new man page for your parser
36076676929SHiroo HAYASHI~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36176676929SHiroo HAYASHI
36276676929SHiroo HAYASHI1. write what the users of your parser may want to (or should) know to ``man/ctags-lang-LANGUAGE.7.rst.in``
363648c1a07SHiroo HAYASHI2. add ``man/ctags-lang-LANGUAGE.7`` to ``GEN_IN_MAN_FILES`` of ``man/Makefile.am``.
364648c1a07SHiroo HAYASHI3. run ``make -C man update-docs``. This step generates the rst file at ``docs/man/ctags-lang-LANGUAGE.7.rst``.
365648c1a07SHiroo HAYASHI4. add ``ctags-lang-LANGUAGE(7)`` to (toctree of) ``docs/man-pages.rst``.
366648c1a07SHiroo HAYASHI5. do ``git add`` for
36776676929SHiroo HAYASHI    * ``man/ctags-lang-LANGUAGE.7.rst.in``
36876676929SHiroo HAYASHI    * ``docs/man/ctags-lang-LANGUAGE.7.rst``
369648c1a07SHiroo HAYASHI6. git commit with a log header: "``docs(man): add a man page for LANGUAGE``".
370648c1a07SHiroo HAYASHI7. make a pull request
371648c1a07SHiroo HAYASHI
372648c1a07SHiroo HAYASHI.. TODO: Why do we have to git add ``docs/man/ctags-lang-LANGUAGE.7.rst``?
373648c1a07SHiroo HAYASHI	A system which uses it has Sphinx. It should be able to generate
374648c1a07SHiroo HAYASHI	``docs/man/ctags-lang-LANGUAGE.7.rst``.
37576676929SHiroo HAYASHI
3762cd4ac56SHiroo HAYASHICommitting and submitting a pull request
3772cd4ac56SHiroo HAYASHI---------------------------------------------------------------------
3782cd4ac56SHiroo HAYASHI
3792cd4ac56SHiroo HAYASHI* Make a pull request even if the change is small enough.
3802cd4ac56SHiroo HAYASHI
3812cd4ac56SHiroo HAYASHI* Wait for one day till merging even if the change is small enough.
3822cd4ac56SHiroo HAYASHI
3832cd4ac56SHiroo HAYASHI* Wait for 3 days at least for non-small change to your parser.
3842cd4ac56SHiroo HAYASHI
385cacd2675SHiroo HAYASHI* Wait for 7 days at least and get an LGTM (Looks Good To Me) comment from a
386cacd2675SHiroo HAYASHI  member of the team if your commit changes the other parts than your parser and
387cacd2675SHiroo HAYASHI  the changes are not obvious.
38804cce070SHiroo HAYASHI
3892cd4ac56SHiroo HAYASHI* Add a test case to your pull request. To make git-bisect happy,
3902cd4ac56SHiroo HAYASHI  don't add a test case for a feature or a bugfix before adding the
3912cd4ac56SHiroo HAYASHI  code for the feature or the bugfix.
3922cd4ac56SHiroo HAYASHI
3932cd4ac56SHiroo HAYASHI* Even if a pull request includes multiple commits, each commit must
3942cd4ac56SHiroo HAYASHI  be semantically well separated. Sometimes you may want to adjust
3952cd4ac56SHiroo HAYASHI  whitespaces in the code. Adjusting whitespaces is o.k., but don't
3962cd4ac56SHiroo HAYASHI  mix the other change with it. Make a commit just for the whitespaces
3972cd4ac56SHiroo HAYASHI  adjustment.
3982cd4ac56SHiroo HAYASHI
3992cd4ac56SHiroo HAYASHITitle of commit log and pull request
4002cd4ac56SHiroo HAYASHI~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4012cd4ac56SHiroo HAYASHI
4022cd4ac56SHiroo HAYASHI* "Misc Fixes" is allowed as far as each commit in a pull request is
4032cd4ac56SHiroo HAYASHI  semantically well separated. Sometimes, you may fix various minor
4042cd4ac56SHiroo HAYASHI  things randomly. Making pull requests for each of them is
4052cd4ac56SHiroo HAYASHI  boring. You may want to make "mix fixes" pull request especially if
4062cd4ac56SHiroo HAYASHI  your code is young.
4072cd4ac56SHiroo HAYASHI
40804cce070SHiroo HAYASHI* Use [WIP] (Work In Progress) prefix as the title of your pull request, if you don't
4092cd4ac56SHiroo HAYASHI  want people to take time for reviewing your code. Removing [WIP]
4102cd4ac56SHiroo HAYASHI  implies "ready to be reviewed."
4112cd4ac56SHiroo HAYASHI
41204cce070SHiroo HAYASHI* Use [FYI] (For Your Information) prefix as the title to show your idea or sketch represented
4132cd4ac56SHiroo HAYASHI  in C language.
4142cd4ac56SHiroo HAYASHI
4152cd4ac56SHiroo HAYASHI* Use the name of your parser as the prefix of a commit log.
4162cd4ac56SHiroo HAYASHI
4172cd4ac56SHiroo HAYASHI  .. code-block:: git
4182cd4ac56SHiroo HAYASHI
4192cd4ac56SHiroo HAYASHI        C++: record template type parameters to detect the end of template prefix
4202cd4ac56SHiroo HAYASHI
4212cd4ac56SHiroo HAYASHI        If we know Foo is a name of type, it becomes easier to detect whether
4222cd4ac56SHiroo HAYASHI        ">>" in "Foo>>" is a shift operator or the end marker of the template
4232cd4ac56SHiroo HAYASHI        prefix.
4242cd4ac56SHiroo HAYASHI
4252cd4ac56SHiroo HAYASHI  In the above example, "C++: " is the prefix.
4262cd4ac56SHiroo HAYASHI
4272cd4ac56SHiroo HAYASHI* Use the name of your parser as the prefix of a pull request if your
4282cd4ac56SHiroo HAYASHI  change is about a parser.
4292cd4ac56SHiroo HAYASHI
4302cd4ac56SHiroo HAYASHI* Use following prefixes for the changes other than parsers.
4312cd4ac56SHiroo HAYASHI
4322cd4ac56SHiroo HAYASHI  main:
43304cce070SHiroo HAYASHI    Changes for files under ``main/`` directory
4342cd4ac56SHiroo HAYASHI
4352cd4ac56SHiroo HAYASHI  Units:
43604cce070SHiroo HAYASHI    Changes for the test cases under ``Units/`` directory
4372cd4ac56SHiroo HAYASHI
4382cd4ac56SHiroo HAYASHI  Tmain
43904cce070SHiroo HAYASHI    Changes for the test cases under ``Tmain/`` directory
4402cd4ac56SHiroo HAYASHI
4412cd4ac56SHiroo HAYASHI  docs(web)
44204cce070SHiroo HAYASHI    Changes for the ``docs/*.rst``
4432cd4ac56SHiroo HAYASHI
4442cd4ac56SHiroo HAYASHI  docs(man)
44504cce070SHiroo HAYASHI    Changes for the ``man/*.rst``
4462cd4ac56SHiroo HAYASHI
44704cce070SHiroo HAYASHI  See also the output of ``git log`` command.
4482cd4ac56SHiroo HAYASHI
4492cd4ac56SHiroo HAYASHI* Combine prefixes with a comma if a change modifies multiple parts of our source tree
4502cd4ac56SHiroo HAYASHI
4512cd4ac56SHiroo HAYASHI  Here is an example.
4522cd4ac56SHiroo HAYASHI
4532cd4ac56SHiroo HAYASHI  .. code-block:: git
4542cd4ac56SHiroo HAYASHI
4552cd4ac56SHiroo HAYASHI
4562cd4ac56SHiroo HAYASHI        commit 64a05963c108af4b7832a2215006ff5cafcaaebb
4572cd4ac56SHiroo HAYASHI        Author: Masatake YAMATO <yamato@redhat.com>
4582cd4ac56SHiroo HAYASHI        Date:   Tue Mar 19 12:19:37 2019 +0900
4592cd4ac56SHiroo HAYASHI
46004cce070SHiroo HAYASHI        main,Flex,JavaScript,SQL,refactor: introduce a helper function to skip two character sequence
4612cd4ac56SHiroo HAYASHI
4622cd4ac56SHiroo HAYASHI        ...
4632cd4ac56SHiroo HAYASHI
4642cd4ac56SHiroo HAYASHI* Use following prefixes if the change as no run-time impact.
4652cd4ac56SHiroo HAYASHI
4662cd4ac56SHiroo HAYASHI  cosmetic
4672cd4ac56SHiroo HAYASHI    - Remove whitespaces at the end of lines
4682cd4ac56SHiroo HAYASHI    - Adjust indentation
4692cd4ac56SHiroo HAYASHI    - Remove an empty line
4702cd4ac56SHiroo HAYASHI    - ...
4712cd4ac56SHiroo HAYASHI
4722cd4ac56SHiroo HAYASHI  style
4732cd4ac56SHiroo HAYASHI    - Rename symbol names
4742cd4ac56SHiroo HAYASHI    - ...
4752cd4ac56SHiroo HAYASHI
4762cd4ac56SHiroo HAYASHI  refactor
47704cce070SHiroo HAYASHI    - Code transformation that doesn't intent changing run-time behavior
4782cd4ac56SHiroo HAYASHI
4792cd4ac56SHiroo HAYASHI  These prefixes reduce the load of reviewers.
4802cd4ac56SHiroo HAYASHI
4812cd4ac56SHiroo HAYASHI* Use [INCOMPATIBLE] as a prefix for both pull request and commit log
482bb84f88aSHiroo HAYASHI  if the change breaks the compatibility with Exuberant Ctags. Write
48304cce070SHiroo HAYASHI  an explanation in ``man/ctags-incompatibilities.7.rst.in`` about the
4842cd4ac56SHiroo HAYASHI  detail of breakage.
4852cd4ac56SHiroo HAYASHI
4862cd4ac56SHiroo HAYASHI* Use [SELF-INCOMPATIBLE] as a prefix for both pull request and commit
487dccba5efSHiroo HAYASHI  log if the change breaks the compatibility with Universal Ctags
4882cd4ac56SHiroo HAYASHI  itself.
4892cd4ac56SHiroo HAYASHI
4902cd4ac56SHiroo HAYASHICommit log
4912cd4ac56SHiroo HAYASHI~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4922cd4ac56SHiroo HAYASHI
4932cd4ac56SHiroo HAYASHI(For new parsers the following criteria is not applicable.)
4942cd4ac56SHiroo HAYASHI
4952cd4ac56SHiroo HAYASHIMake clear the original motivation for the change and/or the impact
4962cd4ac56SHiroo HAYASHIon the tags file.
4972cd4ac56SHiroo HAYASHI
4982cd4ac56SHiroo HAYASHIIf you fix a bug reported somewhere on the web, its URL should be
4992cd4ac56SHiroo HAYASHIlogged, too.
5002cd4ac56SHiroo HAYASHI
501bb84f88aSHiroo HAYASHIIf the bug is reported in the Exuberant Ctags tracker on the
50204cce070SHiroo HAYASHISourceForge web site, log it as ``sf-bugs:N``, ``sf-patches:N``,
50304cce070SHiroo HAYASHI``sf-support-requests:N``, or ``sf-feature-requests:N``.
50404cce070SHiroo HAYASHI``docs/tracking.rst`` also should be updated.
5052cd4ac56SHiroo HAYASHI
506eae71684SMasatake YAMATOSquashing commits
507eae71684SMasatake YAMATO~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
508eae71684SMasatake YAMATO
509ea05728cSDoug KearnsWhen you submit a pull request you might receive some comments from a
510ea05728cSDoug Kearnsreviewer and, in response, update your patches. After updating, we
511ea05728cSDoug Kearnswould like you to squash your patches into logical units of work
512ea05728cSDoug Kearnsbefore we merge them to keep the repository history as simple as
513ea05728cSDoug Kearnspossible.
514eae71684SMasatake YAMATO
51504cce070SHiroo HAYASHI* Use ``git rebase -i`` and ``git push --force`` to refine your change in
5162cd4ac56SHiroo HAYASHI  the meaning of "semantically well separated."  "semantically well
5172cd4ac56SHiroo HAYASHI  separated" is important than "recording the history of your try and
5182cd4ac56SHiroo HAYASHI  error."
5192cd4ac56SHiroo HAYASHI
52004cce070SHiroo HAYASHIQuoted from @steveno in `#393
52104cce070SHiroo HAYASHI<https://github.com/universal-ctags/ctags/issues/393>`_ :
522eae71684SMasatake YAMATO
523eae71684SMasatake YAMATO    You can check out this page for a good example of how to squash
524eae71684SMasatake YAMATO    commits
525eae71684SMasatake YAMATO    http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html
526eae71684SMasatake YAMATO
527eae71684SMasatake YAMATO    Once you've squashed all your commits, simply do a git push -f to
528ea05728cSDoug Kearns    your fork, and GitHub will update the pull request for you
529eae71684SMasatake YAMATO    automatically.
530eae71684SMasatake YAMATO
5312cd4ac56SHiroo HAYASHIRules for reviewing a pull request
5322cd4ac56SHiroo HAYASHI---------------------------------------------------------------------
533eae71684SMasatake YAMATO
5342cd4ac56SHiroo HAYASHI* Put your rough schedule as a comment if you don't have time, but you
5352cd4ac56SHiroo HAYASHI  want to review.
5361522c29aSHiroo HAYASHI
5371522c29aSHiroo HAYASHITesting a PR locally before being merged
5381522c29aSHiroo HAYASHI~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5391522c29aSHiroo HAYASHI
5401522c29aSHiroo HAYASHIYou may want to test a PR locally before it is merged into the master
5416ab21557SHiroo HAYASHIrepository.
5426ab21557SHiroo HAYASHI
5436ab21557SHiroo HAYASHIIf you want to test a PR #2234 on a repository `upstream` as branch name
5446ab21557SHiroo HAYASHI`BRANCHNAME`;::
5456ab21557SHiroo HAYASHI
5466ab21557SHiroo HAYASHI  $ git fetch upstream pull/2234/head:BRANCHNAME
5476ab21557SHiroo HAYASHI  $ git checkout BRANCHNAME
5486ab21557SHiroo HAYASHI
5496ab21557SHiroo HAYASHIThis creates a branch `BRANCHNAME`, and pulls the PR into the branch, and
5506ab21557SHiroo HAYASHIswitches to the branch. The branch name `BRANCHNAME` does not have to be the
5516ab21557SHiroo HAYASHIsame as the branch name of the PR.
5526ab21557SHiroo HAYASHI
5536ab21557SHiroo HAYASHIAlternatively suppose you want to test ``USERNAME``'s PR with branch
5541522c29aSHiroo HAYASHIname ``main-fix-foo``;::
5551522c29aSHiroo HAYASHI
5561522c29aSHiroo HAYASHI  git checkout -b tmp-main-fix-foo master
5571522c29aSHiroo HAYASHI  git pull https://github.com/USERNAME/ctags.git main-fix-foo
5581522c29aSHiroo HAYASHI
5591522c29aSHiroo HAYASHIThis creates a branch ``tmp-main-fix-fix-foo`` from a branch ``master`` and
5601522c29aSHiroo HAYASHIswitches to it, then pulls the branch ``main-fix-foo`` from
5611522c29aSHiroo HAYASHI``https://github.com/USERNAME/ctags.git``.
562