Commit 6dca2d31 authored by Amish Naidu's avatar Amish Naidu Committed by Milian Wolff

clang: Fix completion tests by using documentController to create view

Implement/override completion tests now use DocumentChangeSet which
relies on CodeRepresentation to make changes, if we don't use a view
through the global document controller, a disk file code representation
is created which doesn't update the kate view.
parent 34c34c77
......@@ -41,21 +41,20 @@
void DeleteDocument::operator()(KTextEditor::View* view) const
{
delete view->document();
// explicitly close the document when all references are valid, otherwise we have problems during cleanup
const auto url = view->document()->url();
ICore::self()->documentController()->documentForUrl(url)->close(IDocument::Discard);
}
std::unique_ptr<KTextEditor::View, DeleteDocument> CodeCompletionTestBase::createView(const QUrl& url, QObject* parent) const
std::unique_ptr<KTextEditor::View, DeleteDocument> CodeCompletionTestBase::createView(const QUrl& url) const
{
KTextEditor::Editor* editor = KTextEditor::Editor::instance();
Q_ASSERT(editor);
auto doc = editor->createDocument(parent);
auto doc = KDevelop::ICore::self()
->documentController()
->openDocument(url, KTextEditor::Range::invalid(), KDevelop::IDocumentController::DoNotActivate)
->textDocument();
Q_ASSERT(doc);
bool opened = doc->openUrl(url);
Q_ASSERT(opened);
Q_UNUSED(opened);
auto view = doc->createView(nullptr);
auto view = doc->views().first();
Q_ASSERT(view);
return std::unique_ptr<KTextEditor::View, DeleteDocument>(view);
}
......
......@@ -46,7 +46,7 @@ class CodeCompletionTestBase : public QObject
Q_OBJECT
public:
std::unique_ptr<KTextEditor::View, DeleteDocument> createView(const QUrl& url, QObject* parent) const;
std::unique_ptr<KTextEditor::View, DeleteDocument> createView(const QUrl& url) const;
private Q_SLOTS:
void initTestCase();
......
......@@ -182,6 +182,7 @@ void executeCompletionTest(const ReferencedTopDUContext& top, const CompletionIt
}
QCOMPARE(tester.names, expectedCompletionItems.completions);
lock.unlock(); // customTestFunction should lock appropriately
customTestFunction(tester);
}
......@@ -636,7 +637,8 @@ void TestCodeCompletion::testOverrideExecute()
auto executeItem = [=] (const ClangCodeCompletionItemTester& tester) {
auto item = tester.findItem(itemToExecute);
QVERIFY(item);
auto view = createView(tester.completionContext->duContext()->url().toUrl(), this);
auto view = createView(tester.completionContext->duContext()->url().toUrl());
DUChainReadLocker lock;
item->execute(view.get(), view->document()->wordRangeAt(expectedItems.position));
QCOMPARE(view->document()->text(), expectedCode);
};
......@@ -1046,7 +1048,7 @@ void TestCodeCompletion::testIncludePathCompletion()
auto item = tester.findItem(itemId);
QVERIFY(item);
auto view = createView(file.url().toUrl(), this);
auto view = createView(file.url().toUrl());
QVERIFY(view.get());
auto doc = view->document();
item->execute(view.get(), KTextEditor::Range(cursor, cursor));
......@@ -1233,6 +1235,7 @@ void TestCodeCompletion::testArgumentHintCompletion()
QFETCH(HintItemList, hints);
executeCompletionTest(code, expectedItems, NoMacroOrBuiltin, [&](const ClangCodeCompletionItemTester& tester) {
DUChainReadLocker lock;
HintItemList actualHints;
for (const auto& item : tester.items) {
if (item->argumentHintDepth() == 1) {
......@@ -1403,7 +1406,8 @@ void TestCodeCompletion::testCompleteFunction()
auto executeItem = [=] (const ClangCodeCompletionItemTester& tester) {
auto item = tester.findItem(itemToExecute);
QVERIFY(item);
auto view = createView(tester.completionContext->duContext()->url().toUrl(), this);
auto view = createView(tester.completionContext->duContext()->url().toUrl());
DUChainReadLocker lock;
item->execute(view.get(), view->document()->wordRangeAt(expectedItems.position));
QCOMPARE(view->document()->text(), expectedCode);
};
......
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