Changeset View
Changeset View
Standalone View
Standalone View
languages/clang/codecompletion/context.cpp
Show All 36 Lines | |||||
37 | #include <language/duchain/persistentsymboltable.h> | 37 | #include <language/duchain/persistentsymboltable.h> | ||
38 | #include <language/duchain/types/integraltype.h> | 38 | #include <language/duchain/types/integraltype.h> | ||
39 | #include <language/duchain/types/functiontype.h> | 39 | #include <language/duchain/types/functiontype.h> | ||
40 | #include <language/duchain/types/pointertype.h> | 40 | #include <language/duchain/types/pointertype.h> | ||
41 | #include <language/duchain/types/typealiastype.h> | 41 | #include <language/duchain/types/typealiastype.h> | ||
42 | #include <language/duchain/types/typeutils.h> | 42 | #include <language/duchain/types/typeutils.h> | ||
43 | #include <language/codecompletion/codecompletionmodel.h> | 43 | #include <language/codecompletion/codecompletionmodel.h> | ||
44 | #include <language/codecompletion/normaldeclarationcompletionitem.h> | 44 | #include <language/codecompletion/normaldeclarationcompletionitem.h> | ||
45 | #include <util/foregroundlock.h> | ||||
45 | 46 | | |||
46 | #include "../util/clangdebug.h" | 47 | #include "../util/clangdebug.h" | ||
47 | #include "../util/clangtypes.h" | 48 | #include "../util/clangtypes.h" | ||
49 | #include "../util/clangutils.h" | ||||
48 | #include "../duchain/clangdiagnosticevaluator.h" | 50 | #include "../duchain/clangdiagnosticevaluator.h" | ||
49 | #include "../duchain/parsesession.h" | 51 | #include "../duchain/parsesession.h" | ||
52 | #include "../duchain/duchainutils.h" | ||||
50 | #include "../duchain/navigationwidget.h" | 53 | #include "../duchain/navigationwidget.h" | ||
51 | #include "../clangsettings/clangsettingsmanager.h" | 54 | #include "../clangsettings/clangsettingsmanager.h" | ||
52 | 55 | | |||
53 | #include <functional> | 56 | #include <functional> | ||
54 | #include <memory> | 57 | #include <memory> | ||
55 | 58 | | |||
56 | #include <KTextEditor/Document> | 59 | #include <KTextEditor/Document> | ||
57 | #include <KTextEditor/View> | 60 | #include <KTextEditor/View> | ||
▲ Show 20 Lines • Show All 712 Lines • ▼ Show 20 Line(s) | 767 | ClangCodeCompletionContext::ClangCodeCompletionContext(const DUContextPointer& context, | |||
770 | ) | 773 | ) | ||
771 | : CodeCompletionContext(context, text + followingText, CursorInRevision::castFromSimpleCursor(position), 0) | 774 | : CodeCompletionContext(context, text + followingText, CursorInRevision::castFromSimpleCursor(position), 0) | ||
772 | , m_results(nullptr, clang_disposeCodeCompleteResults) | 775 | , m_results(nullptr, clang_disposeCodeCompleteResults) | ||
773 | , m_parseSessionData(sessionData) | 776 | , m_parseSessionData(sessionData) | ||
774 | { | 777 | { | ||
775 | qRegisterMetaType<MemberAccessReplacer::Type>(); | 778 | qRegisterMetaType<MemberAccessReplacer::Type>(); | ||
776 | const QByteArray file = url.toLocalFile().toUtf8(); | 779 | const QByteArray file = url.toLocalFile().toUtf8(); | ||
777 | ParseSession session(m_parseSessionData); | 780 | ParseSession session(m_parseSessionData); | ||
781 | | ||||
782 | QVector<UnsavedFile> otherUnsavedFiles; | ||||
783 | { | ||||
784 | ForegroundLock lock; | ||||
mwolff: ugh - I hoped to not use the foreground lock in kdev code in order to remove it eventually. But… | |||||
785 | otherUnsavedFiles = ClangUtils::unsavedFiles(); | ||||
786 | } | ||||
787 | QVector<CXUnsavedFile> allUnsaved; | ||||
788 | | ||||
778 | { | 789 | { | ||
779 | const unsigned int completeOptions = clang_defaultCodeCompleteOptions(); | 790 | const unsigned int completeOptions = clang_defaultCodeCompleteOptions(); | ||
780 | 791 | | |||
781 | CXUnsavedFile unsaved; | 792 | CXUnsavedFile unsaved; | ||
782 | unsaved.Filename = file.constData(); | 793 | unsaved.Filename = file.constData(); | ||
783 | const QByteArray content = m_text.toUtf8(); | 794 | const QByteArray content = m_text.toUtf8(); | ||
784 | unsaved.Contents = content.constData(); | 795 | unsaved.Contents = content.constData(); | ||
785 | unsaved.Length = content.size() + 1; // + \0-byte | 796 | unsaved.Length = content.size(); | ||
797 | | ||||
798 | for ( const auto& f : otherUnsavedFiles ) { | ||||
799 | allUnsaved.append(f.toClangApi()); | ||||
800 | } | ||||
801 | allUnsaved.append(unsaved); | ||||
786 | 802 | | |||
787 | m_results.reset(clang_codeCompleteAt(session.unit(), file.constData(), | 803 | m_results.reset(clang_codeCompleteAt(session.unit(), file.constData(), | ||
788 | position.line() + 1, position.column() + 1, | 804 | position.line() + 1, position.column() + 1, | ||
789 | content.isEmpty() ? nullptr : &unsaved, content.isEmpty() ? 0 : 1, | 805 | allUnsaved.data(), allUnsaved.size(), | ||
790 | completeOptions)); | 806 | completeOptions)); | ||
791 | 807 | | |||
792 | if (!m_results) { | 808 | if (!m_results) { | ||
793 | qCWarning(KDEV_CLANG) << "Something went wrong during 'clang_codeCompleteAt' for file" << file; | 809 | qCWarning(KDEV_CLANG) << "Something went wrong during 'clang_codeCompleteAt' for file" << file; | ||
794 | return; | 810 | return; | ||
795 | } | 811 | } | ||
796 | 812 | | |||
797 | auto numDiagnostics = clang_codeCompleteGetNumDiagnostics(m_results.get()); | 813 | auto numDiagnostics = clang_codeCompleteGetNumDiagnostics(m_results.get()); | ||
Show All 30 Lines | 842 | if (trimmedText.endsWith(QLatin1Char('.'))) { | |||
828 | // But it doesn't always do it, so let's try to manually determine whether '.' is used instead of '->' | 844 | // But it doesn't always do it, so let's try to manually determine whether '.' is used instead of '->' | ||
829 | m_text = trimmedText.left(trimmedText.size() - 1); | 845 | m_text = trimmedText.left(trimmedText.size() - 1); | ||
830 | m_text += QStringLiteral("->"); | 846 | m_text += QStringLiteral("->"); | ||
831 | 847 | | |||
832 | CXUnsavedFile unsaved; | 848 | CXUnsavedFile unsaved; | ||
833 | unsaved.Filename = file.constData(); | 849 | unsaved.Filename = file.constData(); | ||
834 | const QByteArray content = m_text.toUtf8(); | 850 | const QByteArray content = m_text.toUtf8(); | ||
835 | unsaved.Contents = content.constData(); | 851 | unsaved.Contents = content.constData(); | ||
836 | unsaved.Length = content.size() + 1; | 852 | unsaved.Length = content.size(); | ||
853 | allUnsaved[allUnsaved.size() - 1] = unsaved; | ||||
837 | 854 | | |||
838 | m_results.reset(clang_codeCompleteAt(session.unit(), file.constData(), | 855 | m_results.reset(clang_codeCompleteAt(session.unit(), file.constData(), | ||
839 | position.line() + 1, position.column() + 1 + 1, | 856 | position.line() + 1, position.column() + 1 + 1, | ||
840 | &unsaved, 1, | 857 | allUnsaved.data(), allUnsaved.size(), | ||
841 | clang_defaultCodeCompleteOptions())); | 858 | clang_defaultCodeCompleteOptions())); | ||
842 | 859 | | |||
843 | if (m_results && m_results->NumResults) { | 860 | if (m_results && m_results->NumResults) { | ||
844 | QMetaObject::invokeMethod(&s_memberAccessReplacer, "replaceCurrentAccess", Qt::QueuedConnection, | 861 | QMetaObject::invokeMethod(&s_memberAccessReplacer, "replaceCurrentAccess", Qt::QueuedConnection, | ||
845 | Q_ARG(MemberAccessReplacer::Type, MemberAccessReplacer::DotToArrow)); | 862 | Q_ARG(MemberAccessReplacer::Type, MemberAccessReplacer::DotToArrow)); | ||
846 | } | 863 | } | ||
847 | 864 | | |||
848 | m_valid = false; | 865 | m_valid = false; | ||
▲ Show 20 Lines • Show All 379 Lines • Show Last 20 Lines |
ugh - I hoped to not use the foreground lock in kdev code in order to remove it eventually. But fair enough for now, leave it as is.