Diffusion User Guide: Symbol Indexes (Article)

http://www.phabricator.com/docs/phabricator/article/Diffusion_User_Guide_Symbol_Indexes.html

Phabricator » Diffusion User Guide: Symbol Indexes (Article)

Article Diffusion User Guide: Symbol Indexes
Defined    src/docs/userguide/diffusion_symbols.diviner:1
Group    Application User Guides
Table of Contents

    Overview
    Populating the Index
    Configuring Differential Integration


Guide to configuring and using the symbol index.

Overview

Phabricator can maintain a symbol index, which keeps track of where classes and functions are defined in the codebase. Once you set up indexing, you can use the index to do things like:

Phabricator 可以维持一个符号索引, 他可以保持对代码库中类和函数的跟踪. 当生成索引之后,你可以做类似下面的事情:


    link symbol uses in Differential code reviews to their definitions
    allow you to search for symbols
    let the IRC bot answer questions like "Where is SomeClass?"
    在Differential code reviews中根据定义链接到符号
    允许你查询符号

    让IRC机器人可以回答类似"Where is SomeClass?"的问题


NOTE: Symbol indexing is somewhat new, and has broader support for PHP than for other languages.

注意: 符号索引比较新, 在PHP中的支持比其他语言更广泛.


Populating the Index

填充索引


To populate the index, you need to write a script which identifies symbols in your codebase and set up a cronjob which pipes its output to:

./scripts/symbols/import_project_symbols.php

Phabricator includes a script which can identify symbols in PHP projects:

./scripts/symbols/generate_php_symbols.php

Phabricator also includes a script which can identify symbols in any programming language that has classes and/or functions, and is supported by Exuberant Ctags (http://ctags.sourceforge.net):

./scripts/symbols/generate_ctags_symbols.php

If you want to identify symbols from another language, you need to write a script which can export them (for example, maybe by parsing a ctags file).

The output format of the script should be one symbol per line:

<context> <name> <type> <lang> <line> <path>

For example:

ExampleClass exampleMethod function php 13 /src/classes/ExampleClass.php

Context is, broadly speaking, the scope or namespace where the symbol is defined. For object-oriented languages, this is probably a class name. The symbols with that context are class constants, methods, properties, nested classes, etc. When printing symbols without a context (those that are defined globally, for instance), the <context> field should be empty (that is, the line should start with a space).

Your script should enumerate all the symbols in your project, and provide paths from the project root (where ".arcconfig" is) beginning with a "/".

You can look at generate_php_symbols.php for an example of how you might write such a script, and run this command to see its output:

$ cd phabricator/
$ find . -type f -name '*.php' | ./scripts/symbols/generate_php_symbols.php

To actually build the symbol index, pipe this data to the import_project_symbols.php script, providing the project name:

$ ./scripts/symbols/import_project_symbols.php yourproject < symbols_data

Then just set up a cronjob to run that however often you like.

You can test that the import worked by querying for symbols using the Conduit method differential.findsymbols. Some features (like that method, and the IRC bot integration) will start working immediately. Others will require more configuration.
Configuring Differential Integration

To configure Differential integration, you need to tell Phabricator which projects have symbol indexes you want to use, and which other projects they should pull symbols from. To do this, go to Repositories -> Arcanist Projects -> Edit as an administrator. You need to fill out these fields:

    Repository: Associate the project with a tracked repository.
    Indexed Languages: Fill in all the languages you've built indexes for.
    Uses Symbols From: If this project depends on other projects, add the other projects which symbols should be looked for here. For example, Phabricator lists "Arcanist" and "libphutil" because it uses classes and functions from these projects.

Once you've configured a project, new revisions in that project will automatically link symbols in Differential.
NOTE: Because this feature depends on the syntax highlighter, it will work better for some languages than others. It currently works fairly well for PHP, but your mileage may vary for other languages.

猜你喜欢

转载自blog.csdn.net/ffb/article/details/8939772