// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

// **********************************************************************
// NOTE: the sections are not ordered by their logical order to avoid
// reshuffling the file each time the index order changes (i.e., often).
// Run the fixnavi.pl script to adjust the links to the index order.
// **********************************************************************

/*!
    \page creator-clang-codemodel.html
    \previouspage creator-reference.html

    \ingroup creator-reference-editors

    \title Clang code model

    \brief Offers code editing services for C++.

    The \e {code model} is the part of an IDE that understands the language you
    are using to write your application. It is the framework that allows \QC
    to offer the following services:

    \list

        \li \l{Complete code}{Code completion}

        \li Syntactic and \l{Semantic Highlighting}{semantic highlighting}

        \li Navigating in the code by using the \l{Navigate with locator}
            {locator}, \l{Move to symbol definition or declaration}
            {following symbols}, and so on

        \li Inspecting code by using the \l{Class View}{class browser}, the
            \l{Outline}{outline}, and so on

        \li Diagnostics

        \li \l{View function tooltips}{Tooltips}

        \li \l{Find symbols}{Finding symbols}

        \li \l{Rename symbols}{Renaming symbols}

        \li \l{Apply quick fixes}{Quick fixes}

    \endlist

    The Clang code model plugin offers some of these services
    for C++ on top of \l{What is clangd}{Clangd}.

    \section1 About the Clang code model

    The Clang project has libraries for parsing
    C language family source files. The feedback you get through warning and
    error markers is the same as a compiler will give you, not an incomplete
    set or a close approximation, as when using the built-in \QC code model.
    Clang focuses on detailed information for diagnostics, which is really
    useful if the code has typos, for example.
    We make use of these libraries via the clangd tool, which implements
    an \l{Language Server Protocol}{LSP} server.

    Clang keeps up with the development of the C++ language. At the time of this
    writing, it supports C++98/03, C++11, C++14, C++17, C89, C99, Objective-C,
    and Objective-C++.

    On the downside, for large projects using Clang as code model is slower than
    using the built-in code model. Clang does not need to generate object files,
    but it still needs to parse and analyze the source files. For small projects
    that only use STL, this is relatively fast. But for larger projects that
    include several files, processing a single file and all the included files
    can take a while.

    The Clang code model plugin now offers some of the same services as the
    built-in C/C++ code model:

    \list

        \li Code completion
        \li Syntactic and semantic highlighting
        \li \l{Clang Checks}{Diagnostics}
        \li Outline of symbols
        \li Tooltips
        \li Following symbols
        \li Renaming symbols
        \li Finding occurrences of symbols

    \endlist

    To use the built-in code model instead, select \preferences >
    \uicontrol C++ > \uicontrol clangd, and clear \uicontrol {Use clangd}.
    This setting also exists on the project level, so that you can have the Clang-based
    services generally enabled, but switch them off for certain projects, or vice versa.

    You can configure Clang diagnostics for:

    \list
        \li \l{Clang Checks}{Clang code model} (globally or at project level)
        \li \l{Configure Clang diagnostics}{Clang tools} (globally or at project
            level)
    \endlist

    \section1 Clangd indexing

    The clangd \e index provides exact and complete results for services such
    as finding references, following symbols under cursor, and using the
    locator, even for complex constructs. When you \l{Open projects}
    {open a project}, clangd scans the source files to generate the index. For
    large projects, this can take a while, but the index is persistent and
    re-scanning is incremental, so nothing is lost by closing and re-starting
    \QC.

    To temporarily disable global indexing, select
    \uicontrol {Toggle Progress Details} (1), and then select \uicontrol X on
    the progress bar.

    \image {qtcreator-toggle-progress-bar.webp} {Toggle Progress Details}

    By default, \QC runs one clangd process per project. If you have created
    \l{Manage sessions}{sessions} that have related projects, you can
    specify that the projects in the session should be managed by a single
    clangd process.

    The document outline in the \l{Outline} view is backed by clangd's document
    symbol support, which makes the results more reliable than before.

    \sa {Configure C++ code model}, {Specify clangd settings},
    {Specify Clang tools settings}, {Use compilation databases},
    {Code Model}, {Clangd}
*/

/*!
    \page creator-how-to-cpp-code-model.html
    \previouspage creator-how-tos.html

    \ingroup creator-how-to-configure-editors
    \ingroup creator-how-to-projects-configure

    \title Configure C++ code model

    The code model offers services such as code completion, syntactic and
    semantic highlighting, and diagnostics.

    To configure the C++ code model for a project:

    \list 1
        \li Go to \uicontrol Projects > \uicontrol {Project Settings} >
            \uicontrol {C++ Code Model}.
            \image {qtcreator-projects-cpp-code-model.webp} {C++ Code Model settings}
        \li Clear \uicontrol {Use global settings}.
        \li Set \uicontrol {C++ Code Model} settings for the project.
    \endlist

    \sa {Code Model}
*/

/*!
    \page creator-preferences-cpp-code-model.html
    \previouspage creator-reference.html

    \ingroup creator-reference-editors

    \title Code Model

    \brief Sets global preferences for the C++ code model.

    The code model offers services such as code completion, syntactic and
    semantic highlighting, and diagnostics.

    To configure the C++ code model globally, go to \preferences >
    \uicontrol C++ > \uicontrol {Code Model}.

    \image {qtcreator-preferences-code-model.webp} {Code Model tab in C++ preferences}

    The following table summarizes the preferences.

    \table
    \header
        \li Setting
        \li Value
    \row
        \li \uicontrol {Interpret ambiguous headers as C headers}
        \li Instructs the code model to interpret ambiguous header files as C
            language files. Select this checkbox if you develop mainly using C.
    \row
        \li \uicontrol {Ignore precompiled headers}
        \li Clear this checkbox to process precompiled headers.
    \row
        \li \uicontrol {Use built-in preprocessor to show pre-processed files}
        \li Uses the built-in preprocessor to show the
            pre-processed source file in the editor.
    \row
        \li \uicontrol {Enable indexing}
        \li Turns on the built-in indexer. Clearing this checkbox severely limits
            the capabilities of the code model.
    \row
        \li \uicontrol {Do not index files greater than}
        \li To avoid out-of-memory crashes caused by indexing huge source files
            that are typically auto-generated by scripts or code, the size of
            files to index is limited to 5MB by default.

            To index all files, clear the checkbox.
    \row
        \li \uicontrol {Ignore files}
        \li To ignore files that match wildcard patterns, enter each wildcard
            pattern on a separate line in the field.
    \endtable

    \section1 Inspect preprocessed C++ code

    To analyze the causes of compile errors or errors caused by wrong includes
    pulled in by dependencies or C++ macros expanding to something unexpected,
    select \uicontrol {Show Preprocessed Source} in the editor context menu.

    This action expands all C++ macros to their actual code and removes code that
    is guarded by a currently inactive \c {#ifdef} statements.

    If you clear \uicontrol {Use built-in preprocessor to show pre-processed files},
    this action also expands all \c {"#include <foo.h>"} statements to their
    actual contents.

    \sa {Configure C++ code model}, {Specify clangd settings},
    {Clang code model}, {Clangd}
*/

/*!
    \page creator-preferences-cpp-clangd.html
    \previouspage creator-reference.html

    \ingroup creator-reference-editors

    \title Clangd

    \brief Sets global preferences for the clangd code model.

    The Clang project has libraries for parsing C language family source files
    and providing you with detailed diagnostics. The clangd \e index provides
    exact and complete results for services such as code completion.

    To set preferences for clangd, go to \preferences > \uicontrol C++ >
    \uicontrol Clangd and select \uicontrol {Use clangd}.

    \image {qtcreator-preferences-clangd.webp} {Clangd tab in C++ preferences}

    The following table describes the available preferences.

    \table
    \header
        \li Preference
        \li Description
    \row
        \li \uicontrol {Path to executable}
        \li Specify the path to clangd version 14, or later.
    \row
        \li \uicontrol {Background indexing}
        \li Select \uicontrol Off to use a faster, but less accurate built-in
            indexer. Set the indexing priority based on whether accuracy or
            speed is more important to you during global symbol searches.
    \row
        \li \uicontrol {Per-project index location}
        \li Specify the folder to store the index files for each project. The
            \c {compile-commands.json} file is also stored here.
    \row
        \li \uicontrol {Per-session index location}
        \li Specify the folder to store the index files for each session.
    \row
        \li \uicontrol {Header/source switch mode}
        \li Select the C/C++ backend for switching between header and source
            files. \uicontrol {Try Both} uses clangd if the built-in code
            model does not find anything.
    \row
        \li \uicontrol {Worker thread count}
        \li Set a fixed number of cores to use. By default, clangd uses all
            unused cores.
    \row
        \li \uicontrol {Insert header files on completion}
        \li Insert header files when completing symbols.
    \row
        \li \uicontrol {Update dependent sources}
        \li Re-parse all source files that include a header file when editing
            it. Clear this option to only re-parse when saving the header file.
    \row
        \li \uicontrol {Completion results}
        \li Maximum number of completion results. Set to 0 to remove the limit.
    \row
        \li \uicontrol {Completion ranking model}
        \li Select the clangd model for ranking completion suggestions.
            \uicontrol {Decision Forest} (default) uses machine learning.
            \uicontrol Heuristic is hand-crafted.
    \row
        \li \uicontrol {Document update threshold}
        \li Time \QC waits before sending document changes to the server.
    \row
        \li \uicontrol {Ignore files greater than}
        \li Maximum size of files to parse. Enable to make parsing faster.
    \row
        \li \uicontrol {Diagnostic configuration}
        \li Clang checks to perform. Select to edit the checks.
    \row
        \li \uicontrol {Sessions with a Single Clangd Instance}
        \li Add sessions that should use a single clangd process for indexing.
    \endtable

    \section1 Clang checks

    Select the value of the \uicontrol {Diagnostic configuration} field to open
    the \uicontrol {Diagnostic Configurations} dialog, where you can select and
    edit the checks to perform.

    \image {qtcreator-clang-diagnostic-configurations.webp} {Diagnostic Configurations dialog}

    In addition to using the built-in checks, you can select \uicontrol Copy to
    create copies of them and edit the copies to fit your needs.

    \list
        \li \uicontrol {Build-system warnings} shows warnings as specified
            by the build system.
        \li \uicontrol {Checks for questionable constructs} combines the \c -Wall
            and \c -Wextra checks for easily avoidable questionable constructions
            and some additional issues.
    \endlist

    Clang checks begin with \c -W. Each check also has a negative version that
    begins with \c -Wno.

    Keep in mind that some options turn on other options. For more information,
    see \l{Options to Request or Suppress Warnings} or the GCC or Clang manual pages.

    \sa {Specify clangd settings}, {Clang code model}, {Code Model}
*/

/*!
    \page creator-how-to-override-clangd-preferences.html
    \previouspage creator-how-tos.html

    \ingroup creator-how-to-projects-configure

    \title Specify clangd settings

    To set clangd preferences for the current project:

    \list 1
        \li Select \uicontrol Projects > \uicontrol {Project Settings} >
            \uicontrol {Clangd}.
            \image {qtcreator-projects-settings-clangd.webp} {Clangd preferences for a project}
        \li Clear \uicontrol {Use global settings}.
        \li Select \uicontrol {Use clangd}.
        \li Specify \uicontrol Clangd preferences for the project.
    \endlist

    \sa {Clang code model}, {Clangd}, {Code Model}
*/
