Commit Graph

100 Commits

Author SHA1 Message Date
Christian Kandeler
548e19370e CppEditor: Remove CppToolsBridge & friends
This redirection did nothing except to horribly obfuscate the code.
Note that most callers already accessed the model manager directly, and
some bridge functions were not called at all.

Change-Id: Ic1c728afe79bf98544da23a1955ee82d0dbde94f
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-09-06 09:49:36 +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
25ff15a1fb Add convenience functions for creating ProjectExplorer::HeaderPaths
Change-Id: I7b1f63caca6b70ba4ec1b1870b83cbf20aa6564a
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-08-30 10:46:56 +00:00
Kai Köhne
bf04c98c1c Do not pass QStringView by const reference
That's what the documentation says:

  https://doc.qt.io/qt-6/qstringview.html#details

Change-Id: I0b41fc4abad1601c0ed416a505534cf7ae7633e1
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2021-06-17 09:54:42 +00:00
Christian Kandeler
d9e5d079be ClangCodeModel: Relax completion result filtering
... in connect() calls.
The logic was: If we are in a place where a signal is expected and there
are signals among the completion results, then we should consider only
signals.
However, in e.g. a member function of a QObject subclass, there are
always signals in scope, even when we expect a class name. So we need to
allow class names as well.
Amends a79b0c6558.

Fixes: QTCREATORBUG-25153
Change-Id: Id3bbaaf4f8eefefe36cfc91e5959d3ef5ad28071
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-01-26 15:55:41 +00:00
Christian Kandeler
f697a0d46c ClangCodeModel: Fix sorting of includes when auto-completing
... by treating the directory separator specially.

Fixes: QTCREATORBUG-21490
Change-Id: Iad6f51f39516a88bd14ba1eddcf2c6656490ee5b
Reviewed-by: David Schulz <david.schulz@qt.io>
2020-11-20 08:43:41 +00:00
Eike Ziller
830a829b2e Fix build of Clang code model and CppEditor with Qt 6
QStringRef gone.
QSharedPointer is no longer auto-converted to bool.
Small things.

Task-number: QTCREATORBUG-24098
Change-Id: I3a2a55459b905118d1ca81ec015d741ab273471d
Reviewed-by: hjk <hjk@qt.io>
2020-09-21 07:21:48 +00:00
David Schulz
dba4bff703 TextEditor: use Utils::FilePath as file member in AssistInterface
Change-Id: I3bf9b013b9350411f918efdb9d1a36a2c22bf972
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2020-09-04 10:14:21 +00:00
Christian Kandeler
a79b0c6558 C++: Offer only signals when completing in a connect() call
... at the second argument.
The logic is as follows: The clang code model checks whether the set of
completions contains any signals. If so, it instructs the built-in code
model to analyze the AST to find out whether the completion location was
at the second argument of a call to QObject::connect(). In that case, we
filter out all non-signals, because they are not valid at that location.

Fixes: QTCREATORBUG-13558
Change-Id: I9c7d0bd16161c723aef822280626cd06ece7df93
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-08-27 14:02:51 +00:00
Christian Kandeler
760d91665f TextEditor: Make threshold for automatic completion configurable
Fixes: QTCREATORBUG-19920
Change-Id: Id6be79485b1fb8c2ab4cce2706816949ae5e217b
Reviewed-by: David Schulz <david.schulz@qt.io>
2020-08-13 13:49:44 +00:00
Christian Kandeler
7938320291 TextEditor: Introduce shortcut for forcing a function hint proposal
... and support it in the ClangCodeModel.
This allows users to get function signature(s) displayed regardless of
where exactly the cursor is on the function call.

Fixes: QTCREATORBUG-19394
Change-Id: I033e8774db93680bfc3ee52610b817e0ef8ccc76
Reviewed-by: David Schulz <david.schulz@qt.io>
2020-08-11 10:10:08 +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
Christian Kandeler
ca3ad20e64 ClangCodeModel: Do not offer completion for inaccessible symbols
We should not offer to auto-complete e.g. private members from contexts
where they cannot legally be accessed. This is also consistent with the
existing behavior of not offering non-const members on const objects.

Fixes: QTCREATORBUG-1984
Change-Id: Ic58c1ba2dc0b8023299feebc20bec4f2a5a6ea38
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2020-06-05 11:06:46 +00:00
Nikolai Kosjar
a35832385c Clang: Fix crash after cancelled completion request
Amends

  commit 755de9f86a
  Editor: delete processor after canceling

Ensure to update the bookkeeping in BackendReceiver on

  CodeAssistantPrivate::cancelCurrentRequest()

as otherwise we run into a use-after-free.

Change-Id: Ic5abdc9d743dc0b76eb050a9e3e00f85d2c5bc96
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
2020-05-19 09:37:43 +00:00
David Schulz
1f37eaa265 Editor: Fix crash in codeassist
We have to report back to the code assistant even if we have no results.
Otherwise the processors aren't correctly reset and may be called after
deletion.

Change-Id: Id7af2e0ee9f631efc00beb2a84bfe1824e138d24
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-02-26 08:18:58 +00:00
hjk
7ab6783e24 Standardize on int for line and column values
Recently tons of warnings show up for presumably "problematic"
singned <-> unsigned and size conversions.

The Qt side uses 'int', and that's the biggest 'integration surface'
for us, so instead of establishing some internal boundary between
signed and unsigned areas, push that boundary out of creator core code,
and use 'int' everywhere.

Because it reduces friction further, also do it in libcplusplus.

Change-Id: I84f3b79852c8029713e7ea6f133ffb9ef7030a70
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2019-07-26 09:23:48 +00:00
Ivan Donchevskii
0852f889d1 Clang: Do not show global completions after comma
Handle the case when we try to show the function hint but
do not find any completion. Do not fall back to the normal
code completion in such case.

Fixes: QTCREATORBUG-21624
Change-Id: I147d71b8970c18d49947f68786347a9db97736bb
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2019-03-11 11:33:22 +00:00
Eike Ziller
eeaa02bc27 Merge remote-tracking branch 'origin/4.8' into 4.9
Conflicts:
	src/plugins/android/androidbuildapkstep.cpp

Change-Id: Id6dfda480c23706089ab38aa6277cd37599b5167
2019-02-28 12:39:09 +01:00
Ivan Donchevskii
97e1bc28d2 Clang: Do not assume that one of the overloads always has parameters
Fixes: QTCREATORBUG-21841
Change-Id: I5d4fc5d10cdf38d124e84952862b9aaf66888c88
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2019-02-22 08:05:52 +00:00
Nikolai Kosjar
99a7f7ec00 Clang: Fix/silence some coverty issues
clangcompletionassistprocessor.cpp: 136
CID 1475671:  Possible Control flow issues  (DEADCODE)
  Execution cannot reach the expression "codeCompletion.completionKind
  != ClangBackEnd::CodeCompletion::SlotCompletionKind" inside this
  statement: "if (slotCompletion && codeC...".

clangbackendcommunicator.cpp: 272
CID 1475649:  Null pointer dereferences  (NULL_RETURNS)
  Dereferencing a pointer that might be null "document" when calling
  "contents". (The dereference happens because this is a virtual
  function call.)

clangutils.cpp: 335
CID 1475678:  Error handling issues  (CHECKED_RETURN)
  Calling "open" without checking return value (as is done elsewhere 144
  out of 158 times).

codecompletionsextractor.cpp: 48
CID 1475676:  Uninitialized members  (UNINIT_CTOR)
  Non-static class member field
  "currentCxCodeCompleteResult.CompletionString" is not initialized in
  this constructor nor in any functions that it calls.

Change-Id: I4c8767ee6e824ba1c42d2f8914ad66dc95ac6717
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2018-12-04 15:01:51 +00:00
Eike Ziller
3d1d9aae2e Merge remote-tracking branch 'origin/4.8'
Conflicts:
	src/plugins/winrt/winrtdevicefactory.cpp

Change-Id: I33b8697e2ebf2bea051d7f1144449e0743ee16a5
2018-11-19 10:00:18 +01:00
Alessandro Portale
62abfd7b50 ClangCodeModel: Modernize
modernize-use-nullptr
modernize-use-auto
modernize-use-override
modernize-use-equals-default
modernize-use-using

Change-Id: I386f885860c01574035c69226240fe3b8e38392c
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2018-11-14 08:09:15 +00:00
Ivan Donchevskii
41d68f469a Clang: Change dot <-> arrow if all completions require it
Return the behavior that existed before completion fix-its
were introduced. Apply it only for the cases when all
items require the fix-it.

Fixes: QTCREATORBUG-21367
Change-Id: Idc358255135f72353f3fd3204b653fc2fc55e7a0
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2018-11-13 08:17:19 +00:00
Nikolai Kosjar
d946ff5403 Clang: Fix adding completion snippets after {
...e.g. as in "void f() {".

The criteria whether to change snippets got invalidated with

    commit 8d0391a4f9
    Clang: Treat brace initialization as constructor completion

as the completion operator might be T_LBRACE now instead of T_EOF_SYMBOL
for normal completions.

This fixes the plugin test ClangCodeCompletionTest::testCompleteGlobals.

Add also unit tests.

Change-Id: I85cf522b9b307359c5c3e25198dd228cbb68ded0
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
2018-10-25 12:13:57 +00:00
Ivan Donchevskii
039a34a369 Clang: Adapt priorities for the same method/constructor overloads
CXXMethod and CXXConstructor may have different priorities
depending ony their origin and attributes. To keep them together
in the sorted list we adapt their priorities to have the same
value if their names match.
To continue keeping ClassCompletion before ConstructorCompletion
change the order of the completion kinds for the sort purposes.

Change-Id: I36efe5d5dbaa77d604a54b1dafe07d67f44db4c9
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2018-10-25 07:10:12 +00:00
Ivan Donchevskii
3f613d25a1 Clang: Move text cursor utility methods into ClangCodeModel
These 3 are only used in ClangCodeModel.

Change-Id: Id7c2cead40473bcb746e4b105aa36cb7d51a2740
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2018-10-18 09:13:35 +00:00
Ivan Donchevskii
239c15b5e2 Fixes: Clang: Sort the initial list of includes for the code completion
Task-number: QTCREATORBUG-6242
Change-Id: Icdd5671801079a547a08b1276a6dbc76fed4bd30
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2018-10-17 08:09:59 +00:00
Ivan Donchevskii
3858c7d3b9 Clang: Fix the crash in function overload completion
Check that the completions container is not empty.

Change-Id: I399b8cce42995d758013441d2d3d9f3d8156dc06
Reviewed-by: hjk <hjk@qt.io>
2018-10-05 13:57:09 +00:00
Ivan Donchevskii
efc39304a1 Clang: Move the majority of completion items sorting to ClangBackend
With this change ClangCodeModel only needs to sort completions by prefix.

Also some other optimization have become possible and are implemented here:
1. Getting completions after '{' for constructor overloads by replacing
   it with '(' inside usaved file.
2. Checking for all overloads requires only previous item check because
   all Class completions are already sorted to go before all CXXConstructor
   completions. Since they are not mixed no extra search is required.

Change-Id: Ie0187ad96a20857a63c1d71ddec74606b803f572
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2018-10-02 12:29:23 +00:00
Nikolai Kosjar
aa290912b8 Clang: Remove project tracking on clangbackend side
...as it is not needed. Just provide the compilation arguments as part
of the Document.

As a side effect, re-initializing the backend after a crash is cheaper
and will not freeze the UI anymore (referenced bug).

Task-number: QTCREATORBUG-21097
Change-Id: I866e25ef1fd5e4d318df16612a7564469e6baa11
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
2018-09-26 10:45:41 +00:00
Tobias Hunger
c763d4d787 ProjectExplorer: Remove HeaderPath::isFrameworkPath
None of the other types has a query function, so remove this one, too.

Change-Id: I936d162e092c8f9361b0e3bb86676e68905d2f4b
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2018-09-13 11:32:59 +00:00
Tobias Hunger
1df553a683 ProjectExplorer: Rename IncludePathType to HeaderPathType
It is the type used by the HeaderPath class, so reflect that in
the name.

I also considered to rename HeaderPath to IncludePath, but
that name is reflected in a lot of users, which would also need
to be adjusted for consistency. That would blow up the patch size
for little value IMHO.

Change-Id: I51421dbd3ab8b2874dc32fc82dc394c9b93ce5e9
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2018-09-13 11:32:31 +00:00
Marco Bubke
3abaf647d0 Add system include path to HeaderPath and merge ProjectPartHeaderPath
System include paths are appended after other includes by the compiler. So
we should set them as system includes and not as normal includes. Otherwise
we change the include order. Headers in system include paths are not
cluttering the screen with unwanted warning and by the way improve
performance too.

ProjectPartHeaderPath was a dopperganger of HeaderPath, so we merged them.

Change-Id: I7c394b4098b697de79761499ffcd5913cc02d652
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2018-09-10 09:31:32 +00:00
Ivan Donchevskii
8b6a16c95b Clang: Fix completion after '{'
Follow-up fix for 8d0391a4f9.

Do not complete after '{' coming not after an identifier.
Take constructor completions only for '{' and function
completions only for '('. Filter constructor completions by
class/struct type.

Task-number: QTCREATORBUG-21004
Change-Id: I7ae2d6bee23cf907648c42b93eb12742942833f6
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2018-08-30 13:36:52 +00:00
Ivan Donchevskii
4a6ad6c849 Clang: Do not replace class completion with constructor completion
Both completion kinds have the same name. Do not merge them
together when looking for constructor overloads.

Task-number: QTCREATORBUG-21010
Change-Id: I4c851033d63ad4e242b6179491f1fba00af466f6
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-08-29 11:54:34 +00:00
Ivan Donchevskii
8d0391a4f9 Clang: Treat brace initialization as constructor completion
Try to complete constructor after left brace with fallback
to normal completion.

Task-number: QTCREATORBUG-20957
Change-Id: I6c33790a3ee1e623a3d8abe9a44cfd821b6f3106
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2018-08-21 10:40:04 +00:00
David Schulz
141f19a652 Utils: move code model icons to utils
In preperation for the language server protocol support.

Change-Id: Iee4ccd53a86d9afdb357972ea62b75ace2edcb1d
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
2018-08-06 13:22:47 +00:00
Ivan Donchevskii
843f31ae04 Clang: Better handle constructor overloads
Follow up for 0f96f735f0. Constructors have worse support
in Clang for their definitions but have proper overloads
for the references.

Change-Id: Ie002ae74b0d15f0fe00126042a7f61172b82946b
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2018-08-06 10:38:34 +00:00
Ivan Donchevskii
0f96f735f0 Clang: Provide all overloads for function definition completion
When we complete a function definition with the parameter list
it is important to have multiple entries to select.

Change-Id: I25e94b58cfe4831387d66eecdec74712addb7ec5
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2018-08-02 12:47:17 +00:00
Ivan Donchevskii
da4be3fdb7 Clang: Use new libclang code completion fix-its feature
Each completion coming from libclang now has it's own
list of fix-its which are required to be applied before
completion itself.

This saves one extra reparse cycle and gives an ability
to provide both kinds of completion (initial and corrected
one) for cases like shared_ptr, unique_ptr or any other
class with overloaded arrow operator.

Each of these extra fix-its is applied together with
corresponding completion dircetly before completion itself.

Change-Id: Ide37e45bb15fa2f1375cd6b86ecd43ced3593046
Reviewed-by: David Schulz <david.schulz@qt.io>
2018-07-27 07:34:44 +00:00
Nikolai Kosjar
f01fbcb789 Clang: Clean up some IPC names
This is long overdue since some names were simply wrong and/or
misleading. Also, some of the old names were long enough to almost get
crazy.

The renaming starts from ClangCodeModelServerInterface and
ClangCodeModelClientInterface and affects usages and related functions.

For the ClangCodeModelServerInterface, categorize the messages in
 - messages that require a response (request*)
 - notification messages (the remaining ones)

Change-Id: I5342ed8e0d87404ee72f3c3766fd8ef7505defb1
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
2018-06-04 09:54:01 +00:00
David Schulz
20e67865ea CodeAssist: Store processor state in specialized objects
Change-Id: I19de64b948599c833496ab8caabf3eaafc845658
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2018-04-19 05:52:21 +00:00
Orgad Shaneh
eea6a7c3b3 Utils: Purge qtcfallthrough.h
No longer needed.

Change-Id: I9b0bee014df89d4c567f1d2431b5ff9404f5f925
Reviewed-by: hjk <hjk@qt.io>
2018-04-09 09:04:13 +00:00
hjk
cf4dbb4bb6 ClangSupport: Use simpler structures in some cases
The patch is mostly mechanical, but contains also a few spurious changes
from values references for some local variables, foreach -> ranged for
etc that I coulnd't resist.

Change-Id: I58f0bd972546895eb318607cbfbd7ac35caf3f23
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
2018-04-06 12:55:23 +00:00
David Schulz
a4b5fc00a8 CodeAssist: use shared pointer to pass around proposal models
Task-number: QTCREATORBUG-17752
Change-Id: Ia41f169b86ead209830e6f15764062389ced2b67
Reviewed-by: hjk <hjk@qt.io>
2018-02-27 12:32:36 +00:00
Ivan Donchevskii
eb1f85a971 Clang: simplify column convertion calls
Pass QTextBlock directly into clangColumn call.

Change-Id: I3410a82ed9a84da66e7b430e2aefce64ec459db8
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2018-02-01 14:14:15 +00:00
Ivan Donchevskii
fbbdfd2444 Clang: Add commentary about column convertion
... to/from utf8 byte offset used by Clang.

Change-Id: I294d6cd61b416e5f2d64206ee2f3f1b4a91fb1d3
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2018-02-01 12:22:45 +00:00
Ivan Donchevskii
09310bcdc6 Clang: fix utf8 related column numbers
Use new clang_getFileContents to efficiently convert
utf8 byte offsets from line start to column numbers.
Also provide simplier backwards convertion to pass
resulting utf8 offset to clang.

Task-number: QTCREATORBUG-16941
Change-Id: If0e58fe01ad3e281b7e952e972b9e86f6e75aadb
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2018-01-26 15:39:31 +00:00
Friedemann Kleint
f482270432 Introduce Q_FALLTHROUGH()
Silence g++ 7.X warnings.

Change-Id: I9d06d04b496c9ec060e13e1be6f43d8fbadb1f3b
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2018-01-24 14:50:43 +00:00
Nikolai Kosjar
917592970d Clang: Extract and rename backend classes
IpcCommunicator -> BackendCommunicator
IpcSender -> BackendSender
IpcReceiver -> BackendReceiver

Change-Id: I110ebe8d185db7ff47d2d5de9b786262520926d0
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-09-28 12:45:31 +00:00