Commit Graph

275 Commits

Author SHA1 Message Date
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
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
David Schulz
dc87947cb3 ClangD: skip automatic code action request
.. after receiving diagnostics since the code actions are already
inlined into the diagnostics.

Change-Id: I11ed1270344ff5119dd111503d173eef2f340c1d
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-08-11 10:34:17 +00:00
Christian Kandeler
11da66f768 ClangCodeModel: Adapt to new "virtual" modifier
... in clangd's semantic tokens.
See https://reviews.llvm.org/D107145.

Change-Id: Idf9fe327df3fb806697ab5b806e89bb62d43e706
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-08-05 15:00:42 +00:00
Christian Stenger
f0bc9036f8 ClangD: Fix possible access violation
Change-Id: I6b54dcdb42f9f9e2c3a9fd686146d253dcdfa40c
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-08-03 11:43:39 +00:00
Christian Kandeler
d6acd21fc0 ClangCodeModel: Get search term for "Find References" from clangd
QTextCursor's understanding of a "word" does not always correspond to
what will actually be searched for (e.g. "operator+").
By doing a symbol info request first, we make sure that the string
displayed to the user in the search widget is really what clangd is
searching for.

Change-Id: I8be6e6122e5ed76334c4e6fc5b41debed96b6a40
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-08-03 11:16:33 +00:00
Christian Kandeler
c999b6066f ClangCodeModel: Start a fallback clangd for files without a project
These were still being served by the old code model even when clangd
support was enabled.

Change-Id: I5f01b6a7071b90c374750f93435299755cabe3e9
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-07-29 11:33:45 +00:00
Christian Kandeler
42fe70b93e ClangdClient: Fix possible crash
Fixes: QTCREATORBUG-26018
Change-Id: Ib93d6067950b548f6d437bb06cc9f11a8246e105
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-07-19 13:11:33 +00:00
Christian Kandeler
34a1971ede Clangd: Allow more fine-grained logging
Change-Id: Ia882575a3b6babd0945ef60be08b152428d3f39d
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-07-16 08:18:30 +00:00
Christian Kandeler
d603654aca ClangdClient: Do not close temporarily opened files
... if they have been properly opened in the meantime.
This fixes the problem that when a file was opened indirectly via "Go to
definition", the didClose message for the file that we temporarily opened
to search for overrides sometimes came in after the "regular" opening of
the file. As a result, such files were not actually in clangd's open
documents set, and no functionality was available for them (e.g. F2 on a
symbol would do nothing).
Also remove a left-over related declaration.

Change-Id: I9fc85d95595cb38a8d92e3f46505b9c514537d21
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-07-12 12:49:30 +00:00
Christian Kandeler
792699be06 ClangdClient: Do not send document update requests
... when requesting extra data from clangd.

Change-Id: I3552a2b7e09a1947de6570352936fd45e95f37a2
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-07-09 11:24:57 +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
c0a44be27b ClangCodeModel: Provide outline via clangd
Note that we used to encode the information about symbol visibility and
static-ness in the icons, which we can't do anymore, because clangd does
not provide this information.
On the upside, this change likely fixes a ton of bugs, as our own outline
was rather "quirky".

Change-Id: I099f11ec4e3c6f52cd461fb43080bbdde3bed5e5
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-07-01 08:36:20 +00:00
Christian Kandeler
f4a3310059 Clangd: Handle settings changes
Users no longer have to re-load a project for settings changes to take
effect.

Change-Id: I86dccccac14a30514c8dac292c7765ee4806f6ba
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-07-01 08:34:51 +00:00
Christian Kandeler
fbb804c442 Clangd: Add per-project settings
Users might want to use clangd for certain project, but not for others.

Change-Id: Id29ce3349f0acd359cf7c824ece073b147ed2280
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-06-30 15:09:56 +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
4e777fcf90 Clangd: Make "Follow Symbol" more robust
The AST is only needed for virtual function disambiguation, while the
basic functionality works fine without it. So in case clangd fails to
retrieve the AST node for some reason, just use the original "go to
definition" result.
This also makes "Follow Symbol" work with clangd < 12.

Change-Id: I2c110e9a51b01dc912fcdf6f4ed45fce766df374
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-06-29 12:50:33 +00:00
Christian Kandeler
117fa35e00 Clangd: Ensure open document for "Send Goto Implementation" requests
Fixes: QTCREATORBUG-25861
Change-Id: Ied14b3ad129b205b05653a40c249a0a339ab686a
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-06-29 08:37:06 +00:00
Christian Kandeler
7bf52b0c0d ClangCodeModel: Provide diagnostics via clangd
Change-Id: Ib45a62ebe200c2b56a1bb1a66f8a92103e60d092
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-06-28 13:22:36 +00:00
Christian Kandeler
56cddf38b3 Clangd: Let users limit the worker thread count
This is particularly interesting for indexing, where users might prefer
a slower-building index with less CPU load.

Change-Id: Id44c58e9041df2857cd0772e71345673b14623f3
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-06-28 10:35:33 +00:00
Christian Kandeler
876cd8e975 Clangd: Allow to switch off background indexing
It is conceivable that users don't want to spend the extra CPU time on
this.

Change-Id: Ic3611c8d17d201ae986fad08b344369a8728ce1b
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-06-28 10:35:06 +00:00
Christian Kandeler
ba138a1855 CppTools: Add dedicated settings and settings page for clangd
We plan to add more clangd settings, and it makes sense to have a
dedicated place for them both in the code and the UI.

Change-Id: Ideb92935b7a5a6a98e07980f4011736fb82042d1
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-06-28 10:34:24 +00:00
David Schulz
b6367b6359 Core: use FilePaths to notify files changed internally
Change-Id: I2fce65ad340f18292fc0286233e78aaf769a130d
Reviewed-by: hjk <hjk@qt.io>
2021-06-23 12:03:10 +00:00