Indexer¶
The indexer scans your project directory and records meta-information about classes and functions in your project.
The indexer required only for some features (such as Jump to Implementation).
Building the index¶
It will be automatically enabled when used with the language server but can also be used with RPC if run manually.
Build index and watch for changes
$ phpactor index:build --watch
Build from scratch
$ phpactor index:build --reset
The index is built automatically on LS initialize and subsequently updated as necessary.
You can however force a reindex:
Build from scratch:
:CocCommand phpactor.reindex
Make a request to indexer/reindex.
Parallel indexing¶
Processing files in parrallel trades memory usage for performance.
This happens automatically for larger indexing runs. Whenever at least
indexer.parallel_min_files files need indexing, which in
practice means the first index of a project and explicit --reset rebuilds.
Re-indexing a handful of changed files stays in the main process, where
starting a pool of workers would cost more than it saves.
By default Phpactor uses up to 8 workers, past that the main process becomes the
limiting factor and extra workers mostly cost memory. Set
indexer.parallel_workers to pick a number yourself, or to 1 to
turn parallel indexing off:
$ phpactor config:set indexer.parallel_workers 4
Each worker is a PHP process holding the records for the chunk it is working on.
Watching¶
File watchers are used to keep the index up-to-date.
Several watching systems can be used, by default Phpactor will choose the first supported one:
lsp¶
Any platform
This watcher depends on file events from the LSP client (e.g. VSCode).
inotifywait¶
Linux only, react immediately to file changes.
Installation
apt install inotify-tools
watchman¶
Linux/Mac cross platform, reacts immediately to file changes, see Watchman documentation.
Watchman is the recommended watcher.
Installation:
apt install watchman
brew install watchman
find¶
Linux/Mac/POSIX Poll the system for changes every 5 seconds.
This tool should be installed by default.
php¶
Any system: Poll system using PHP (slow) every 5 seconds.
Querying from the CLI¶
You can query the index from the CLI:
$ phpactor index:query "Symfony\\Component\\Console\\Output\\OutputInterface"
$ phpactor index:query "sprintf"
$ phpactor index:query "method#createFoobar"
$ phpactor index:query "property#createFoobar"
$ phpactor index:query "constant#createFoobar"
Note that this information is primarily intended for the indexer and is not yet intended to provide a true “querying” facility.
Configuration¶
List the possible configuration options with phpactor config:dump | grep
indexer, explanations of some important ones:
indexer.enabled_watchers: List of watchers to enable (e.g. inotify, find).
indexer.include_patterns: List of glob patterns to include
indexer.exclude_patterns: List of glob patterns to exclude
indexer.stub_paths: List of external paths to index
indexer.poll_time: Poll time used for polling watchers (e.g.
find,php)indexer.buffer_time: Time to wait to collect batch messages from “realtime” watchers (e.g.
inotify)indexer.parallel_workers: Number of child processes used to parse files, see Parallel indexing
indexer.parallel_min_files: How many files an indexing run needs before it is worth starting those child processes
Troubleshooting¶
Inotify: Why isn’t inotifywait used when I’m on Linux?¶
It may not be installed, on Debian/Ubuntu
$ sudo apt install inotify-tools
Inotify: inotify limit reached¶
The default number of watchers is quite low by default, try increasing the number of watchers:
$ sudo sysctl fs.inotify.max_user_watches=100000
Note this still may not be sufficient, so increase as necessary, make the
change permanent by writing to /etc/sysctl.conf