## IdeCompileCommands IdeCompileCommands — Integration with compile_commands.json |

## Functions

IdeCompileCommands * | ide_compile_commands_new ()
gboolean | ide_compile_commands_load ()
void | ide_compile_commands_load_async ()
gboolean | ide_compile_commands_load_finish ()
gchar ** | ide_compile_commands_lookup ()

## Types and Values

#define | IDE_TYPE_COMPILE_COMMANDS
| IdeCompileCommands

## Object Hierarchy

        GObject
        ╰── IdeCompileCommands

## Description

The IdeCompileCommands object provides a simplified interface to interact with compile_commands.json files which are generated by a number of build systems, including Clang tooling, Meson and CMake.

Create a new IdeCompileCommands instance, and then asynchronously load the file using `ide_compile_commands_load_async()`. After the database has been loaded, you can access build commands using `ide_compile_commands_lookup()`.

Due to the rather unfortunate design of JSON, this file holds on to a number of strings during the lifetime of the object, for each of the compile commands. On larger projects, this can be the order of a couple of megabytes.

## Functions

### ide_compile_commands_new ()

    IdeCompileCommands *
    ide_compile_commands_new (void);

Creates a new IdeCompileCommands object which can be used to parse clang-style compile commands database files (compile_commands.json).

#### Returns

The newly created IdeCompileCommands

Since: 3.32

### ide_compile_commands_load ()

    gboolean
    ide_compile_commands_load (IdeCompileCommands *self,
                               GFile *file,
                               GCancellable *cancellable,
                               GError **error);

Synchronously loads the contents of the requested `file` and parses the JSON command database contained within.

You may only call this function once on an IdeCompileCommands object. If there is a failure, you must create a new IdeCompileCommands instance instead of calling this function again.

See also: `ide_compile_commands_load_async()`

#### Parameters

self | An IdeCompileCommands |
file | a GFile |
cancellable | a GCancellable, or `NULL`. | [nullable]
error | A location for a GError, or `NULL` |

#### Returns

`TRUE` if successful; otherwise `FALSE` and `error` is set.

Since: 3.32

### ide_compile_commands_load_async ()

    void
    ide_compile_commands_load_async (IdeCompileCommands *self,
                                     GFile *file,
                                     GCancellable *cancellable,
                                     GAsyncReadyCallback callback,
                                     gpointer user_data);

Asynchronously loads the contents of the requested `file` and parses the JSON command database contained within.

You may only call this function once on an IdeCompileCommands object. If there is a failure, you must create a new IdeCompileCommands instance instead of calling this function again.

See also: `ide_compile_commands_load_finish()`

#### Parameters

self | An IdeCompileCommands |
file | a GFile |
cancellable | a GCancellable, or `NULL`. | [nullable]
callback | the callback for the async operation |
user_data | user data for `callback` |

Since: 3.32

### ide_compile_commands_load_finish ()

    gboolean
    ide_compile_commands_load_finish (IdeCompileCommands *self,
                                      GAsyncResult *result,
                                      GError **error);

Completes an asynchronous request to `ide_compile_commands_load_async()`.

See also: `ide_compile_commands_load_async()`

#### Parameters

self | An IdeCompileCommands |
result | a GAsyncResult provided to the callback |
error | A location for a GError, or `NULL` |

#### Returns

`TRUE` if the file was loaded successfully; otherwise `FALSE` and `error` is set.

Since: 3.32

### ide_compile_commands_lookup ()

    gchar **
    ide_compile_commands_lookup (IdeCompileCommands *self,
                                 GFile *file,
                                 const gchar * const *system_includes,
                                 GFile **directory,
                                 GError **error);

Locates the commands to compile the `file` requested.

If `directory` is non-NULL, then the directory to run the command from is placed in `directory` .

#### Parameters

self | An IdeCompileCommands |
file | a GFile representing the file to lookup |
system_includes | system include dirs if any |
directory | A location for a GFile, or `NULL`. | [out][optional][transfer full]
error | A location for a GError, or `NULL` |

#### Returns

A string array or `NULL` if there was a failure to locate or parse the command.

[nullable][transfer full]

Since: 3.32

## Types and Values

### IDE_TYPE_COMPILE_COMMANDS

    #define IDE_TYPE_COMPILE_COMMANDS (ide_compile_commands_get_type())

### IdeCompileCommands

    typedef struct _IdeCompileCommands IdeCompileCommands;