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>
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>
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>
...for consistency and to avoid future file name clashes.
Change-Id: If595c8debfa1ceb01a1bb0ed34649fa513660503
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
Related to
commit c47079f97f7d42db0c581525a2ce6fddbc0995f2
Clang: Activate the code model with a check box
Change-Id: Ief11768ba0dd27788032e2dd3ad9b7ae39a8f52b
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
Fix the following use case:
* Open foo.h
* Open foo.cpp
* Change both files externally (e.g. git checkout) e.g. by adding a
function (declaration + definition)
* Confirm the reload dialog in Qt Creator
* The added function in foo.cpp gets a diagnostic that it's out of line
although foo.h is also reloaded.
TextDocument::contentsChangedWithPosition() is also emitted during a
reload. However, the revision of the document at that point is not yet
updated. This led to an out-dated copy of the unsaved files in the clang
backend.
Change-Id: I70580d32bb7a34dc43356dc05019cc18addf950e
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
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>
File containers were generates in many places. To reduce the noise this
getters are introduced.
Change-Id: I059745c27ac2dd0515bc23b3438d6d264ba071d7
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
Ensure that first the editors unregister with the removed project part,
then unregister the project part.
This makes testing and following the message logs easier.
It also fixes the following race condition:
* Unload project of opened file
* Immediately close the editor before a new project part is calculated
==> The editor is closed, but the translation unit is not properly
unregistered.
Change-Id: I618930d221323435ba60ac6c051380bccc9fdaf1
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
If a file is reloaded it should update every translation unit.
Change-Id: Ib61d933e95fcd9fe4d32363ddc06f5edcca55e35
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
They are invokable by the usual means (Alt+Enter, editor's context menu
> Refactor) plus by the context menu of the editor's left margin for the
related line.
The fixit text comes directly from libclang and is thus not translated.
We modify the text slighty by stripping the diagnostic category prefix
("note:", "error:", ...) and capitalizing the first letter.
A follow-up change should properly indicate available refactorings with
a refactoring icon in the editor's left margin.
Task-number: QTCREATORBUG-14868
Change-Id: I86157c9f824d2a9dedf19087476d02ad1e6cc854
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
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>
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>
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>
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>
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>
The assertion failed if textDocument was of type e.g.
DiffEditorDocument.
Change-Id: I00f8734b99c1187c071ef55ff1622fe1f9c3eb56
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
To make it clear that it is for testing only.
Change-Id: If257b0049e87c834b24073991f173bfc1b3e93e7
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
It makes the resource allocation much more clear.
Change-Id: Ib276e089dc3db551171373d72e9b54c9d87b4c8c
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
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>
Mostly done using the following ruby script:
Dir.glob('**/*.cpp').each { |file|
next if file =~ %r{src/shared/qbs|/qmljs/}
s = File.read(file)
s.scan(/^using namespace (.*);$/) {
ns = $1
t = s.gsub(/^(.*)\b#{ns}::((?!Const)[A-Z])/) { |m|
before = $1
char = $2
if before =~ /"|\/\/|\\|using|SIGNAL|SLOT|Q_/
m
else
before + char
end
}
if t != s
puts file
File.open(file, 'w').write(t)
end
}
}
Change-Id: I6fbe13ddc1485efe95c3156097bf41d90c0febac
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
First step of some more 'Base' removal in TextEditor.
s/Core::TextDocument/Core::BaseTextDocument/
s/TextEditor::BaseTextDocument/TextEditor::TextDocument/
Change-Id: I71ba325a2f0ad72ec9dae0d96846cbae72d326f7
Reviewed-by: hjk <hjk121@nokiamail.com>
This mainly takes CppEditorSupport apart.
* Parsing is now invoked by CPPEditorDocument itself by listening to
QTextDocument::contentsChanged().
* Upon construction and destruction CPPEditorDocument creates and
deletes an EditorDocumentHandle for (un)registration in the model
manager. This handle provides everything to generate the working copy
and to access the editor document processor.
* A CPPEditorDocument owns a BaseEditorDocumentProcessor instance that
controls parsing, semantic info recalculation and the semantic
highlighting for the document. This is more or less what is left from
CppEditorSupport and can be considered as the backend of a
CPPEditorDocument. CPPEditorDocument itself is quite small.
* BuiltinEditorDocumentProcessor and ClangEditorDocumentProcessor
derive from BaseEditorDocumentProcessor and implement the gaps.
* Since the semantic info calculation was bound to the widget, it
also calculated the local uses, which depend on the cursor
position. This calculation got moved into the extracted class
UseSeletionsUpdater in the cppeditor plugin, which is run once the
cursor position changes or the semantic info document is updated.
* Some more logic got extracted:
- SemanticInfoUpdater (logic was in CppEditorSupport)
- SemanticHighlighter (logic was in CppEditorSupport)
* The *Parser and *Processor classes can be easily accessed by the
static function get().
* CppHighlightingSupport is gone since it turned out to be useless.
* The editor dependency in CompletionAssistProviders is gone since we
actually only need the file path now.
Change-Id: I49d3a7bd138c5ed9620123e34480772535156508
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
...instead an ITextEditor.
The ITextEditor was only used to access the file path and QTextDocument
via the BaseTextEditorWidget.
Change-Id: Idef2b8162b992fe3718e16e2a046e2ff214846f2
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Do not use QObject::tr(), use native file paths,
use complete contexts.
Change-Id: Icc4990b4c2ca5b9ae6f6b639db9e1a45a93e0a65
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>