Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 3f613418 authored by Kevin Funk's avatar Kevin Funk

Defer running the CompletionHelper

Only run it if necessary, introduce CompletionHelper::computeCompletions
parent ca443e74
......@@ -23,6 +23,7 @@
#include "../duchain/clangtypes.h"
#include "../duchain/cursorkindtraits.h"
#include "../duchain/parsesession.h"
#include <language/duchain/stringhelpers.h>
#include <language/editor/simplecursor.h>
......@@ -31,6 +32,8 @@
#include "../util/clangutils.h"
#include <clang-c/Index.h>
namespace {
struct OverrideInfo
......@@ -255,19 +258,19 @@ CXChildVisitResult declVisitor(CXCursor cursor, CXCursor parent, CXClientData d)
}
CompletionHelper::CompletionHelper(const CXTranslationUnit& unit, const KDevelop::SimpleCursor& position, const char *file)
CompletionHelper::CompletionHelper()
{
CXFile clangFile = clang_getFile(unit, file);
if (!clangFile) {
kDebug() << "Completion helper couldn't find file: " << file;
return;
}
}
void CompletionHelper::computeCompletions(const ParseSession& session, const SimpleCursor& position)
{
const auto unit = session.unit();
CXSourceLocation location = clang_getLocation(unit, clangFile, position.line + 1, position.column + 1);
CXSourceLocation location = clang_getLocation(unit, session.file(), position.line + 1, position.column + 1);
if (clang_equalLocations(clang_getNullLocation(), location)) {
kDebug() << "Completion helper given invalid position " << position
<< " in file " << file;
<< " in file " << session.file();
return;
}
......
......@@ -22,11 +22,12 @@
#ifndef COMPLETIONHELPER_H
#define COMPLETIONHELPER_H
#include <clang-c/Index.h>
#include <QStringList>
#include <QVector>
#include "codecompletionexport.h"
#include <language/duchain/duchainpointer.h>
struct FuncOverrideInfo
{
QString returnType;
......@@ -49,6 +50,8 @@ namespace KDevelop {
class SimpleCursor;
}
class ParseSession;
Q_DECLARE_TYPEINFO(FuncOverrideInfo, Q_MOVABLE_TYPE);
Q_DECLARE_TYPEINFO(FuncImplementInfo, Q_MOVABLE_TYPE);
using FunctionOverrideList = QVector<FuncOverrideInfo>;
......@@ -57,9 +60,10 @@ using FunctionImplementsList = QVector<FuncImplementInfo>;
class KDEVCLANGCODECOMPLETION_EXPORT CompletionHelper
{
public:
CompletionHelper(const CXTranslationUnit& unit,
const KDevelop::SimpleCursor& position,
const char *filename);
CompletionHelper();
void computeCompletions(const ParseSession& session,
const KDevelop::SimpleCursor& position);
FunctionOverrideList overrides() const;
FunctionImplementsList implements() const;
......
......@@ -253,7 +253,6 @@ ClangCodeCompletionContext::ClangCodeCompletionContext(const DUContextPointer& c
)
: CodeCompletionContext(context, text, CursorInRevision::castFromSimpleCursor(position), 0)
, m_results(nullptr, clang_disposeCodeCompleteResults)
, m_completionHelper(session.unit(), position, ClangString(clang_getFileName(session.file())).c_str())
, m_parseSession(session)
{
ClangString file(clang_getFileName(session.file()));
......@@ -274,6 +273,8 @@ ClangCodeCompletionContext::ClangCodeCompletionContext(const DUContextPointer& c
m_valid = false;
return;
}
m_completionHelper.computeCompletions(session, position);
}
ClangCodeCompletionContext::~ClangCodeCompletionContext()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment