... 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>
... 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>
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>
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>
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>
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>
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>
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>
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>
...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>
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>
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>
...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>
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>
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>
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>
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>
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>
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>
In preperation for the language server protocol support.
Change-Id: Iee4ccd53a86d9afdb357972ea62b75ace2edcb1d
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
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>
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>
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>
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>
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>
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>
Allows to use this header without texteditor dependency.
Change-Id: I706f42799c3ea42473a716fa9ef9f3cfbef6fdd4
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
... to reuse this position in backend (instead of
searching the function start again)
Change-Id: I02818dce4fc37ed6e7ecfb533191dbfe60610204
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
We already share same classes there which has nothing to do with IPC and
I want to more for sharing. So we should use a name which fits better.
Change-Id: Idfb12b6de714206117b92634ad719c6a0e290e78
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Correct columns in clang diagnostics and completion
Task-number: QTCREATORBUG-16775
Change-Id: I7260a0e52007fe261e83492dca5d457c34476497
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
For "foo(|" [1] we requested a completion from libclang with the cursor
position just before "foo" and then filtered the function declarations
for functions matching the name "foo". This worked fine for ordinary
functions, but obviously not for constructors and functors.
Recent versions of libclang support proper function call completion with
XCursor_OverloadCandidate, so make use of that.
[1] '|' represents the cursor position
Task-number: QTCREATORBUG-14882
Task-number: QTCREATORBUG-14884
Change-Id: I9d31b3960ccff6a8b9440dbcb7ff9f5ca9f61266
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
To avoid repeating the 'MimeDatabase mdb; mdb.something(); ' mantra
all over the place.
Change-Id: I4bfef62e73275a991455141671d6071162788e9d
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reproduce with:
1. Create a new class named Foo with the wizard.
2. Close foo.h
3. In foo.cpp, add some class member function.
4. In foo.cpp, trigger the refactoring action "Add public Declaration"
for the just defined member function. As a result, foo.h will be
opened.
==> While the declaration was added, the header file is not yet
reparsed with the new content - this can be verified by setting
a custom color for "Function".
In this use case, the refactoring action opens the editor and
immediately modifies the document (RefactoringFile::apply).
Fix by sending the document content along for the very first
RegisterTranslationUnitForEditorMessage if the document was already
modified.
Change-Id: If20615a45b72dd0bef87e1870e403d0b277bc5d6
Reviewed-by: David Schulz <david.schulz@qt.io>
The order is 0 by default and thus the snippet items were at the very
top, e.g.:
enum EnumType { EnumValue };
void f()
{
EnumType et = // Complete here and see snippet items at top
}
Change-Id: I70a160d102b91a2589972354c50aa5f0b29323e8
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
...on the plugin side by removing a left over calculation. We construct
the detail in the virtual ClangAssistProposalItem::detail(), that is, on
demand.
Test:
1. Open src/plugins/clangstaticanalyzer/unit-tests/qt-essential-includes.pro
2. Open main.cpp
3. Complete in the main function
Measured with a timer in IpcReceiver::codeCompleted.
On Linux, for 20637 completion items:
Before: 119ms (avg)
Now: 81ms (avg)
Gain: 32%
Change-Id: I9617cb9651a8367c31cd40e965175b5b37e10730
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>