Commit Graph

59 Commits

Author SHA1 Message Date
Nikolai Kosjar
b869f02f72 Clang: Introduce headers for client/server messages
This reduces the overhead when a new message needs to be added.

Change-Id: I5bb2833af2f06f2a8e101cfb03f75ffc2927bf68
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2017-06-19 11:08:39 +00:00
Nikolai Kosjar
e6a4041003 Clang: Remove pointless member variable
The called function uses already static state.

Change-Id: I22c6cceea6c0c779c4b8ca94b74e0828e27b1f4e
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2017-06-15 08:00:26 +00:00
Nikolai Kosjar
ca72c29462 Clang: Provide highlighting for identifier under cursor
Change-Id: I80ffe23cbcc84ab7323124581d9dd6afbe974fd0
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2017-06-14 12:49:05 +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
Nikolai Kosjar
e2e78c6a5d CppTools: Distinguish between ProjectFile::{unclassified,unsupported}
There was no way to determine whether ProjectFile::classify() was run or
not. Now, ProjectFile::classify() returns ProjectFile::Unsupported
instead of ProjectFile::Unclassified.

Change-Id: I660d0e42044bdefcac38058c6f4a3425983a6d93
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-02-02 14:46:13 +00:00
Nikolai Kosjar
02d8e2af1b CppTools: Clean up ProjectInfo
Change-Id: I5d0db45d9fdb624bb6cc55d7f04061d553f13bce
Reviewed-by: David Schulz <david.schulz@qt.io>
2016-12-13 09:15:25 +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
0e12c51d0b Clang: Clean up clangbackendipcintegration.cpp
Change-Id: I60d7d2969d55499bc2ac5ddaf0127c60e8c76a7a
Reviewed-by: David Schulz <david.schulz@qt.io>
2016-11-23 09:17:39 +00:00
Nikolai Kosjar
1948481390 Clang: Do not print AliveMessage by default
In 99% of the time this is annoying.

Change-Id: I14749eec6180472221193577aa14b1e396f34ba7
Reviewed-by: David Schulz <david.schulz@qt.io>
2016-11-23 09:14:30 +00:00
Nikolai Kosjar
2b9e9ebbfc Clang: Work around libclang not accepting not existing unsaved files
Feeding libclang with unsaved files (e.g. in-memory generated ui_*.h)
that do not exist on disk leads to regeneration of the preamble on every
parse/reparse/completion and thus renders the clang code model useless.

We could check the existence in the file system for every unsaved file
just before every parse/reparse/completion. Obviously this does not
scale (e.g. qtcreator.pro generates about 200 unsaves files) and would
also slow down the responsiveness of the completion, especially for the
dot-to-arrow correction case.

We could also set up a file system watcher. However, implementing the
"file got created" case is not trivial because QFileSystemWatcher does
not support it out of the box.

Instead, set up a custom include directory and create empty files in it
that represent the unsaved files and pass that include directory to
libclang as the last one. While this fixes the performance problems, it
also comes with at least two problems:

  * Because ui_*.h files are "relocated" to the same directory, two or
    more "foo.ui" in the same session will be problematic.

  * Because of the custom include directory, problems might arise for
    projects that include the ui_*.h as "some/relative/path/ui_foo.h"
    instead of "ui_foo.h". This should be the less common case.

Task-number: QTCREATORBUG-17245
Change-Id: I6e40e87c3ef095086eb22c972dd8c1a6459a8245
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2016-11-22 12:21:14 +00:00
Nikolai Kosjar
434ecfc4f5 Clang: Log messages with time stamp
Change-Id: I0bb56d319328a2773e55609d63b4ac28eea07386
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2016-10-21 09:08:04 +00:00
Nikolai Kosjar
9d55d8485c Clang: Show info bar for parse errors in header files
...because those errors can lead to a substantial performance/functional
regression.

The actual diagnostics (possibly with children) are shown as details in
the info bar.

The info bar can be hidden with the "Do Not Show Again" button.
Re-enabling the info bar is possible with the new editor tool bar
button.

Change-Id: I03394ff8e3c84127946b0b791930b28a385f5a46
Reviewed-by: David Schulz <david.schulz@qt.io>
2016-10-11 14:01:14 +00:00
Nikolai Kosjar
2bff4ba1ec Clang: Log clangbackend process errors to "General Messages" pane
Change-Id: I687c4a4eb8a7a8874fd88b4d3d6995535dade2c9
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
2016-10-11 08:22:44 +00:00
Nikolai Kosjar
9730513698 Clang: Stop sending data to backend on disconnect
This addresses

    SOFT ASSERT made fatal: "m_connection.isConnected()" in file
      src/plugins/clangcodemodel/clangbackendipcintegration.cpp, line 230

I could not reproduce the issue locally, so I'm leaving the soft asserts
untouched for now.

Change-Id: If1d55ba7bc7e2d1ac20ad992c6d0d43ceb0f5d73
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2016-10-07 12:48:43 +00:00
Nikolai Kosjar
cb0e730bb5 Clang: Clean up exceptions
* Extract common stuff into the base class ClangException
* Remove unused exceptions TranslationUnitParseErrorException and
  TranslationUnitReparseErrorException
* Do not send error messages to the Qt Creator side. The messages were
  only generated when the backend crashed and while it was not yet fully
  re-initialized (e.g. do code completion right after crash where the
  document was not yet registered at the backend).

Change-Id: I91d98d5ef681ad487f7a2fd66f78fa7cd1e958df
Reviewed-by: David Schulz <david.schulz@qt.io>
2016-09-14 13:08:08 +00:00
Nikolai Kosjar
8f9c42c640 Clang: Merge highlighting/diagnostics messages
The messages

    RequestDiagnosticsMessage
    RequestHighlightingMessage

and

    DiagnosticsChangedMessage
    HighlightingChangedMessage

are always send/received together, so merge them into

    RequestDocumentAnnotationsMessage
    DocumentAnnotationsChangedMessage

Change-Id: I6a0b6281ed1e6efe6cb18386afe99b1d1fb58abf
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@theqtcompany.com>
2016-07-18 13:17:27 +00:00
Marco Bubke
c5e79f6269 Clang: Decouple ConnectionClient and ClangCodeModel*
We want to reuse the connection client in other plugins. This is the first
step, the next step is refactoring the IPC mechanismn and move it up to
the IpcServer- and IpcClientInterface.

Change-Id: I6eb6db1e9bc18232c8df350a6303afd2edc68da8
Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
2016-07-12 09:08:23 +00:00
Nikolai Kosjar
e6fa92e58c Clang: Adapt to async starting/connecting to backend
Change-Id: Iaa01a68b161efc80e69ee671c62e2e5b007ae0f6
Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
2016-07-12 09:08:02 +00:00
Marco Bubke
cda6e3c15a Clang: Start ConnectionClient asynchronously
The connection client can block main thread at start up. This patch is
removing the wait functions and using signals instead.

Change-Id: I847c98b095752f6a875c0365bc27361bc5bdd051
Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2016-07-12 09:07:39 +00:00
Marco Bubke
974070d2c8 Clang: Use MessageEnvelop instead of QVariant
QVariant has unwanted dependencies so we provided our own simpler solution.
We want to support move only types and calling the copy constructor as you
move the value in and outside. This copying is adding unwanted overhead
too.

Change-Id: I2e27a7924868efe81e8b8ff3415499c9fa22c2bc
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2016-02-08 14:11:44 +00:00
Marco Bubke
e134dfcad4 Clang: Remove project part dependency in IpcCommunicator
Change-Id: I312f4a3721c045ae4b4ed4b72218201dbb38aa4b
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2016-02-02 11:56:16 +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
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
ddd1d4c9cc CppTools: Remove cpptools/cppprojects.[h|cpp]
Change-Id: Ida0e8552d371972c141cf561b28667f4428c6fff
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2016-01-13 14:47:27 +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
Nikolai Kosjar
475b11aad1 Clang: Fix recovering on clangbackend crash
The translation unit was updated, but not re-registered.

Handle the editor documents this way:
  1. Reset all ClangEditorDocumentProcessors (this will send an
     unregister message, but that's not problematic).
  2. For the visible editor documents, run their processors so that the
     translation units will be re-registered.
  3. For the invisible editor documents, mark them dirty. Once the user
     makes an invisible document visible again, the processor will run
     and also re-register the translation unit.

Change-Id: I23693ac197bd34a183f3a0020eb5372268636599
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-12-02 16:04:31 +00:00
Marco Bubke
a08336fcc2 Clang: Don't send multiple completions for the same position
If we send already a completion we should test if there is already one
sent for the same position.

Change-Id: Ie88f89bff0e1da1c5e747827a45154c7ccaecabc
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-12-02 16:01:54 +00:00
Marco Bubke
ff913b83ae Clang: Use revision from file container
Change-Id: Ie084677fb910fc6e415afcdf7533369150162f8f
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-12-02 13:46:10 +00:00
Marco Bubke
493a2a6189 Clang: Fix slowness of code completion after opening the file
Task-number: QTCREATORBUG-15429
Change-Id: I9a8a582fb3c59a960425f83eb8e7b436f15d1c1a
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-12-02 12:37:25 +00:00
Marco Bubke
d579608e8a Clang: Prioritize current and visible translation units
We reparse first the current and then the visible translation units before
we reparse all other units.

The signals connections are queued to wait for the visible editor update.

Change-Id: I5e2b8bc80568450268ca24e26720b3f5af640995
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-12-01 11:14:39 +00:00
Nikolai Kosjar
a12a8c95f9 Clang: Request diagnostics/highlighting only if needed
Most of the time, the updated diagnostics/highlightings will be send by
the backend on translation unit update.

The other use case is changing the font settings (e.g. color), here we
need to request the highlightings explicitly.

Change-Id: I17a574eaf972c8bef12900241e7b33fe6ffd9dbd
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-11-30 16:50:49 +00:00
Nikolai Kosjar
5f98b8ec24 Clang: Remove PchManager
...which is the last dependency to libclang from the plugin.

Change-Id: I173ee7e9621912ec88706b4cf62db2b1dbcf7610
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-11-30 11:03:51 +00:00
Marco Bubke
7ce9ef9db4 Clang: Integrate highlighting results from backend
Change-Id: I2c3fb69aabfe075bde76d63eafc2ca370f17493c
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-11-26 15:19:27 +00:00
Nikolai Kosjar
641abf3e56 Clang: Update the fallback project part
Change-Id: I1dfbb32246798a402a1efe18529e95d6199ba942
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
2015-11-09 12:11:35 +00:00
Nikolai Kosjar
787b386ecc Clang: Use the fallback project part
...for project-less files.

Change-Id: I02d7e26bdd40dfce3b0663a07b591ee6beb2f6b7
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
2015-11-06 11:55:28 +00:00
Nikolai Kosjar
23fa5a7efd Clang: Provide the language option to the backend
Provide the language option (e.g. "-x c++-header") when registering a
translation unit for the editor.

Task-number: QTCREATORBUG-14787
Change-Id: Ie06f9fdab302f1b21ba72cdb65b6aabf9f7bc04c
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
2015-11-06 11:54:16 +00:00
Nikolai Kosjar
8f2ad8d246 Clang: Remove dead code
Change-Id: Ic81768748bb998d73906dcfc599a52f8c363f5b8
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
2015-11-06 11:32:53 +00:00
Nikolai Kosjar
582494e68f Clang: Fix misleading function name
Change-Id: I60934867db6b61c8309a712db8a189d458a73ea7
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
2015-11-06 11:32:47 +00:00
Marco Bubke
250c8d662b Clang: Add UpdateTranslationUnitsForEditorMessage
If an editor is changing all translation units independent of their project
part they must be updated too. So we introduce a new message to update all
translation units with the same file path.

Change-Id: I70d0ea2bbca9fa880111ff7219573e54f3277026
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-10-13 14:03:11 +00:00
Marco Bubke
bc89baa6e8 Clang: Request new diagnostics after reload
Diagnostics should be not computed after a file change but after creator
is requesting them. Now we wait for the dialog if the file should be
reloaded.

Change-Id: Id0d51874b95e0f8743002a91511d07e0ed47ecdc
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-10-12 15:32:03 +00:00
Marco Bubke
d6d5d9ac8c Clang: Improve IpcCommunicator::requestDiagnostics
Add logging and don't send if sendMode is IgnoreSendRequests.

Change-Id: Ia3df9fd2c1c75cfec720233518401fc9df5e0017
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-10-01 13:05:13 +00:00
Nikolai Kosjar
514efee682 Clang: Fix typo in function name
Change-Id: I6f3dd4cb41f52df440ce9d133cc199f6c66b742c
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-09-30 14:33:52 +00:00
Marco Bubke
c5941f9fec Clang: Call updateTranslationUnit for reloaded files
If a file is reloaded it should update every translation unit.

Change-Id: Ib61d933e95fcd9fe4d32363ddc06f5edcca55e35
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-09-30 14:29:29 +00:00
Marco Bubke
b412eb81ea Clang: Add revision and completion management
Reparsing a document is expensive so we should avoid it by all means. In
this patch we prevent that the same document is send again. It isn't send
too in advance of a code completion if there was no changes before the
the completion position.

Change-Id: I0bb786ba1d4e7ce08611a518cb32f8cf8f4d0037
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-09-28 15:46:15 +00:00
Marco Bubke
a272d93fcd Clang: Change name to registerCurrentCppDocuments
registerCurrentUnsavedFiles was misleading.

Change-Id: I5a2444d81d141ced4b8a0fae7236484c9e919d8d
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-09-21 13:28:35 +00:00
Marco Bubke
7eee8061f6 Clang: Add unsaved files messages
We have auto generated buffers from ui files which are not open but have no
file representation. So we need to provide them as unsaved files only.

Change-Id: I48a426c18e06eeda2fa707864f32f293e17ac651
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-08-31 15:02:19 +00:00
Marco Bubke
6e14eb6940 Clang: Rename ForCodeCompletion in ForEditor
It reflects that the translation units and projects have a tied
relationship with an editor.

Change-Id: I3c01d5776980fe079af1fdef82feded83fdf5463
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-08-31 15:02:02 +00:00
Marco Bubke
f2b7371af1 Clang: Reparse only if files are changed
Includes are now watched by a file watcher. Unsaved file changes are
watched too. If they are changed the translation units which depend on
them are set to a state which require a reparse. Later the diagnostics
of this units are collected and send back to creator.

Change-Id: I2fb5c7dd6644687f22399edd8d18edd6215c9505
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-08-31 15:00:07 +00:00
Marco Bubke
b278dc87ca Clang: Add diagnostics
Diagnostics are now moved to the clang backend process. Fixits are
supported too.

Change-Id: I20faacf466bbf78dec479220c3d7b336a47bc453
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-08-31 14:59:16 +00:00
Marco Bubke
ec4d002857 Clang: Rename command in message
Change-Id: I1e2671d15b0db3c670b86dd0d4bed5ee09e866f1
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-08-25 12:54:27 +00:00