Commit Graph

75 Commits

Author SHA1 Message Date
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
Ivan Donchevskii
80a472740d TextEditor: move convenience from texteditor to utils
Allows to use this header without texteditor dependency.

Change-Id: I706f42799c3ea42473a716fa9ef9f3cfbef6fdd4
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2017-09-22 12:59:35 +00:00
Ivan Donchevskii
d809e3fb8f Clang: send function name position for completion
... to reuse this position in backend (instead of
searching the function start again)

Change-Id: I02818dce4fc37ed6e7ecfb533191dbfe60610204
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2017-09-08 07:37:06 +00:00
Marco Bubke
7c0331ab93 Clang: Rename library clangbackendipc to clangsupport
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>
2017-08-29 16:36:35 +00:00
Nikolai Kosjar
415d3c4784 Clang: Fix cursor position after completion of overloads
struct Foo {
    void begin();
    void begin() const;
};

void c(Foo &foo)
{
    foo.beg // complete to foo.begin()| instead of foo.begin(|)
}

Task-number: QTCREATORBUG-17443
Change-Id: I60ca16bbfeeb75c5c37a0d5bc6f46e9e9913b86e
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2017-08-14 12:51:15 +00:00
Ivan Donchevskii
707170ca04 Clang: make workaround for multibyte utf8
Correct columns in clang diagnostics and completion

Task-number: QTCREATORBUG-16775
Change-Id: I7260a0e52007fe261e83492dca5d457c34476497
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2017-05-22 13:28:36 +00:00
Nikolai Kosjar
64ec695566 Clang: Show function signature hint for constructors and functors
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>
2017-05-11 11:54:09 +00:00
hjk
3f5caf4cdc Utils: Wrap MimeDatabase into static functions
To avoid repeating the 'MimeDatabase mdb; mdb.something(); ' mantra
all over the place.

Change-Id: I4bfef62e73275a991455141671d6071162788e9d
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2017-03-03 07:57:54 +00:00
Nikolai Kosjar
6cf1f7968f Clang: Fix initial document parse with modified content
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>
2016-11-23 11:50:39 +00:00
Nikolai Kosjar
14428c1586 Clang: Decrease order of snippets
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>
2016-07-28 14:42:30 +00:00
Nikolai Kosjar
0651eddbad Clang: Stop needless completion detail calculation
...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>
2016-07-26 06:13:59 +00:00
Nikolai Kosjar
a1749f9a14 Clang: Fix dot-arrow-correction for zero results
If there are no completion items, do not add snippets since these will
otherwise pop-up at undesired positions, e.g. when:

 1) Typing float/doubles: 0.
 2) Typing file suffix in include directives: #include "stdio.

Task-number: QTCREATORBUG-16188
Change-Id: Ie1c29826dc62dc447b2ff57b0c5537eb9d9511ef
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
2016-06-24 07:29:27 +00:00
Alessandro Portale
984a6eca73 cplusplus: Make functions of Icons static
This avoids multiple instatiations and reloading of the same image files.

Change-Id: I4d0bb955e23c1cb817671c25bff4e74fb7b3d0f4
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
2016-04-06 08:48:32 +00:00
Nikolai Kosjar
334e3edd18 C++: Extract base startOfOperator()
...in order to remove some duplication.

Change-Id: Ie974b6ed9418967ad80b4604088b0e1c293b59d0
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
2016-03-31 09:30:37 +00:00
Nikolai Kosjar
4b3a987c39 C++: Equalize startOfOperator()
There are two versions of startOfOperator:
    * InternalCppCompletionAssistProcessor::startOfOperator
    * ClangCompletionAssistProcessor::startOfOperator

The latter started as a copy of the former, but the former got some bug
fixes in the meantime.  Adjust both versions to each other, so it's easy
to diff them and to extract the duplication in a follow-up change.

Change-Id: Icf48386bf1ad0fa473bec476c5412be9b1890139
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
2016-03-31 08:01:58 +00:00
Nikolai Kosjar
4de62a7349 C++: Fix completion for doxygen tags I
There are three cases that must be handled:

 1. Completion in C++ style comment
 2. Completion in first line of a C style comment
 3. Completion in non-first line of a C style comment

This change fixes case 1 + 2. Case 3 will be addressed in a follow-up
change, same goes for the duplication.

Task-number: QTCREATORBUG-15143
Change-Id: I449711f965ddcbbe6158870a8a5ae33218e0d238
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
2016-03-31 06:51:34 +00:00
Marco Bubke
07e8edb4fe Clang: Remove ClangEditorDocumentProcessor from ClangCompletionAssistProcessor
Change-Id: I15b0124b980b0df974cc4405b5834919659d6834
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2016-02-02 11:56:06 +00:00
Marco Bubke
ecca269292 Clang: Add ClangPreprocessorAssistProposalItem
Change-Id: Ifb27b9a21b9a2fe9a04496bbb70fa3fa07d1f89c
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2016-02-01 14:38:31 +00:00
Marco Bubke
bb3b7307ef Clang: ClangAssistProposalItem is now inheriting AssistProposalItemInterface
Change-Id: I781ba27659e852782292596fe590666b09d7253e
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2016-02-01 14:01:44 +00:00
Marco Bubke
c903f4974f TextEditor: Introduce AssistProposalItemInterface
For unit test we need to break every dependency to the TextEditor
Widget etc.. With an abstract interface we can implement it in clang
without relying on unwanted dependencies. It makes it also easier to
compute the values deferred.

Change-Id: I1b313a1625f4e80bd324ab4bf1a7c4f6b690abe9
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2016-02-01 14:01:35 +00:00
Tobias Hunger
397e7f4843 Update License according to agreement with Free Qt Foundation
* Update files in src/plugins

Change-Id: Ia5d77fad7d19d4bb3498e78661982f68729adb22
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
2016-01-19 15:57:01 +00:00
Eike Ziller
98257617e9 Merge remote-tracking branch 'origin/3.6'
Conflicts:
	src/plugins/clangcodemodel/clangassistproposalmodel.cpp
	src/plugins/clangcodemodel/clangassistproposalmodel.h

Change-Id: Iba30d2f4d95fa0f551afe58890d15f5835dfb715
2016-01-19 16:41:17 +01:00
Nikolai Kosjar
2324db9d41 Clang: Fix html code in completion list item
E.g. "dynamic_cast&lt&gt;()" showed up as item.

Let CompletionChunksToTextConverter default to plain text format and
explicitly request HTML where needed.

Change-Id: Iebce85cb888a5bd697ffdce364118b6dc65a435d
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2016-01-19 13:37:06 +00:00
Nikolai Kosjar
8d6549fa74 Clang: Correct member access operator if possible
1 struct Foo { int member; };
 2 void f(Foo *foo)
 3 {
 4     foo.<REQUEST COMPLETION> // correct '.' to '->' and provide results
 5 }

The preferred approach would be to check if "foo" in line 4 is of
pointer type, but there is no suitable cursor (only CompoundStmt) at
that position since the code is usually not yet parsed and thus invalid.

Thus, just run the completion as is. If there are not any results for a
dot completion, re-run the completion with "." exchanged by "->". This
approach is inherently slower than the preferred approach implemented in
the built-in code model.

The following rare cases are not handled:

 1) Requesting completion after white space:
      Works: foo.<COMPLETE HERE>
      Fails: foo. <COMPLETE HERE>

 2) Opening a file and requesting completion (ctrl+space) without prior
    editing. No editing before triggering completion means that no
    unsaved file is generated on the backend side, which is a
    requirement for the correction.

Task-number: QTCREATORBUG-11581
Change-Id: I6bc8e8594778774ab342755fdb01a8a3e5c52ba0
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2016-01-19 13:20:35 +00:00
Marco Bubke
2b4cadf1fe CppTools: Move ProjectPart in its own header file
Also extracting inline HeaderPath class and change projects list in vector
because the size is  larger than a pointer.

Change-Id: I885fdff3fe9bccc877634d1615249755f5b674fd
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2016-01-13 14:46:56 +00:00
Nikolai Kosjar
ca63359386 CppTools/Clang: Clean-up of includes
Change-Id: I0ba340dcf0ee23e61588f17262d07e7088751836
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-12-16 13:15:38 +00:00