Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve discoverability of cddatags #37954

Merged
merged 6 commits into from
Feb 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1039,12 +1039,13 @@ endif

export ODIR _OBJS LDFLAGS CXX W32FLAGS DEFINES CXXFLAGS TARGETSYSTEM

ctags: $(SOURCES) $(HEADERS) $(TESTSRC) $(TESTHDR)
ctags $(SOURCES) $(HEADERS) $(TESTSRC) $(TESTHDR)
ctags: $(ASTYLE_SOURCES)
ctags $^
./tools/json_tools/cddatags.py

etags: $(SOURCES) $(HEADERS) $(TESTSRC) $(TESTHDR)
etags $(SOURCES) $(HEADERS) $(TESTSRC) $(TESTHDR)
find data -name "*.json" -print0 | xargs -0 -L 50 etags --append
etags: $(ASTYLE_SOURCES)
etags $^
./tools/json_tools/cddatags.py

astyle: $(ASTYLE_SOURCES)
$(ASTYLE_BINARY) --options=.astylerc -n $(ASTYLE_SOURCES)
Expand Down
5 changes: 5 additions & 0 deletions doc/DEVELOPER_TOOLING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ On Windows, there is an [AStyle extension for Visual Studio](https://github.com/

See the [JSON style guide](JSON_STYLE.md).

## ctags

In addition to the usual means of creating a `tags` file via e.g. [`ctags`](http://ctags.sourceforge.net/), we provide `tools/json_tools/cddatags.py` to augment a `tags` file with locations of definitions taken from CDDA JSON data. `cddatags.py` is designed to safely update a tags file containing source code tags, so if you want both types of tag in your `tags` file then you can run `ctags -R . && tools/json_tools/cddatags.py`. Alternatively, there is a rule in the `Makefile` to do this for you; just run `make ctags` or `make etags`.


## clang-tidy

Cataclysm has a [clang-tidy configuration file](../.clang-tidy) and if you have
Expand Down
11 changes: 11 additions & 0 deletions doc/JSON_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Use the `Home` key to return to the top.

- [Introduction](#introduction)
- [Navigating the JSON](#navigating-the-json)
- [File descriptions](#file-descriptions)
* [`data/json/`](#datajson)
* [`data/json/items/`](#datajsonitems)
Expand Down Expand Up @@ -162,6 +163,16 @@ Use the `Home` key to return to the top.
# Introduction
This document describes the contents of the json files used in Cataclysm: Dark days ahead. You are probably reading this if you want to add or change content of Catacysm: Dark days ahead and need to learn more about what to find where and what each file and property does.

# Navigating the JSON
A lot of the JSON involves cross-references to other JSON entities. To make it easier to navigate, we provide a script `tools/json_tools/cddatags.py` that can build a `tags` file for you.

To run the script you'll need Python 3. On Windows you'll probably need to install that, and associate `.py` files with Python. Then open a command prompt, navigate to your CDDA folder, and run `tools\json_tools\cddatags.py`.

To use this feature your editor will need [ctags support](http://ctags.sourceforge.net/). When that's working you should be able to easily jump to the definition of any entity. For example, by positioning your cursor over an id and hitting the appropriate key combination.

* In Vim, this feature exists by default, and you can jump to a definition using [`^]`](http://vimdoc.sourceforge.net/htmldoc/tagsrch.html#tagsrch.txt).
* In Notepad++ go to "Plugins" -> "Plugins Admin" and enable the "TagLEET" plugin. Then select any id and press Alt+Space to open the references window.

# File descriptions
Here's a quick summary of what each of the JSON files contain, broken down by folder. This list is not comprehensive, but covers the broad strokes.

Expand Down
4 changes: 2 additions & 2 deletions tools/json_tools/cddatags.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def main(args):
if filename.endswith('.json'):
full_path = os.path.join(dirpath, filename)
assert full_path.startswith(TOP_DIR)
relative_path = full_path[len(TOP_DIR):].lstrip('/')
with open(full_path) as file:
relative_path = full_path[len(TOP_DIR):].lstrip(os.path.sep)
with open(full_path, encoding='utf-8') as file:
try:
json_data = json.load(file)
except Exception as err:
Expand Down