Commit Graph

97 Commits

Author SHA1 Message Date
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
Christian Kandeler
221eb6def0 ClangCodeModel: Add infrastructure for collecting timing data
... and use it for highlighting with clangd.

Change-Id: Ib082c0b80593a2115f9cc19ee8279b17187e9309
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-05 09:12:54 +00:00
Christian Kandeler
545da2f6a6 ClangCodeModel: Improve collection of highlighting info from AST
... with clangd.
- Turn function with lots of lambdas into a class.
- Traverse the AST without repeatedly modifying a list in a tight loop.

Change-Id: I46668a4df672c00cbd7b1a562ae94a6db4cbd2fc
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-05 09:11:45 +00:00
Christian Kandeler
2fcd764d56 ClangCodeModel: Add clangd-based document locator filter
Change-Id: I2811be80e740cacf57eccd19e47560af746ad0c1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-04 15:40:49 +00:00
Christian Kandeler
ec7c60cd67 ClangCodeModel: Do not report non-type template parameters as types
... with clangd.

Change-Id: I9edad375eacc6c33a833c88da64dc29f79334157
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-10-01 11:40:08 +00:00
Christian Kandeler
29c0512416 ClangCodeModel: Do not use clangd for completing #ifdef & friends
Annoyingly, LLVM does not complete preprocessor directives in disabled
code, so that we would not offer e.g. "#endif" after "#if 0" (but we
would offer it after "#if 1").
Fixing it would require messing with the clang libs (rather than just
clangd), so let's just keep using our existing code, which seems to work
fine.

Change-Id: I9dabf9a2a8f3a2f68e88a11b62c3df3b5e64a55c
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-09-29 09:31:33 +00:00
Christian Kandeler
94a59f15c6 ClangCodeModel: Replace a TODO item with a version check
Change-Id: I22911b5bc5da3e905d1f31ac1bb19251058a5471
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-09-29 09:30:49 +00:00
Eike Ziller
45e23e07a8 Fix build on macOS
Amends 901a96231c

Change-Id: I4ebc961bed63a9f5a8fc3a997d0c861d779d0c11
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-09-29 08:12:07 +00:00
David Schulz
23a58a320e clangd: introduce ClangdCompletionItem
allowing to overwrite apply and get rid of the apply helper in the
LanguageClient completion provider and processor.

Change-Id: I066fe10b116d638bd1b7a81d4488840bec5f0b63
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-09-29 04:41:06 +00:00
Christian Kandeler
e7eeb5ae34 ClangCodeModel: Use namespace TextEditor in clangdclient.cpp
Less noise.

Change-Id: Ia7ec9c6cbe93868826828379ded2d039f6fa3a44
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-09-28 13:12:04 +00:00
Christian Kandeler
901a96231c ClangCodeModel: Cache clangd's AST
Since we use the AST in several contexts, it can easily happen that we
need to consult it more than once for the same document revision.
Therefore, it makes sense to cache the AST to prevent redundant requests
for potentially large amounts of data.

Change-Id: I33100e0052ee21bb46e91848d3d2e8a0a96bb860
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-09-28 11:34:25 +00:00
Christian Kandeler
03f6de1eeb ClangCodeModel: Properly mark "#ifdefed-out" blocks with clangd
The behavior is now the same as when using libclang. Namely:
    - The whole block is grayed out, rather than just symbols
      having a gray background.
    - Ifdefed-out blocks no longer mess with the brace depth.

Change-Id: I8b5f3a788430edcd9dd79249323c26a5ee5d68ed
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-09-28 10:23:03 +00:00
David Schulz
e7f6abc084 LanguageClient: remove codeassist proposal handler
Removes noise from the interface. Using specialized clangd processors
that redirect the proposals for testing purposes is an overall cleaner
solution.

Change-Id: Ia4f3d4720765f0533c5530a2a5c7db3cc971e0be
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-09-28 09:50:46 +00:00
Christian Kandeler
be6ea67bfd ClangCodeModel: Replace TODO items with links to upstream bug reports
Change-Id: Iff1ccf77aca74bc34e2944996e7ef2eb2fcb3bad
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-09-28 08:22:49 +00:00
Christian Kandeler
b35630c03d ClangCodeModel: Highlight "override" and "final" with clangd
Change-Id: If30de546ce360ab9bc3cfa2780f61d6a78e4191d
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2021-09-27 15:03:50 +00:00
Christian Kandeler
553f4bec7e ClangCodeModel: Remove inapplicable TODO item
It's not worth the extra effort to restrict the identifier <-> file name
check to data types: There is hardly any possibility for a completely
false positive, as local variables do not pass through this code path.

Change-Id: Ia92549c8c6723e520789a2ad820a2606620d4efe
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-09-24 11:41:07 +00:00
Christian Kandeler
eefc8cbc7d ClangCodeModel: Remove inapplicable TODO item
I don't see any explicit sorting of the references in clangd, so let's
continue to not rely on that.

Change-Id: I65269af4995ab851e49f52686a10cc96697fbe64
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-09-24 11:40:49 +00:00
Christian Kandeler
b10641caa2 ClangCodeModel: Adapt clangd test to upstream change
See https://reviews.llvm.org/D110324.

Change-Id: I9dbc03dd814392939be28d1943515d581f9f5b58
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-09-24 08:42:21 +00:00
Christian Kandeler
15b6eaa47b ClangCodeModel: Switch off clang-tidy in clangd
We have our own dedicated clang-tidy support, so let's not confuse
users.

Change-Id: I69a32de3ac96ad2c51d70c82a9eb62f811e65460
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-09-21 13:24:32 +00:00
David Schulz
cb5eaf4a63 Clangd: remove unused member
Change-Id: Idd95245a6c5b0db37ca30966cb509fc75a4901e3
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-09-17 12:44:22 +00:00
David Schulz
07cfae77ba Clangd: fix opening document with client for project
Using LanguageClientManager::openDocumentWithClient function to assign a
document to a specific server. This function also takes care of
deactivating the document for the old client and opens it if necessary
in the new client.

Fixes: QTCREATORBUG-26205
Change-Id: Idbff154a62d12c432a2cb10d547f78a537e63a3c
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-09-17 12:00:32 +00:00
David Schulz
17b05bc3e8 Clangd: Create correct code assist processor in provider
... for the context of the code assist instead of using a callback from
the text editor.

Change-Id: I636b1b267a944895d4ff732e3c0a8811332ec14f
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-09-17 12:00:18 +00:00
Christian Kandeler
56f9d17d35 ClangCodeModel: Fix an instance of mis-highlighting with clangd
In the expression x.f(), x was wrongly categorized as an output
parameter if f was a static function.

Change-Id: I9167f98916963cdaa4b5ac6ead2c86fab43ad02e
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-09-17 08:48:52 +00:00
Christian Kandeler
ad23d86b41 ClangCodeModel: Make use of clangd's non-const ref parameter tagging
clangd 14 will tag non-const reference parameters for us (https://
reviews.llvm.org/D108320), so let's make use of that at least as a
shortcut.

Change-Id: I0162b5d7b9fecc3e6ce0338e896980cd5b363ceb
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-09-16 09:09:51 +00:00
Christian Kandeler
bcfe229f8b ClangCodeModel: Get document symbols immediately
... when doing a decl/def switch via clangd.
The delay is fine for e.g. populating the outline, but shouldn't be used
when dealing with explicit user requests.

Change-Id: I0350ed6daf8220ec3b702a3876fbf0f726da8a67
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-09-16 09:09:27 +00:00
David Schulz
4324f3e8c1 Editor: pass AssistInterface to createProcessor
The interface can be used for checking the context of a codeassist
request to determine
the correct processor that has to be created.

Change-Id: I47ddb05c46399566e27bae21711f11a3a4132c3f
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-09-16 08:25:36 +00:00
Christian Kandeler
719f51445e ClangCodeModel: Use dedicated completion assist provider for clangd
The pure LSP-based implementation is too inflexible with regards to
activation characters.

Change-Id: I386a60b80f59e1b48254d55c2a47f1a1ffe1f97f
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-09-14 09:11:33 +00:00
Eike Ziller
3d4d7c7e14 Merge remote-tracking branch 'origin/5.0'
Conflicts:
	src/plugins/clangtools/clangtoolssettings.cpp
	src/plugins/clangtools/executableinfo.cpp
	src/plugins/clangtools/executableinfo.h

Change-Id: Id8caf63e3e594792467d3447870086bd2d8f73b9
2021-09-13 17:03:55 +02:00
David Schulz
04763a307d Clangd: prevent adding refactorings for outdated documents
Change-Id: I658662dca345e1ae209a4d74e145b59c44417b00
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-09-09 11:46:12 +00:00
Christian Kandeler
1b723f6fd9 CppEditor: Remove unneeded CppEditorWidgetInterface
Removes a pseudo-abstraction and simplifies ClangdClient.

Change-Id: I5161d069371ff92a517866bb7500517cab6781b7
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-09-07 11:16:47 +00:00
Christian Kandeler
4504570447 ClangCodeModel: Fix access type categorization with clangd
... in "Find References".
This was broken in d6acd21fc0.

Change-Id: I0a185a8440bd5260b7cc18a87cefb450be71e77f
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-09-07 10:06:06 +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
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
Eike Ziller
94d352ab28 Merge remote-tracking branch 'origin/5.0'
Conflicts:
	src/plugins/autotest/testresultdelegate.cpp

Change-Id: If172206f231fc2a9f4a672cd2e6eaeaea4988c96
2021-08-18 16:14:24 +02:00
Christian Kandeler
49b0026826 ClangCodeModel: Adapt clangd tooltip test for include directives
This feature was recently added upstream
(https://reviews.llvm.org/D107137).

Change-Id: I022855cd5d69230b755cdd657c5a7df2db5508ce
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-08-18 12:10:34 +00:00
David Schulz
fdd3b03ba9 clangd: add setting for document update timeout
Change-Id: I4fae2cdff022f6f29566c0316a8ade51d3482466
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-08-16 07:48:22 +00:00