Commit Graph

70 Commits

Author SHA1 Message Date
Christian Kandeler
b5b9b7e32c ClangCodeModel: Use clangd's include path
... rather than the one from the LLVM that Qt Creator was compiled
against.

Task-number: QTCREATORBUG-27120
Change-Id: I4f211345ed547cd13f0b0774b99bc0f199a9cd44
Reviewed-by: David Schulz <david.schulz@qt.io>
2022-05-10 13:16:09 +00:00
Christian Kandeler
7ef5001076 ClangCodeModel: Speed up compilation db generation
We needlessly re-evaluated the same compiler options again and again for
all files in a project part.
Now we only do the actual file-related work per file. Along the way, we
dissolved some unneeded classes and made CompilerOptionsBuilder non-
polymorphic.

Change-Id: I9710d641a57032936cc0812515974dbc91676c8c
Reviewed-by: David Schulz <david.schulz@qt.io>
2022-05-06 09:05:59 +00:00
Christian Kandeler
4b0b3e9e35 ClangCodeModel: Move fix-it tests into plugin
Change-Id: If53df602a42d8c1ffde5db6c8cb1e7fc269bb272
Reviewed-by: David Schulz <david.schulz@qt.io>
2022-05-04 10:03:47 +00:00
Christian Kandeler
6da7babc4a ClangCodeModel: Remove libclang-based completion and function hints
Change-Id: I742fb14b1aba3ba1f35a5c80bf553d2a735cac48
Reviewed-by: David Schulz <david.schulz@qt.io>
2022-05-02 10:31:05 +00:00
Christian Kandeler
19119b9533 ClangCodeModel: Use more suitable location for compile_commands.json
... for clangd.
Putting it in the build directory seems sensible in principle, but that
can be problematic for in-source builds. So introduce another level of
nesting to prevent conflicts.

Fixes: QTCREATORBUG-26431
Change-Id: Id66aa0852d206695f2fc2ec42292b1cecefe2b59
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-20 09:06:23 +00:00
Christian Kandeler
d583dde17b ClangCodeModel: Force clangd restart on external changes
Neither we nor clangd can afford to watch all source files, which means
that after e.g. a branch switch we can easily end up in an inconsistent
state.
We alleviate this problem by restarting clangd if at least one open file
was changed externally.

Change-Id: I7e0d14835e3afbd7a64c3233614f2161282dddc0
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-09-07 10:05:28 +00:00
Christian Kandeler
284817fae6 Merge CppTools into CppEditor
There was no proper separation of responsibilities between these
plugins. In particular, CppTools had lots of editor-related
functionality, so it's not clear why it was separated out in the first
place.
In fact, for a lot of code, it seemed quite arbitrary where it was put
(just one example: switchHeaderSource() was in CppTools, wheras
switchDeclarationDefinition() was in CppEditor).
Merging the plugins will enable us to get rid of various convoluted
pseudo-abstractions that were only introduced to keep up the artificial
separation.

Change-Id: Iafc3bce625b4794f6d4aa03df6cddc7f2d26716a
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-09-01 14:53:58 +00:00
Christian Kandeler
a952500e90 CppTools: Use only const pointers for ProjectInfo and ProjectPart
All members were already const, but this makes it clear at all points of
use that these data structures are immutable.

Change-Id: Iea615c090bde462c445d15223caccc561b0c713d
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2021-08-27 10:53:54 +00:00
Christian Kandeler
e0e8fda580 ClangCodeModel: Use clangd for completion and function hint
Change-Id: I80160f3a40da18ac178682afe6caba5e5af6e3eb
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-08-23 09:06:31 +00:00
Christian Kandeler
33108795d6 CppTools: Turn some classes into pure value types
ProjectInfo, ProjectPart and ProjectUpdateInfo used to carry pointers
to Project and/or Toolchain, even though they were used in contexts
where these pointers were either unsafe to access or not guaranteed to
be valid anymore, which made their use difficult and error-prone.
We turn these classes into pure value types by copying in all relevant
information before the first async operation takes place.

Fixes: QTCREATORBUG-25678
Change-Id: I1914b0dbda6c7dfba6c95e5e92f2d69977755590
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2021-08-13 12:35:49 +00:00
Christian Kandeler
68846a7729 ClangCodeModel: Provide highlighting via clangd
Note that we lose the highlighting for virtual function calls. We need
to amend clangd to add the respective information to its semantic tokens
message.
Also, Qt properties are no longer highlighted as class members. We'll
investigate how to best restore this feature.

Change-Id: I403712aada3d7a8e1c7b7c1277f43f7f64f8450b
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-07-05 07:39:06 +00:00
Christian Kandeler
673d596c84 ClangCodeModel: Provide tooltips via clangd
Note that we temporarily lose the ability to hover over an include and
get the full path of the header file. This is a valuable feature that we
need to restore, preferably by fixing clangd itself.
Fixing the remaining few test failures would likely require more
complicated code as well as additional LSP round-trips, and as of now
I'm not convinced it is worth the effort.

Change-Id: I08c72c4bd1268bbd67baeb57bbfd29d9b11303a5
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-06-30 08:49:24 +00:00
Christian Kandeler
40181057cd ClangCodeModel: Use clangd for local renaming
Change-Id: I1536265a8d46c9840e722bdfcb8638906d3f45cf
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-06-21 13:00:40 +00:00
Christian Kandeler
898558508d ClangCodeModel: Add test for "follow symbol"
These are the tests from clangbackend, so we are now up to par coverage-
wise.

Change-Id: I7b8a63109bff17745782a646f684fd795f732672
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-06-03 08:15:32 +00:00
Christian Kandeler
6dc3c1f156 ClangCodeModel: Support access type categorization
... with "Find Usages", as we do in the built-in code model.
Note 1: This is very slow, so it's for now only enabled if the
        search results come from a small number of files.
        Possible ways of speeding up the operation
        to be investigated.
Note 2: All test cases from the old code model also pass here,
        but checking with non-trivial real-world projects
        shows a lot of mis-categorizations.
        Well will fix them one by one.
Note 3: This functionality requires clangd >= 13.

Change-Id: Ib3500b52996dbbf9d7d9712d729179bcbd3262fc
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-05-18 08:42:04 +00:00
Christian Kandeler
ecafdb7543 ClangCodeModel: Add experimental clangd support
If the user has enabled clangd (default is off), we start up one instance
per project when it is opened/changed (including build config switches),
and trigger background indexing.
So far, the index is used to provide results for locators and "Find
Usages".
Per-document functionality such as semantic highlighting and completion
is still provided by libclang.

Change-Id: I12532fca1b9c6278baab560e7238cba6189cde9f
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-04-22 07:32:58 +00:00
Eike Ziller
eaefcbd8f0 Use new, more evocative MessageManager API
At various places where semantics doesn't change.

Change-Id: Ib4d4a5c9f067e109126c6de88257f9e198a71447
Reviewed-by: hjk <hjk@qt.io>
2020-12-16 09:30:44 +00:00
hjk
f0628cca29 ClangCodeModel: Replace nested ClangCodeModel::Utils namespace
... by the customary ::Internal.

It adds only noise on the user side and conflicts regularly with
the top-level ::Utils namespace.

Remove a (now) duplicated definition of setLastSentDocumentRevision().

Plus minor namespace related fixes.

There are still minor conflicts between Utils::Text and
ClangCodeModel::Text

Change-Id: I2e8df6b3c6c3599192774032822ee7e778355bba
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2020-07-06 15:12:28 +00:00
hjk
a44bfdd779 Provide an empty default IPlugin::extensionsInitialized()
And remove all empy re-implementations.

Change-Id: I19f0b4e55c042c96693ecb89766f97f0a97b54ae
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2020-02-07 10:21:34 +00:00
hjk
c8137bdcf9 ProjectExplorer: Consolidate some Session::active* accesses
Change-Id: I47b0f6c2c60b2f7c86b6ffd1ad3df393d1321c8b
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2019-11-29 08:39:07 +00:00
hjk
251287f0d3 Avoid warning on empty expressions
For some reason, Q_UNUSED includes already a semicolon, adding one
on the user side creates an additional empty statement.

Change-Id: I9c5e8fac381345a60792cb75e2938fd53958d3b0
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2019-07-23 11:55:59 +00:00
Eike Ziller
10098b2508 Merge remote-tracking branch 'origin/4.10'
Conflicts:
	CMakeLists.txt
	tests/unit/unittest/unittest.pro

Change-Id: I64296ad31502d9b35012da129a28e9277e9fcf8e
2019-06-28 12:50:03 +02:00
Leena Miettinen
26d618024c Clang Code Model: Fix product name capitalization in UI text
Change-Id: I81d7e411d47e64d5304f30ca295c3f4b1f0d51b5
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2019-06-25 06:50:02 +00:00
Marco Bubke
4bae5de36b Enable macro editing for the Clang indexer
Refactor much of the code from Environment* classes to NameValue* classes
to share it with the preprocessor macro settings.

Change-Id: Ica4ee817aa338230c422b30d91240d266248d226
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2019-06-13 16:51:48 +00:00
Eike Ziller
e0b0a08e50 ExtensionSystem: Move away from QList
Qt 6 API will move away from it.
Use QVector for API and some std container for internal things.

Change-Id: Iff14d48a47d5ac52ade875d9c8c84ad8a4f577d8
Reviewed-by: hjk <hjk@qt.io>
2019-05-27 14:21:00 +00:00
Christian Kandeler
3a58c4652e Compilation database: Add information to message pane
We must tell users where we generated the file, and also inform them
about errors.

Change-Id: I6383655e2f731f41b9121b2a6a31bba551d1c1de
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
2019-03-15 09:55:21 +00:00
Ivan Donchevskii
ec9d35f237 CompilationDatabase: Show the progress bar while generating
Change-Id: Ie8df9257f92a9dba110847fda2783c6090a23fdf
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2019-03-15 08:08:08 +00:00
Ivan Donchevskii
d2154e6c40 Clang: Save compilation database to the build directory
For example CMake puts compile_commands.json into the build
directory and it makes sense because it uses some target-specific
command line options.

Change-Id: I92a5b391f35e3f75bbcf41b8efff448f197895bb
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2019-03-14 07:36:38 +00:00
Ivan Donchevskii
5077bf379d Clang: Fix menu button text capitalization
Change-Id: I771cbaebbb801665e96cc3d6ea337ebe15872803
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
2018-08-20 08:26:16 +00:00
Christian Stenger
f6b228842c Clang: Fix possible nullptr access
Change-Id: I8643912f02d127286b0a0ededbaf7d4f23347a5f
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
2018-08-14 06:35:47 +00:00
Ivan Donchevskii
f60b035295 Clang: Add button to generate compile_commands.json
Change-Id: Iaabdcfc8d1b3463c3f6e5ce47536f9c52556eac0
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2018-08-13 13:24:12 +00:00
Nikolai Kosjar
7be7d26814 Clang: Show current editor diagnostics in issues pane
This helps to deal with many diagnostics.

Error diagnostics precede warning diagnostis to have them on top.
If no CppEditor is active, no diagnostics are displayed.

Previously one had to scroll the document up and down to locate the
diagnostics. Now they are in a list and can be easily navigated with
F6/Shift-F6. Also, at least for some diagnostics "Get Help Online" from
the context menu seems to provide useful results. For example,
triggering the action on clang tidy issues will open the web browser
with some good hits explaining the issues.

Change-Id: Idabe30b0961d893bee39ccee431e92aeeda1cc26
Reviewed-by: David Schulz <david.schulz@qt.io>
2018-04-16 09:37:06 +00:00
David Schulz
4322990926 Editor: Simplify text marks
Moving defaultToolTip and color from TextMarkRegistry to TextMark.
Allowing every instance of a TextMark object to define these
information.

Change-Id: Iec1794372cf902b34d343402074e3999e7f9faf7
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2017-06-22 08:42:40 +00:00
Christian Stenger
a2b47b7da2 ClangCodeModel: Fix compile
Change-Id: I648ebd8d898cab3bb121eabf96f2de3d4b28842c
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2017-02-28 11:30:37 +00:00
Nikolai Kosjar
d1133916a9 Clang: Fix release build
* The QtTest include is not available in release builds.
* Make the batch file mode only available in debug/test builds as that
  one uses test utilities that are only available in debug builds.

Change-Id: I441c51ec00b14b81a396ad0199882cf46fff10b0
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-02-28 09:34:55 +00:00
Nikolai Kosjar
ca1d1dfbe2 Clang: Add possibility to "pgo-train" libclang with a batch file
This allows to start Qt Creator in batch processing mode:

  $ export QTC_CLANG_BATCH=/path/to/file
  $ export QT_LOGGING_RULES=qtc.clangcodemodel.batch=true
  $ ./qtcreator -load ClangCodeModel

The batch file will be executed and Qt Creator will exit. Advanced
logging output can be activated as stated above.

Note that it is required that the project was already configured/set up
properly with the used settingspath, otherwise the wrong configuration
will be taken or a pop-up dialog will block the execution.

A small example follows that covers all the understood and so far needed
batch file commands in order to train libclang for profile guided
optimization. ${PWD} expands to the directory of the batch file.

    openProject "${PWD}/calendarwidget.pro"

    # Initial parsing
    openDocument "${PWD}/window.cpp"
    closeAllDocuments
    openDocument "${PWD}/window.cpp"

    # Reparse
    setCursor 478 1
    insertText " "
    insertText " "
    insertText " "

    # Completion
    complete
    complete
    complete

    # Member completion
    insertText "comboBox->"
    complete
    complete
    complete

    # Wait in order to inspect the result
    processEvents 3000

Change-Id: I7dc5dddc6752272ecc2fb4f30497b17cee3f9a9f
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-02-27 13:29:50 +00:00
hjk
3e225628ee Revert "Clang: Add possibility to "pgo-train" libclang with a batch file"
This reverts commit 07f4ae6227,
which broke compilation

clangbatchfileprocessor.cpp:170:27: error: ambiguous overload for
    'operator==' (operand types are 'const QChar' and 'char')

and only worked in QT_TEST=1 cases.

Change-Id: I089427359958221882cb4e4369c4b88d71779acf
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-02-24 16:49:18 +00:00
Nikolai Kosjar
07f4ae6227 Clang: Add possibility to "pgo-train" libclang with a batch file
This allows to start Qt Creator in batch processing mode:

  $ export QTC_CLANG_BATCH=/path/to/file
  $ export QT_LOGGING_RULES=qtc.clangcodemodel.batch=true
  $ ./qtcreator -load ClangCodeModel

The batch file will be executed and Qt Creator will exit. Advanced
logging output can be activated as stated above.

Note that it is required that the project was already configured/set up
properly with the used settingspath, otherwise the wrong configuration
will be taken or a pop-up dialog will block the execution.

A small example follows that covers all the understood and so far needed
batch file commands in order to train libclang for profile guided
optimization. ${PWD} expands to the directory of the batch file.

    openProject "${PWD}/calendarwidget.pro"

    # Initial parsing
    openDocument "${PWD}/window.cpp"
    closeAllDocuments
    openDocument "${PWD}/window.cpp"

    # Reparse
    setCursor 478 1
    insertText " "
    insertText " "
    insertText " "

    # Completion
    complete
    complete
    complete

    # Member completion
    insertText "comboBox->"
    complete
    complete
    complete

    # Wait in order to inspect the result
    processEvents 3000

Change-Id: Ib30526036f999e530f0c01d42a196a1e311e2c4c
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-02-24 11:12:15 +00:00
David Schulz
8b21f687c0 Add default tool tips to text marks
The default tool tip should describe the general purpose
of the mark which is displayed in the UI when no tool tip
is explicitly set for the text mark.

Change-Id: I27aff26cf0f3458d454428e805a9b323191dc393
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2016-08-22 05:40:50 +00:00
hjk
2459652234 ProjectExplorer: Rework mode main window
The existing solution with the special-style horizontal
kit selector comes from a time when there was typically
one, at most four targets. Today's setup can easily
reach half a dozen targets with several toolchain versions
each and can't be sensibly handled with the overflowing
horizontal bar.

This here replaces the horizontal kit selector bar as
well as the top level project "tab bar" with a normal
tree view. All targets are visible (but possibly disabled)
at once, and can be enabled/disabled using the context
menu on the tree items.

Change-Id: I1ce7401ca96109bf34bc8c0ae19d265e5845aa88
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
2016-07-26 10:00:09 +00:00
Nikolai Kosjar
83e18c127c Clang: Introduce warning configuration per project
Change-Id: I5b9a330274e6f72b0786259eb25aa454877d4eef
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@theqtcompany.com>
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2016-03-01 15:55:30 +00:00
Tobias Hunger
397e7f4843 Update License according to agreement with Free Qt Foundation
* Update files in src/plugins

Change-Id: Ia5d77fad7d19d4bb3498e78661982f68729adb22
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
2016-01-19 15:57:01 +00:00
Nikolai Kosjar
f89d3dca8b Clang: Activate code model automatically if plugin is loaded
This removes also the need to close editor documents.

Change-Id: I96c68105bceb37841053f3dbd8a264e059a02cb8
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-12-16 12:23:58 +00:00
Nikolai Kosjar
421046cb7b Clang: Remove left-over project settings
Change-Id: I45a667c0bdd767697766ebe82b65b61253c77f56
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-12-09 17:33:12 +00:00
Nikolai Kosjar
1410bf3faf Clang: Use "clang" prefix plugin files
...for consistency and to avoid future file name clashes.

Change-Id: If595c8debfa1ceb01a1bb0ed34649fa513660503
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-11-30 11:04:07 +00:00
Nikolai Kosjar
5f98b8ec24 Clang: Remove PchManager
...which is the last dependency to libclang from the plugin.

Change-Id: I173ee7e9621912ec88706b4cf62db2b1dbcf7610
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-11-30 11:03:51 +00:00
Nikolai Kosjar
daf9369679 Clang: Remove dead code
Change-Id: Ia36e96424580d9b34000cf4a9b38eab98f9c449c
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-11-30 11:03:04 +00:00
Marco Bubke
7ce9ef9db4 Clang: Integrate highlighting results from backend
Change-Id: I2c3fb69aabfe075bde76d63eafc2ca370f17493c
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-11-26 15:19:27 +00:00
Nikolai Kosjar
48952084a6 Clang: Remove per-mimetype settings
Related to

    commit c47079f97f7d42db0c581525a2ce6fddbc0995f2
    Clang: Activate the code model with a check box

Change-Id: Ief11768ba0dd27788032e2dd3ad9b7ae39a8f52b
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-11-16 14:08:25 +00:00
Nikolai Kosjar
56f37f78b2 Clang: Speed up requesting diagnostics
Register the translation unit and request diagnostics from the
clangbackend as soon as the project part is determined. There is no
reason to wait until the parser is finished for the highlighter.

Change-Id: Iebccbf59ebd205389462dcee97363746fb651bb2
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
2015-11-06 11:55:39 +00:00