Commit Graph

464 Commits

Author SHA1 Message Date
Ivan Donchevskii
81f5c1c8ec Clang: implement globalRename based on clang Index
Has the same limitations as findUsages.

Change-Id: I8de4df2ecbfd8a4f3073666994398dc43af0d73c
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2017-10-25 13:35:48 +00:00
Ivan Donchevskii
050b4dd2f5 Clang: implement findUsages with existing index
Functionality is limited to the abilities of
current index which is not updated and is
generated only at project open.
Search box temporarily doesn't allow to "Search again".

Change-Id: Id1047f27ad0aafc901f06aa51ad38ceab95eaebb
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2017-10-24 10:46:52 +00:00
Ivan Donchevskii
5c554c0de9 CppTools: add multiple refactoring engines support
Make model manager able to select the most functional
refactoring engine from the available ones.

Change-Id: I74031c910706fd694a0a7def022531501f1ea005
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2017-10-17 13:32:51 +00:00
Ivan Donchevskii
a959fe59da C++: remove builtin RefactoringEngine dependency from CppEditor
Move CppRefactoringEngine to CppTools and builtin member
ownership to model manager.

Change-Id: I3e72308559fd2928229f9f25d4dd09beb3f56c34
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2017-09-22 12:59:20 +00:00
Ivan Donchevskii
55a5ffc1ec C++: remove builtin FollowSymbol dependency from CppEditor
Move FollowSymbolUnderCursor to CppTools and
builtin member ownership to internal model manager.

Change-Id: I97a4f744ec1709ccc0b34fb67b58680973ef566f
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2017-09-22 12:59:05 +00:00
Ivan Donchevskii
a137b08eaa CppEditor: refactor FollowSymbol
Create an interface to get the ability to use
another FollowSymbol implementation

Change-Id: I5802f62523ff3ee47b8a14e487adf43edcb6c9b1
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2017-09-15 14:14:01 +00:00
Marco Bubke
b6e12f4a1c Convert macros from plain QByteArray to a vector of structs
The old code model expected the macros as C++ formatted text
("#define Foo 42) but newer targets like the Clang codemodel expect key
value arguments like "-DFoo=42". So instead of parsing the text again and
again we use an abstract data description.

Task-number: QTCREATORBUG-17915
Change-Id: I0179fd13c48a581e91ee79bba9d42d501c26f19f
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-09-14 15:23:56 +00:00
Nikolai Kosjar
b2e537baaa ProjectExplorer: Move built-in parser workarounds to built-in code model
...so that only the built-in code model parser sees them, but not the
clang code model, which has problems with them. The specific case here
is due to definition of __int32:

  winnt.h:3077:1: error: functions that differ only in their return type
                  cannot be overloaded
  intrin.h:357:31: note: previous declaration is here

While moving, drop __MSVCRT__, which seems to be a predefined macro of
ancient MSVC versions, see

https://sourceforge.net/p/mpg123/mailman/mpg123-devel/?viewmonth=201010&viewday=24

Change-Id: I4b8c49ed4bdc942a2190dbae3c260f3a1a8078a4
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-03-16 16:18:44 +00:00
Nikolai Kosjar
45b7c5ac29 Revert "CppTools: Do not put configuration document into global snapshot and working copy"
This reverts commit 05942b63f8 because it
breaks refactoring, e.g. Q_PROPERTY generators.

Change-Id: I9a14b912ba72663f08ea99e7e066d824b18da4b0
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-03-07 11:54:16 +00:00
Nikolai Kosjar
8c90998fff CppTools/ProjectManagers: Reduce ui blocking when loading projects
${AnyProject}::updateCppCodeModel() did two potentially not that cheap
operations in the ui thread:
 (1) Querying the MimeDatabase for the mime type for the source files of
     the project. In 99.9% of the cases no files need to be read for
     this as the file extension will resolve the type. The expensiveness
     comes from the sheer number of files that can occur.
 (2) Calling compilers with the "(sub)project's compiler command line"
     to determine the macros. While the caches avoid redundant calls,
     the number of the unique compiler calls makes this still a
     ui-freezing experience.

These two operations are moved into a worker thread. For this, the
expensive compiler calls are encapsulated in thread safe lambdas
("runners") in order to keep the "mutexed" data minimal. The original
API calls of the toolchains are implemented in terms of the runners.

While adapting the project managers, remove also the calls to
setProjectLanguage(). These are redundant because all of the project
managers already set a proper value in the constructor. Also, currently
there is no need (client) to report back detection of C sources in
project parts. This also keeps CppProjectUpdater simple.

There is still room for improvement:
 * Run the compiler calls in parallel instead of sequence.
 * Ensure that the mime type for a file is determined exactly once.

Change-Id: I2efc4e132ee88e3c8f264012ec8fafe3d86c404f
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-02-20 09:18:13 +00:00
Ulf Hermann
c70b689526 Unify projectexplorer language IDs
We don't need two IDs for C++ and the QmlJS ID should look the same as
as the others.

Change-Id: Ib9747f6b36a90bb652951d85eec69666615670c4
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2017-01-30 15:34:46 +00:00
Nikolai Kosjar
7415964819 CppTools: Fix choosing project part after project open
As long as there are project parts for a source file, always determine
the best project part, instead of trying to stick to the previous one.
This ensures the best project part at all times and simplifies the code.

Change-Id: I25ea3eb43a5a3e6d93688d4b8965f596dc9ae22b
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-01-26 07:52:54 +00:00
Nikolai Kosjar
602c873d3e CppTools: Reparse editor documents after active project change
Change-Id: I010709c866291bf59c27f4a05765e1ab0efd28af
Reviewed-by: David Schulz <david.schulz@qt.io>
2016-12-16 13:56:31 +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
a10bfb8400 CppTools: Do not hardcode default language version
...instead, use the latest we support.

Change-Id: I7e7768bc4bc31de1fe0f441c03f3ab5d677d76e8
Reviewed-by: David Schulz <david.schulz@qt.io>
2016-12-13 08:33:09 +00:00
Nikolai Kosjar
05942b63f8 CppTools: Do not put configuration document into global snapshot and working copy
These are remnants of the time when we had only one snapshot.

Change-Id: I6ff4db645d1065a0ef195834890e0774e2e2c60e
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2016-12-08 08:52:17 +00:00
Nikolai Kosjar
521423b433 CppTools: Call ProjectInfo::finish when we get it
No need to require the project managers to do this. Also, it is easy to
forget.

Change-Id: I96f7a5e5547418678af9653e5753c372f0880e5a
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
2016-12-06 14:34:39 +00:00
Nikolai Kosjar
83ea1f4deb CppTools: Add UI for file size limit of indexer
Task-number: QTCREATORBUG-16712
Change-Id: I92db8cbcac9669cbd5e4ee5f7ef6f613797c753a
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
2016-08-31 07:47:27 +00:00
Nikolai Kosjar
f06a5db22b CppTools: Fix condition in file size check
Change-Id: I71d67f1273bad025b8dff45b3903b458f5cda2a2
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
2016-08-16 13:38:13 +00:00
Marco Bubke
4cdb5bab15 Clang: Add clang refactoring
Change-Id: I2e3f36f810276da3f8dc7dcc587b06f8edb586d3
GPush-Base: d02f51b48fc752fddcdef6dcb32b3f7f6c0195a3
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2016-08-04 14:37:19 +00:00
Nikolai Kosjar
d63e27d877 CppTools/Clang: Announce only removed project parts
...and not all projects parts of a project if it is closed.

Re-produce with:
  open a project A with subdirs (e.g. qtcreator.pro)
  open a subdir project from project A (e.g. cppeditor.pro)
  close project A
  --> The project part representing the subdir is announced as removed
      although it is still open.

The clang code model was the only affected user - affected translation
units were not parsed/updated anymore
("ERROR: ProjectPartDoesNotExistMessage").

Change-Id: Ia79341ce201e3b4aefff9f597920dbc6f7d67634
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
2016-06-28 07:48:18 +00:00
Orgad Shaneh
46cacd901a CppTools: Use Qt5-style connects
Mostly done by clazy.

Change-Id: I0fbbbe1a2d28b79bcb83093d608bca6e2f927ebb
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2016-05-23 09:02:21 +00:00
Nikolai Kosjar
1cbb4cc954 QbsProjectManager: Fix SOFT ASSERT: "future.isFinished()"
...in file qbsproject.cpp, line 940.

The assert can be triggered with e.g.:
 1. Load a bigger qbs project, e.g. qtcreator.qbs.
 2. Trigger project build as soon as possible.
 3. Cancel the "Parsing C/C++" operation.
 4. Wait until the build finished and the assert occurs.

This happens because CppModelManager::updateProjectInfo() since

  commit  536ccc8a87
  CppTools: Fix incompletely indexed project

will check whether the previous indexer run was canceled or not. If it
was canceled, it will trigger a full-reindexing of the project.

Updating the compiler call data is a special case and it should never
trigger an indexing operation, so introduce a dedicated update function
for this case.

Change-Id: I456945ccf2bf697aaeada572ed87f3acb21a5eaf
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2016-05-03 08:03:24 +00:00
Nikolai Kosjar
536ccc8a87 CppTools: Fix incompletely indexed project
Use case to reproduce:
 1. Open some bigger project, e.g. qtcreator.pro
 2. As soon as "Parsing C/C++ files" is reported, add a character to
    qmake's additional arguments in project mode (indexing should not be
    finished at this point).
 3. The indexing gets canceled.
 ==> ...but reindexing is not triggered.

Fix by checking whether the future was canceled.

Task-number: QTCREATORBUG-16134
Change-Id: I520c6a64a6adc1cb04cafb5e0aa56c8bf41d7b14
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2016-04-25 12:41:42 +00:00
Nikita Baryshnikov
5f91cb0d68 CppTools: fix metatype registration macro usage
in places where we do not need it

Change-Id: Ibf35f8144da859fffa3e0a7b6bb262284ec2292a
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2016-03-24 08:15:44 +00:00
Eike Ziller
74cdce071f Merge remote-tracking branch 'origin/3.6'
Conflicts:
	src/shared/qbs
	tests/manual/proparser/main.cpp

Change-Id: I13654bf10c14eb6b1d6805fe86b67ac73b2e4d75
2016-02-24 10:08:37 +01:00
Orgad Shaneh
6234511a2c CppTools: Use a shared thread pool
Without this, too many threads are spawned, and loading a project takes
forever.

Change-Id: I3c22557ddd7bfb0c70f7b089c276432e3b003097
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
2016-02-19 10:21:40 +00:00
Nikolai Kosjar
e1b14565fa CppTools: Do not clear project state on session unload
Affected functionality was, among others:
 * Getting the correct project part when opening a file
 * Fallback project part (merged defines/includes) not up to date
 * Fallback for "Switch Header/Source" not up to date

In the early days sessions switching was probably implemented by "close
all projects of session X, open all projects of session Y". That's not
the case anymore today.

Change-Id: I4c6a80e2eb219615d3ea6fcf07be7c05072c8832
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
2016-02-12 07:48:27 +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
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
f89d3dca8b Clang: Activate code model automatically if plugin is loaded
This removes also the need to close editor documents.

Change-Id: I96c68105bceb37841053f3dbd8a264e059a02cb8
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-12-16 12:23:58 +00:00
Nikolai Kosjar
7bb2d833f1 CppTools: Predefine __func__ and friends
...so the built-in parser can handle them.

Change-Id: Iff69638f8939c3c4dced99699a3357dd94b23c71
Task-number: QTCREATORBUG-15431
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
2015-12-15 09:57:28 +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
48952084a6 Clang: Remove per-mimetype settings
Related to

    commit c47079f97f7d42db0c581525a2ce6fddbc0995f2
    Clang: Activate the code model with a check box

Change-Id: Ief11768ba0dd27788032e2dd3ad9b7ae39a8f52b
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-11-16 14:08:25 +00:00
Nikolai Kosjar
9d7b054120 CppTools: Fix potential race condition
...when acessing m_headerPaths, m_projectFiles or m_definedMacros from
different threads.

ensureUpdated() locked the mutex before writing the variables, but
reading them happened with an unlocked mutex.

Change-Id: I4951fd58f1939e4e50534a018dd600004789668e
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
2015-11-09 12:10:14 +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
77270648e8 CppTools: Fix dead lock on project unloading
...with the clang code model.

In updateProjectInfo() we lock the project mutex and emit a signal.
However, the correspondig slot in the clang code model will call back
into a function that needs to lock the mutex, too:

    CppTools::CppModelManager::workingCopy // dead locks here
    CppTools::BaseEditorDocumentParser::InMemoryInfo::InMemoryInfo
    ClangCodeModel::Internal::ClangEditorDocumentProcessor::run
    ClangCodeModel::Internal::ModelManagerSupportClang::unregisterTranslationUnitsWithProjectParts
    ClangCodeModel::Internal::ModelManagerSupportClang::onProjectPartsRemoved
     ...
    CppTools::CppModelManager::projectPartsRemoved
    CppTools::CppModelManager::updateProjectInfo // emits here

Fixed by emitting the signal after releasing the mutex.

Change-Id: Id3f3cd22b0604f343ada56ea13c26f0dc1a75bd6
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-10-14 10:10:47 +00:00
Nikolai Kosjar
6b6ad446eb CppTools: Make FollowSymbol respect projects
Finding the class definition for a forward declaration or finding the
function definition from its declaration is mostly determined by the
file iteration order. Documents with the most common path prefix are
checked first.

This works fine as long as the files of your project have a common
ancestor. If that's not the case, FollowSymbol might take you to the
definition within another project.

Fix that issue by considering the project part id when constructing the
file iteration order. Since the cached file iteration order now depends
on the projects, ensure to clear it if projects are added, changed or
removed.

Task-number: QTCREATORBUG-15116
Change-Id: I529166bac363959c9fee0b946747fd0370a88809
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-10-12 15:08:24 +00:00
Nikolai Kosjar
6ced48ea89 CppEditor: Move static symbol finder instance to CppTools
...to it can be reused by other clients more easily. Also, in a
follow-up change it will have a project part dependency that can be
cleared inside the CppModelManager more easily.

Change-Id: Ic9f2ce5212a94fd05ab0571e9ad99d0a25f5bc5c
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-10-12 14:04:31 +00:00
Aleix Pol
b899684a89 Don't put QString in static attributes
It crashed in some places on our code-base due to the so-called "static
initialization order fiasco".
As a solution, it turns the variable into a function. This shouldn't have
a penalty due to QStringLiteral.

Change-Id: I9f8a955afdff878dc2f0db16fec861d81250c243
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
2015-10-09 17:09:45 +00:00
Daniel Teske
307061032c Fix changing "#include" lines after file renaming
Didn't work if there was any folded text before the #include.

Change-Id: I8f16205f06bfaa8b8541401a9ebd5995c15b2227
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
2015-10-06 13:17:55 +00:00
Marco Bubke
3114780e55 CppTools: Add CppModelManager::isManagedById
Change-Id: Ica1a33b2619f64746b8671bff2856503775a40bf
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
2015-08-31 15:02:11 +00:00
Nikolai Kosjar
a3056e8922 CppTools: Fix removedProjectParts()
It compared pointers, not ids.

Change-Id: Ic77c64e452f8abfe9a35b74591f0f3baeebcf7f0
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-07-20 09:49:26 +00:00
Nikolai Kosjar
420bc69739 CppTools: Use project part ids instead of file paths
File paths are not unique since e.g. each qbs group in a file is mapped
to a project part.

Change-Id: I7df3f224dd23046b869f2588b8a34eb26cfc0b1a
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-07-20 09:49:14 +00:00
Nikolai Kosjar
0369bac126 UiCodeModelSupport: Notify if content changes
Needed for ClangCodeModel.

If the content changes, we want to send it immediately to the
codemodelbackend process.

Change-Id: Iedf16930b494ccb5e91f1bc435db026067d98613
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
2015-07-08 15:38:16 +00:00
Nikolai Kosjar
b4db657cb5 CppTools: Remove invalid QTC_CHECK
Quitting Qt Creator before the project was loaded from the project
manager triggers the assert because the updateProjectInfo() call was not
yet made by the project manager.

Change-Id: I23c660971e48d007d1bae00ecf8ed5c2ad3d4071
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-06-24 13:31:14 +00:00
Nikolai Kosjar
23b8a3b2e8 Clang: Use completion through backend process
This makes us independent of libclang crashes for completion.
Re-parsing for highlighting still happens in the Qt Creator process.

Run in verbose mode:
    qtc.clangcodemodel.ipc=true

Run tests:
    -test "ClangCodeModel"

Task-number: QTCREATORBUG-14108
Task-number: QTCREATORBUG-12819
Change-Id: Id3e95bd2afdb6508bbd1d35fddc69534a909b905
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
2015-06-10 10:15:40 +00:00
Nikolai Kosjar
1960503ae9 CppTools: Allow to limit the files to process by file size
...with the environment variable QTC_CPP_FILE_SIZE_LIMIT_MB.

Task-number: QTCREATORBUG-14390
Change-Id: Iaefaa1a3db023b58f9351b96e1b9e2139797e280
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
2015-05-13 08:26:52 +00:00
Nikolai Kosjar
d4bb5033b2 CppTools: Remove separate indexing revision
For indexing we used a custom revision that was updated on each
modelManager BuiltinIndexingSupport::refreshSourceFiles() call. This
could lead to rejection of updated documents triggered by refactoring
actions, like for the following case:

 1. Open a project containing a.h and a.cpp
 2. Open a.cpp, insert some new lines, save and close the document
 3. Open a.h and rename a function that is defined in a.cpp
    --> The refactoring action modifies a.h and a.cpp, so re-indexing
        of those is triggered. Since a.cpp has already a higher revision
        (step 2) than the updated document, the updated document is
        discarded. As a consequence find usages and follow symbol fails
        for the renamed function.

Now the document call back provided to CppSourceProcessor is responsible
for updating the document revision based on the latest revision in the
global snapshot.

Change-Id: I4dfa0a4d34991655acfa749109f00c47b0fbfdbe
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
2015-04-24 08:35:13 +00:00
Nikolai Kosjar
f0d891758a CppTools: Update project part structures consistently
When the configuration (defines and includes dirs) did not change, we
only updated the m_projectToProjectsInfo data structure, but not the
others (m_projectFileToProjectPart, m_fileToProjectParts).

Change-Id: I0ca235ea4bbe4556bd8b6d36897dedd6482f86a0
Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
2015-04-07 08:03:15 +00:00