Commit Graph

133 Commits

Author SHA1 Message Date
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
Christian Kandeler
e77e57420a ClangCodeModel: Check for AST nodes from foreign files
... when highlighting with clangd. This can happen due to macro
invocations or unusually placed includes.

Task-number: QTCREATORBUG-26396
Change-Id: I471faee13c62fa511bdedfdd5b864327e858f6b8
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-19 09:11:36 +00:00
Christian Kandeler
097efa58ba ClangCodeModel: Add some clangd completion logging
Change-Id: I35dea3ad2815683181eb5dfbe1ea7d985037f55c
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-15 12:39:12 +00:00
Christian Kandeler
40f863b9cf LanguageClient: Allow to log to console rather than message window
And make use of that in ClangdClient.
When I get a slowdown while typing, it is usually accompanied by the
clangd message "Request cancelled because the document was modified"
occurring in the message window, often many times in a row. I'd like to
find out whether writing to the message window itself is a contributing
factor to the slowdown.

Change-Id: Iff7c459af0aed27d22366b9aade573f51eb5dbc7
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-15 09:26:37 +00:00
Christian Kandeler
fe4a033a44 ClangCodeModel: Improve completion with clangd
Namely, do not duplicate parts of the to-be-completed item (including
parentheses) that already exist at the cursor position.
The code is taken from ClangAssistProposalItem; I had left it off in the
original implementation, because I mistakenly assumed that clangd would
handle this situation itself.

Change-Id: I216f5d507a54db90cd23af2fadb26060dbc4a735
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-15 07:55:22 +00:00
Christian Kandeler
c4256a9a2b CppEditor: Squash three copies of the "is in comment or string" check
Change-Id: Id6c4e35ae2d3b3031e5c95ea04f5b971bef58389
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-15 07:54:51 +00:00
Christian Kandeler
9234bc369b ClangCodeModel: Fix highlighting of user-defined string literals
... with clangd.

Task-number: QTCREATORBUG-26425
Change-Id: I805ed5a68a990528ef20dcac015591a2a600066b
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-15 07:54:28 +00:00
Christian Kandeler
d9dd3612da ClangCodeModel: Fix QStringView crashes
Some AST nodes have no range, triggering crashes in QStringView::mid().
Rather than checking all callers, we just use a safe variant.

Change-Id: I3c8d388693f9161249f201ecd4e8bad933463960
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-14 09:39:08 +00:00
Christian Kandeler
ce34ffdc21 ClangCodeModel: Do not trigger snippets
... in strings or comments with clangd.

Change-Id: Ic16e94051018e91f273fafe2ec90d5395e4cc07a
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-11 08:48:28 +00:00
Christian Kandeler
a40b7867f6 ClangCodeModel: Optimize getAstPath()
Profiling has shown that this function is a hotspot. Luckily, it can be
easily sped up by taking advantage of the fact that the AST nodes are
(mostly) sorted by range, allowing us to employ a binary search when
looking for a given range.

Change-Id: I950c150543ff68b975d36c6fb652d366b93ea3b2
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-11 08:46:52 +00:00
Christian Kandeler
cd453a5c67 ClangCodeModel: Refer to clangd for the AST node under the cursor
The question which concrete AST node corresponds to a given cursor
position is surprisingly difficult to answer, and clangd already has a lot
of code for this. Therefore, we always refer to clangd to get a concrete
node, even if we already have the full AST.

Change-Id: I5d1528d776ee459a53b8e650a616ea7019ec59bf
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-07 09:36:49 +00:00
Christian Kandeler
25a7f30ffc ClangCodeModel: Do not hold highlighters by value in ClangdClient
Semantic highlighter objects are owned by their respective documents, so
we can run into destruction issues when keeping them by value.

Fixes: QTCREATORBUG-26364
Change-Id: Idc128d685ccdd25989dd9389d352453ccc935fa9
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2021-10-06 12:03:08 +00:00
Christian Kandeler
372b0c9b7e ClangCodeModel: Handle clangd's semantic tokens in parallel
This speeds up semantic highlighting considerably.

Change-Id: I1dca2c8d6b9e41ac2895a53b795466a3249f79bc
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-06 09:45:26 +00:00