Using clang code-completion with CodeLite


As of version 3.0, CodeLite supports code completion based on the clang compiler. From CodeLite v3.5 this is improved; if you are still using v3.0 please see this page instead.



Advantages and disadvantages of clang code-completion


Code-completion is more accurate and complete with clang than with ctags. It is also much better at visually-disabling unused code-paths of macros e.g. #if defined FOO.

Its disadvantage is that it's slower and more cpu-intensive.


Configuring clang


Adding include paths

Since clang is a full compiler, it needs to be told search paths for the standard include files (like stdio.h, string etc)

This is done from: Settings | Tags Settings | clang | General

Sensible suggestions are provided, but you can set paths manually (each path should be on a separate line in the 'search paths' text area). Clicking on the 'Suggest search paths...' button will reset the defaults.





In the Cache tab of the settings dialogs you can clear the clang cache, and also choose when a file is parsed: on loading, or only when code-completion is triggered.



Setting priorities between clang / ctags


CodeLite can work with both parsers at the same time.
However, you can (and should) set your preference for which engine to try first.

The following table describes CodeLite's behavior for the combination of the two check boxes 'Enable clang code completion' and 'Use clang completion over ctags completion':

Enable clang code completionUse clang completion over ctags completionDescription
X CodeLite will use the ctags parser first. If that fails, it will try again using the clang parser
XXonly the clang code completion is used
  only the ctags parser is used

By default CodeLite sets both checkboxes to FALSE (i.e. un-checked).



Working with standard CodeLite projects


When working with standard CodeLite projects (i.e. projects which are using CodeLite's generated makefiles) clang completion should work out of the box. If it doesn't, please report it.



Working with custom-build projects


Custom-build projects cause a problem, since CodeLite does not know which compilation flags/include paths/macros should be passed to clang for producing code completion.
CodeLite 'solves' this problem by allowing the user to enter them himself.

These flags can be set in 2 levels:

  • The workspace
  • The project

The workspace level

Right-click on the workspace icon in the workspace view and select Workspace settings | Code Completion
This will pop up the following dialog:

This dialog is divided into three areas:

  • Search paths
  • Compile flags
  • Macros

Search paths: In this text box you can enter the include paths for clang. Each include path should be placed on a separate line.

Compile flags: Enter here the compilation flags (e.g. -g or -Wall) that should be passed to clang. Note that this text box also accepts backticks and shell expressions (e.g. `wx-config --cxxflags` or $(shell wx-config --cxxflags)). Each flags/expression entry should be placed on a separate line.

Macros: Enter here the macros that should be passed to clang (e.g. _WIN32=1). Each macro should be placed on a separate line.

The project level

You can also specify a set of flags/include paths/macros per project. This is done from:
Right-click on your project, Project Settings | Code Completion
The project's code completion page is identical to the workspace one above.



Using clang with macros


If it has the necessary information available, clang can tell CodeLite to 'grey out' code-lines where a macro causes them to be unused. This is controlled by Settings | Tags Settings | Colouring | Colour macro blocks with grey text colour when the macro is not defined

This should happen automatically for standard CodeLite projects.

Projects using a custom makefile are more challenging. The easiest way is probably to copy the compilation line of a typical source file from your project into the Compile flags textbox of your Project or Workspace settings; CodeLite will parse this line and will pass the needed macros and include paths to clang.
If the compilation line is actually the output of a script (e.g. wx-config --cxxflags or pkg-config --cflags gtk+-2.0) you can replace all or part of it by a call to the script, using backticks or $(shell...).

Edit - History - Print - Recent Changes - Search
Page last modified on November 29, 2011, at 09:32 PM