diff options
author | Nikolai Kosjar <nikolai.kosjar@qt.io> | 2017-02-27 13:10:19 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2017-02-28 09:56:16 +0000 |
commit | d3b51ccda7ff1e2f699acbe10397f40a2e25b9eb (patch) | |
tree | 76be4350d58d10b1ce6e2202e4805b01d7b2bbaf /src/plugins/clangcodemodel | |
parent | 7c5f2184c6261bf6c852cee9f22302c1d04f35ad (diff) | |
download | qt-creator-d3b51ccda7ff1e2f699acbe10397f40a2e25b9eb.tar.gz |
Clang: Avoid pointless preamble regeneration on Windows
...on first user modification of the document by ensuring that libclang
sees only one kind of line separators.
This reduces the latency for the very first completion.
Change-Id: I9fdd5641e673a5d07200d61476d56d01db62b89e
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/clangcodemodel')
-rw-r--r-- | src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp index 1cb6790b44..19f3bdaa22 100644 --- a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp +++ b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp @@ -331,18 +331,24 @@ void ClangEditorDocumentProcessor::onParserFinished() void ClangEditorDocumentProcessor::registerTranslationUnitForEditor(CppTools::ProjectPart *projectPart) { + // On registration we send the document content immediately as an unsaved + // file, because + // (1) a refactoring action might have opened and already modified + // this document. + // (2) it prevents an extra preamble generation on first user + // modification of the document in case the line endings on disk + // differ from the ones returned by textDocument()->toPlainText(), + // like on Windows. + if (m_projectPart) { - if (projectPart->id() != m_projectPart->id()) { - m_ipcCommunicator.unregisterTranslationUnitsForEditor({fileContainerWithArguments()}); - m_ipcCommunicator.registerTranslationUnitsForEditor({fileContainerWithArguments(projectPart)}); - } - } else if (revision() != 1) { - // E.g. a refactoring action opened the document and modified it immediately. - m_ipcCommunicator.registerTranslationUnitsForEditor({{fileContainerWithArgumentsAndDocumentContent(projectPart)}}); - ClangCodeModel::Utils::setLastSentDocumentRevision(filePath(), revision()); - } else { - m_ipcCommunicator.registerTranslationUnitsForEditor({{fileContainerWithArguments(projectPart)}}); + if (projectPart->id() == m_projectPart->id()) + return; + m_ipcCommunicator.unregisterTranslationUnitsForEditor({fileContainerWithArguments()}); } + + m_ipcCommunicator.registerTranslationUnitsForEditor( + {fileContainerWithArgumentsAndDocumentContent(projectPart)}); + ClangCodeModel::Utils::setLastSentDocumentRevision(filePath(), revision()); } void ClangEditorDocumentProcessor::updateTranslationUnitIfProjectPartExists() |