Commit Graph

245 Commits

Author SHA1 Message Date
Christian Kandeler
cfc7890416 ClangCodeModel: Create a clangd config file, if none exists yet
There are some clangd settings that can only be provided via a config file
(i.e. neither via the command line nor via LSP extensions).
In addition, clangd is very picky about that file's location; in
particular, we cannot put it at the "pseudo project root" where our
generated compilation database resides.
Therefore, we have to go with a user config file (as we don't want to
write into any project source directories). If there already is such a
file, we don't do anything, based on the assumption that the user is
familiar with clangd and has already configured it to their liking.
Otherwise, we create the file, including a special marker that tells us
it was generated by us and can safely be overwritten.
The set of options we set is currently quite small, but we expect it to
grow in the future.

Change-Id: I1605bf7b0edecc844f3e7cdd1d7dddda7af33956
Reviewed-by: David Schulz <david.schulz@qt.io>
2022-02-04 14:23:46 +00:00
Christian Kandeler
0e7de92319 ClangCodeModel: Retrieve all kinds of clangd tweaks
Contrary to our expectation, the "quickfix" tweaks are not part of the
inline code actions after all.
User-observable effect: "Populate switch" becomes available.
Amends 8b63dfccc6.

Change-Id: I4f7fa25a58bb54dbdb470d7db064b4d804c34d26
Reviewed-by: David Schulz <david.schulz@qt.io>
2022-02-04 14:23:24 +00:00
Christian Kandeler
92156cc1d6 LanguageClient: Indent code coming from the server
... if the client implementation requests it.
The server is not necessarily aware of our indentation style, so we
might have to apply it to the newly inserted code.

Change-Id: I43518575c7124568da42be3b04a28d7f352f6dc2
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
2022-02-03 14:30:19 +00:00
Christian Kandeler
8b63dfccc6 ClangCodeModel: Make clangd refactoring actions available
Introduce an assist processor that merges our built-in quickfixes with
refactoring actions from clangd ("tweaks").
For now, we make it clear which ones are coming from clangd, and we do
not filter duplicate functionality. In the future, we might want to
disable redundant built-in actions if clangd is enabled for the
respective file.

Change-Id: I04842132798c8635dfddf8cfc98cc7a6313fac09
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: David Schulz <david.schulz@qt.io>
2022-02-01 11:02:53 +00:00
Christian Kandeler
abe09bfd76 ClangCodeModel: Adjust cursor for following destructor symbols
... with clangd. More specifically, for the case where we switch between
declaration and definition of a destructor. Since clangd expects the
cursor before the "~" character, we move it there.

Fixes: QTCREATORBUG-26809
Change-Id: I8ea6a060bea3545c963cb8ebbe2d3ae3a18da2d5
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2022-01-28 12:34:48 +00:00
Christian Kandeler
cfae24a6e5 ClangCodeModel: Enable clangd's new "dirty headers" flag, if possible
This feature will be availabe with LLVM 14,
see https://reviews.llvm.org/D95046.

Task-number: QTCREATORBUG-26810
Change-Id: I0a6797a836c56f5b72cca34be8f2d3edf8ac7359
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2022-01-24 12:46:29 +00:00
Eike Ziller
7d92375b2f Merge remote-tracking branch 'origin/6.0'
Conflicts:
	cmake/QtCreatorIDEBranding.cmake
	qbs/modules/qtc/qtc.qbs
	qtcreator_ide_branding.pri
	src/plugins/clangcodemodel/clangdclient.cpp

Change-Id: I75c954d2e573d65089205d2542747bba3276be2a
2022-01-03 14:14:12 +01:00
Christian Kandeler
3cf51b0cc7 ClangCodeModel: Fix build with MSVC 2022
Change-Id: Ifd0e1e67057e57e4c978784e9634f987edb9dfe4
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-12-17 19:03:28 +00:00
Eike Ziller
85b60d9608 Merge remote-tracking branch 'origin/6.0'
Conflicts:
	src/plugins/coreplugin/editormanager/editormanager.cpp

Change-Id: I80fe565749ad5c06dfe99436f2dc6ab4b66a2537
2021-12-16 10:50:33 +01:00
Christian Kandeler
bbd4352188 ClangCodeModel: Fix flaky clangd completion test
Change-Id: I38e283146d43a9ce6e9cb07dfc5b0e9ea7eb2a76
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-12-13 09:34:12 +00:00
Christian Kandeler
5f15e1f066 ClangCodeModel: Relax check for const-ness
... when detecting output arguments with clangd.
This should lead to fewer false positives. We plan to handle false
negatives on a case-by-case basis (rather than the other way around).

Change-Id: I541b418927dc410c2ea4ea9f6c1b5a7bd291a1a8
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-12-10 08:40:34 +00:00
Christian Kandeler
fc3b7f7ac5 ClangCodeModel: Fix access type categorization for functions
... with clangd.
The code is starting to look rather hacky and might need to be rewritten
completely at some point. Let's see how far we get with it.

Change-Id: I506dd410831970b9f9291b005129b4d70f397de0
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-12-10 08:39:57 +00:00
Christian Kandeler
92e3eb722a ClangCodeModel: Another clangd cursor adjustment
This time for the case where we are after the last character of a
function call argument.

Fixes: QTCREATORBUG-26638
Change-Id: I634fa91e87103a7ae82e3a43246dfbc7069dbbdc
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2021-12-07 16:08:28 +00:00
Christian Kandeler
7ffaa89f02 ClangCodeModel: Work around clangd cursor issue, part 2
Amends 825c9ea64f to work also for member access via pointer.

Change-Id: I8ee68d0f6d93c65c2f82a63bce5baef2aa2159de
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-12-07 14:00:18 +00:00
David Schulz
7552c9958f TextEditor: move setIfdefedOutBlocks to TextDocument
The location of the blocks to marked ifdefed out are not tied to a
specific editor instance, but just depend on the document content.

Change-Id: I837730dc00e1d6060dd46bbb2cfccbfa5f72e6ce
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-12-06 05:17:51 +00:00
Christian Kandeler
825c9ea64f ClangCodeModel: Work around clangd cursor issue
If the cursor is right before the "." in a member access expression,
clangd interprets it as belonging to the member instead of the base
expression, which leads to unexpected behavior.
Work around this by sending a cursor position one to the left of the
real one to clangd in such cases.

Change-Id: I429ee9189760ccb02d231acfcb94ab6cfde3cd8d
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-12-03 11:17:17 +00:00
Christian Kandeler
0f9aa307a3 ClangCodeModel: Highlight Q_PROPERTY declarations with clangd
We re-use the moc parser for this purpose.

Change-Id: Ib0ef4f727d1f0b862a202a95a3ae9c551cb502a5
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-12-03 10:10:10 +00:00
Christian Kandeler
b2d63bf79e Fix various compiler warnings
Change-Id: Ib64f04f154b2c44dad3248ef038449c2ac628686
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2021-12-02 15:48:52 +00:00
Eike Ziller
d62d0f305b Merge remote-tracking branch 'origin/6.0'
Change-Id: I71b19dd8ecd96a7a2a58622f68283b8635264e48
2021-12-01 09:24:05 +01:00
Christian Kandeler
1f2e25dd48 ClangCodeModel: Tighten the check for ambiguous calls
... when doing "Follow Symbol" with clangd. Not every call to a virtual
function is ambiguous.
Amends 4fe5be2565.

Change-Id: I7c31644510ca85d430a3e18b2ccad97548f71d54
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-11-25 09:29:13 +00:00
hjk
56009b8b15 Merge remote-tracking branch 'origin/6.0'
Change-Id: I0eae76ecff1a315877e4fdd471f0de3a3a55f180
2021-11-24 11:37:12 +01:00
Christian Kandeler
153dd2fe0b ClangCodeModel: Fix overly simplistic check
... when doing function call completion with clangd.
We did not take default arguments into account. E.g. the following
declaration:
    void func(int i, int j = int());
was mis-detected as taking no arguments, causing to the cursor to be at
the wrong location afterwards.

Change-Id: I522921721b0cb347ed593c43ed285ca6d02ccfee
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-11-24 10:00:20 +00:00
Christian Kandeler
7498b5523a ClangCodeModel: Fix another mis-highlighting with clangd
Output parameter marking strikes again.

Change-Id: Id98e07e87824a9db435d09482235d56c6808d42e
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-11-23 16:43:37 +00:00
Christian Kandeler
c53e3f4893 ClangCodeModel: Treat function-like macros like functions
... when completing with clangd.

Change-Id: I8ffc0ff7a4a0f819f2ae48aabbb16609eb178178
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-11-23 16:42:23 +00:00
hjk
4de74a67ee Merge remote-tracking branch 'origin/6.0'
Change-Id: I773141d47e3f2b773da51f2e26ef53b93bb28f90
2021-11-22 13:18:08 +01:00
Christian Kandeler
f4070c4b43 ClangCodeModel: Do not report symbol references from non-existing files
... which we get from clangd's textDocument/references.
This works around https://github.com/clangd/clangd/issues/935.

Fixes: QTCREATORBUG-26574
Change-Id: I3933f30fdaca024a6e240bd0962de3d97acd0dbf
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-11-22 09:56:59 +00:00
Eike Ziller
eba4115b82 Merge remote-tracking branch 'origin/6.0'
Change-Id: I3bab4e31bc5993c59c7025ebde0846bf6c75810e
2021-11-19 10:44:15 +01:00
Christian Kandeler
037d2b3889 ClangCodeModel: Fix clangd highlighting of string literals
... passed to macros defined in a different file.
This amends e77e57420a. Contrary to our expectation, it is possible that
AST nodes that are marked as belonging (only) to a header file can
contain child nodes that belong to the main file.

Fixes: QTCREATORBUG-26553
Change-Id: I4d1d877d8e1e2dcf7d81b63aa98e1149b5514e3f
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-11-17 14:46:37 +00:00
Christian Kandeler
03e6351c0e ClangCodeModel: Provide clangd memory usage in language inspector
Change-Id: I8a87cb5f267571584b2eecac06be65b841592c7a
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-11-17 13:43:59 +00:00
Christian Kandeler
5769dbe0aa ClangCodeModel: Force clangd re-highlighting on font settings change
Change-Id: Ie449a5329bd49eac116751e66a07602f316e147d
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-11-15 14:35:02 +00:00
Christian Kandeler
95e8afabba ClangCodeModel: Handle UI header updates with clangd
We need to manually refresh the documents that include the generated
header, as clangd does not know about it.

Change-Id: I8c4303ac029bbb56c01aa99b7950dcc651701678
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-11-12 14:37:51 +00:00
Christian Kandeler
0c60370f3e ClangCodeModel: Fix Qt header completion with clangd < 14
The problem is fixed upstream, but this must work now.

Fixes: QTCREATORBUG-26482
Change-Id: I3b2e863efec0edf7eaa74d73eb94705aa28723cf
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2021-11-11 13:15:11 +00:00
Christian Kandeler
084dced9be ClangCodeModel: Provide signal/slot icons for clangd completions
Fixes: QTCREATORBUG-26555
Change-Id: I3b647f6fdbeed69bc453d64a69fb57731d92231e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-11-11 10:09:12 +00:00
Christian Kandeler
af647841cf ClangCodeModel: Fix erroneous marking of lambda parameter
... as output argument when using clangd.

Change-Id: I35ef2da235cb317bb7eb1f08b865ea62c27d3b76
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-11-11 09:27:08 +00:00
Christian Kandeler
397cbd77ab ClangCodeModel: Fix highlighting problem with template types
With clangd, we mis-detected variables of template types as output
parameters in certain contexts.

Change-Id: I906abd489f987351793f4ef676e4af59cdfdbf97
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-11-10 09:04:52 +00:00
Christian Kandeler
35e57ca748 ClangCodeModel: Make sure not to overwrite macros with their expansion
... when highlighting with clangd.

Change-Id: I89ec8bf5a1ed4d43e0e9a398b26705df00ca9a46
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-11-08 13:55:15 +00:00
Christian Kandeler
a6a1423421 ClangCodeModel: Fix assertion in clangd timing logger
Change-Id: If5134e5160b8278b2d0ef7037a00abe3b4b035ad
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-11-04 13:24:47 +00:00
David Schulz
4d55fc911d clangd: disable lsp snippets
We have some additional handling with the completion items that might
interfere with the snippets.

Change-Id: I86405ec67af189d01c8a4dfa468f56035e6e69c4
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-11-04 12:07:18 +00:00
Christian Kandeler
4022043792 ClangCodeModel: Ignore redundant semantic tokens
This can now happen due to the newly implemented refresh support.

Change-Id: If64feede84b044140f7ec04e317289d3f493aa53
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-11-04 09:54:02 +00:00
Christian Kandeler
33b5fa25a8 ClangCodeModel: Do not mark the LHS of assignments as output parameters
... when using clangd. Amends a1f088376a.

Change-Id: Ief442d978e1cf3027dcba5a3c75b66c0f4ae8809
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-11-04 09:20:30 +00:00
Christian Kandeler
bcebf65bb1 ClangCodeModel: Make sure clangd sends all results
... for textDocument/references. The --limit-results option was recently
split up; we have to set --limit-references as well now.

Change-Id: I979aa21a11a08e829b6e843c0c135098aac7d3f5
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-11-01 14:19:46 +00:00
David Schulz
a2cb1edb69 clangd: assert on starting client for project that already has a client
Change-Id: Ia50662063f7f7bdc26e5a842f7c25af4f4f4efdf
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-11-01 12:56:48 +00:00
Christian Kandeler
6e5ec9a939 ClangCodeModel: Prevent indexing with fallback client
There is no project to index.

Change-Id: I6d3ad2f894a45e2a7934cfb3c10c525299bfd34b
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-11-01 09:38:31 +00:00
Christian Kandeler
4fe5be2565 ClangCodeModel: Try harder to find out whether a function is virtual
... when following symbols with clangd.
The textdocument/implementation request is expensive, so we'd like to
make sure we only run it if we are sure that we're really dealing with a
virtual function. We re-use the information gathered during highlighting
for this purpose.

Change-Id: Id92a9a92fe2ac7fd5acf903a9ade711223ee401b
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-11-01 09:38:13 +00:00
Christian Kandeler
c3a1193969 TextEditor: Add highlighting category for namespaces
... and make use of it in the built-in code model and with clangd.

Task-number: QTCREATORBUG-16580
Change-Id: I8c331f56aa1bbf91c9f768be82a779a72f40c4c7
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-29 08:36:20 +00:00
Christian Kandeler
1311244832 ClangCodeModel: Do not always consult clangd for the symbol name
... when doing "find usages".
The symbol info request follows typedefs, which will result in confusing
search window contents. So do the symbol info request only if the cursor
is not on a normal identifier.

Change-Id: I0d3bd8bfd47879c59e6656a4da73344406c97a21
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-28 11:27:12 +00:00
Christian Kandeler
d8d4739bc4 TextEditor: Allow special highlighting for static members
Task-number: QTCREATORBUG-9659
Change-Id: Idae529fd876ba5f555c76e4d282efc9263263d6c
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-28 10:04:57 +00:00
Christian Kandeler
a1f088376a ClangCodeModel: Mark output arguments also for lambdas
... with clangd.
This required rewriting getAstPath(), because the previous
implementation did not do the necessary backtracking and could therefore
miss the AST branch containing the node fully matching the input range.

Task-number: QTCREATORBUG-22381
Change-Id: Id5caf2a401b920c0e76f742bec97b5ca6977b4df
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-27 11:22:52 +00:00
Christian Kandeler
2ecbbb126d ClangCodeModel: Do not let clangd insert header files on completion
... by default.
This feature often doesn't do what you'd want it to, so we make it opt-
in.

Change-Id: I631eae9c154ddcb0e8feeac44c5d5c0265706a67
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-27 10:17:39 +00:00
Christian Kandeler
6f26a1545c ClangCodeModel: Check doc revision when highlighting with clangd
Change-Id: I981d375e3656e89bb66516218e3f4e33ee8bbb9e
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-25 08:45:07 +00:00