CLI for common editor actions for Objective-C. xclang
focuses on solving common clang
integration problems into text editors. Currently projects main focus is iOS
and MacOS
platforms.
While it's really tempting to write Objective-C
application with your favorite editor, it can be a hard task without proper syntax checker and code completion that XCode
provides by default. Luckily, clang tooling can solve most of the problems and it probably used by XCode
internally. Unfortunately, clang tooling
requires some preparation steps and it's exposes low-level C
/C++
API. xclang
solves preparation steps for you and exposes simple CLI
that can be integrated into your editors.
xclang
tries to be agnostic to the editors, but it returns results in format that is usable by popular plugins for Emacs
(flycheck
, company
, autocomplete
) and Vim
(syntastic
).
At this point xclang
doesn't work as backend server, on the other hand it works pretty fast, in most cases latency in Emacs
is barely noticeable. This can be changed in future.
At this point xclang
provides this commands:
-
compilation-database
. Serves as preparation step for other operations, it builds your project withxcodebuild
CLI, parses output into Compilation Database and writes it intocompile_commands.json
. All other commands will try to find recursivelycompile_commands.json
starting from current folder. You can run this command incontinuous
mode (--continuous
), which will refreshcompilation database
each time you are adding new file. -
syntax-check
. Returnserrors
andwarnings
found in provided file. If you want to do a check on a temporary buffer (like many editor plugins do) you have to provide original buffer with-o
argument, it will be used to recover compilation arguments from the compilation database. -
code-complation
. Returns possible completions ordered bypriority
(based onclang
heuristics) at the specific location (-l
). If you are doing completion on a temporary buffer, you have to provide-o
argument. You can specify prefix (-p
) that will used for filtering completion results. -
goto-definition
. Returns location of the definition at the specific location (-l
). This command traversestranslation units
in the project in order to find definition, but will fallback to declaration (ex: for internal framework definitions).
xclang
is written with Rust, so you will need a Rust
compiler.
In order to work properly with iOS
it requires clang
version that is bundled with XCode
, so you will need to install XCode
.
Compilation process is super simple, just run: make
from the project directory. You can also run tests with make test
.
xclang
will be compiled to the bin
folder. You may consider symlinking it to the directory that is in your PATH
environment variable.
Currently only Emacs
integration is provided (company
and flycheck
). Syntastic
integration for Vim
may be provided. Unfortunately, I'm not aware of a good completion plugins for Vim
, thus it's a bit hard to provide lightweight completion solution.
Syntax check for Emacs
provided as a flycheck plugin, so it has to be installed. Once you have flycheck
you can just load-file
on the plugin file from the emacs
folder.
Syntax check happens automatically for errors
and warnings
. If it's not happening, you may consider checking if xclang
is in flycheck-checkers
list. If you don't have xclang
in your PATH
you can set path to the xclang
directly in flycheck-xclang-executable
variable.
Code completion for Emacs
provided as a company-mode plugin. It requires yasnippet for snippet expansion. Once you have installed plugins you can load-file
on the plugin file from the emacs
folder, company
mode and yasnippet
minor mode have to be active.
If you don't have xclang
in your PATH
you can set path to the xclang
directly in company-xclang-executable
variable.
Goto definition is implemented as standalone interactive
function, you can find source in emacs
folder. If you don't have xclang
in your PATH
you can set path to the xclang
directly in xclang-definition-executable
variable.