Commit 43aa52f2 authored by Kevin Funk's avatar Kevin Funk

Initial port towards KF5

parent f77e3548
project(kdev-clang)
set(VERSION_MAJOR 1)
set(VERSION_MINOR 7)
set(VERSION_PATCH 60)
set(VERSION_MINOR 90)
set(VERSION_PATCH 90)
# KDevplatform dependency version
set( KDEVPLATFORM_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" )
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/)
cmake_minimum_required(VERSION 2.8.9)
cmake_minimum_required(VERSION 2.8.12)
find_package (ECM 0.0.9 REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH})
find_package(KDE4 REQUIRED)
include(ECMAddTests)
include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDECompilerSettings)
find_package(Qt5 REQUIRED Core Widgets Test)
find_package(KF5 REQUIRED COMPONENTS KDELibs4Support ThreadWeaver TextEditor I18n)
find_package(KDevPlatform ${KDEVPLATFORM_VERSION} REQUIRED)
find_package(KDevelop REQUIRED)
find_package(Clang 3.4)
macro_log_feature(CLANG_FOUND "libclang" "LibClang is a high level C interface to clang" "http://clang.llvm.org/" TRUE "3.4")
set_package_properties(Clang PROPERTIES
TYPE REQUIRED
PURPOSE "LibClang is a high level C interface to clang"
URL "http://clang.llvm.org/")
add_definitions(${LLVM_CFLAGS})
include_directories(
......@@ -47,7 +58,7 @@ enable_testing()
include_directories(
${KDE4_INCLUDES}
${KDEVPLATFORM_INCLUDE_DIR}
${CMAKE_INSTALL_PREFIX}/${KDEVPLATFORM_INCLUDE_DIR}
${KDEVELOP_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
......@@ -60,7 +71,7 @@ add_subdirectory(codegen)
add_subdirectory(util)
add_subdirectory(tests)
kde4_add_plugin(kdevclangsupport
add_library(kdevclangsupport SHARED
clangparsejob.cpp
clangsupport.cpp
documentfinderhelpers.cpp
......@@ -72,14 +83,16 @@ kde4_add_plugin(kdevclangsupport
target_link_libraries(kdevclangsupport
kdevclangduchain
${KDE4_THREADWEAVER_LIBS}
${KDEVPLATFORM_PROJECT_LIBRARIES}
KF5::ThreadWeaver
KF5::TextEditor
KDev::Util
KDev::Project
)
configure_file(kdevclangsupport.desktop.cmake ${CMAKE_CURRENT_BINARY_DIR}/kdevclangsupport.desktop)
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/kdevclangsupport.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
install(TARGETS kdevclangsupport DESTINATION ${PLUGIN_INSTALL_DIR})
install(TARGETS kdevclangsupport DESTINATION ${PLUGIN_INSTALL_DIR}/kdevplatform/${KDEV_PLUGIN_VERSION})
install(FILES kdevclangsupport.rc DESTINATION ${DATA_INSTALL_DIR}/kdevclangsupport)
macro_display_feature_log()
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
......@@ -160,7 +160,7 @@ ClangSupport* ClangParseJob::clang() const
return static_cast<ClangSupport*>(languageSupport());
}
void ClangParseJob::run()
void ClangParseJob::run(ThreadWeaver::JobPointer self, ThreadWeaver::Thread *thread)
{
QReadLocker parseLock(languageSupport()->language()->parseLock());
......@@ -189,7 +189,7 @@ void ClangParseJob::run()
DUChainWriteLocker lock;
const auto& context = DUChainUtils::standardContextForUrl(document().toUrl());
if (context) {
sessionData = ParseSessionData::Ptr::dynamicCast(context->ast());
sessionData = ParseSessionData::Ptr(dynamic_cast<ParseSessionData*>(context->ast().data()));
}
}
}
......@@ -260,9 +260,9 @@ void ClangParseJob::run()
// the user
// otherwise no editor component is open for this document and we can dispose
// the TU to save memory
context->setAst(KSharedPtr<IAstContainer>::staticCast(session.data()));
context->setAst(IAstContainer::Ptr(session.data()));
}
auto file = KSharedPtr<ClangParsingEnvironmentFile>::dynamicCast(context->parsingEnvironmentFile());
auto file = dynamic_cast<ClangParsingEnvironmentFile*>(context->parsingEnvironmentFile().data());
Q_ASSERT(file);
// verify that features and environment where properly set in ClangHelpers::buildDUChain
Q_ASSERT(file->featuresSatisfied(TopDUContext::Features(minimumFeatures() & ~TopDUContext::ForceUpdateRecursive)));
......
......@@ -38,12 +38,12 @@ public:
ClangSupport* clang() const;
protected:
virtual void run();
virtual void run(ThreadWeaver::JobPointer self, ThreadWeaver::Thread *thread) override;
virtual const KDevelop::ParsingEnvironment* environment() const override;
private:
KSharedPtr<ParseSessionData> createSessionData() const;
QExplicitlySharedDataPointer<ParseSessionData> createSessionData() const;
ClangParsingEnvironment m_environment;
};
......
......@@ -66,9 +66,9 @@
#include <QRegExp>
K_PLUGIN_FACTORY(KDevClangSupportFactory, registerPlugin<ClangSupport>(); )
K_EXPORT_PLUGIN(KDevClangSupportFactory(
KAboutData("kdevclangsupport", 0, ki18n("Clang Plugin"), "0.1",
ki18n("Support for C, C++ and Objective-C languages."), KAboutData::License_GPL)))
//K_EXPORT_PLUGIN(KDevClangSupportFactory(
// KAboutData("kdevclangsupport", 0, ki18n("Clang Plugin"), "0.1",
// ki18n("Support for C, C++ and Objective-C languages."), KAboutData::License_GPL)))
using namespace KDevelop;
......@@ -83,83 +83,83 @@ namespace {
*
* @return Range pointing to the path-spec of the include or invalid range if there is no #include directive on the line.
*/
SimpleRange rangeForIncludePathSpec(const QString& line, const SimpleRange& originalRange = SimpleRange())
KTextEditor::Range rangeForIncludePathSpec(const QString& line, const KTextEditor::Range& originalRange = KTextEditor::Range())
{
if (!line.contains(QRegExp("^\\s*#include"))) {
return SimpleRange::invalid();
return KTextEditor::Range::invalid();
}
SimpleRange range = originalRange;
KTextEditor::Range range = originalRange;
int pos = 0;
for (; pos < line.size(); ++pos) {
if(line[pos] == '"' || line[pos] == '<') {
range.start.column = ++pos;
range.setStart({range.start().line(), ++pos});
break;
}
}
for (; pos < line.size(); ++pos) {
if(line[pos] == '"' || line[pos] == '>') {
range.end.column = pos;
range.setEnd({range.start().line(), pos});
break;
}
}
if(range.start > range.end) {
range.start = range.end;
if(range.start() > range.end()) {
range.setStart(range.end());
}
return range;
}
QPair<QString, SimpleRange> lineInDocument(const KUrl& url, const SimpleCursor& position)
QPair<QString, KTextEditor::Range> lineInDocument(const KUrl& url, const KTextEditor::Cursor& position)
{
KDevelop::IDocument* doc = ICore::self()->documentController()->documentForUrl(url);
if (!doc || !doc->textDocument() || !doc->textDocument()->activeView()) {
if (!doc || !doc->textDocument() || !ICore::self()->documentController()->activeTextDocumentView()) {
return {};
}
const int lineNumber = position.line;
const int lineNumber = position.line();
const int lineLength = doc->textDocument()->lineLength(lineNumber);
KTextEditor::Range range(lineNumber, 0, lineNumber, lineLength);
QString line = doc->textDocument()->text(range);
return {line, range};
}
QPair<TopDUContextPointer, SimpleRange> importedContextForPosition(const KUrl& url, const SimpleCursor& position)
QPair<TopDUContextPointer, KTextEditor::Range> importedContextForPosition(const KUrl& url, const KTextEditor::Cursor& position)
{
auto pair = lineInDocument(url, position);
const QString line = pair.first;
if (line.isEmpty())
return {{}, SimpleRange::invalid()};
return {{}, KTextEditor::Range::invalid()};
SimpleRange wordRange = rangeForIncludePathSpec(line, pair.second);
KTextEditor::Range wordRange = rangeForIncludePathSpec(line, pair.second);
if (!wordRange.isValid()) {
return {{}, SimpleRange::invalid()};
return {{}, KTextEditor::Range::invalid()};
}
// Since this is called by the editor while editing, use a fast timeout so the editor stays responsive
DUChainReadLocker lock(nullptr, 100);
if (!lock.locked()) {
debug() << "Failed to lock the du-chain in time";
return {TopDUContextPointer(), SimpleRange::invalid()};
return {TopDUContextPointer(), KTextEditor::Range::invalid()};
}
TopDUContext* topContext = DUChainUtils::standardContextForUrl(url);
if (line.isEmpty() || !topContext || !topContext->parsingEnvironmentFile()) {
return {TopDUContextPointer(), SimpleRange::invalid()};
return {TopDUContextPointer(), KTextEditor::Range::invalid()};
}
if ((topContext->parsingEnvironmentFile() && topContext->parsingEnvironmentFile()->isProxyContext())) {
debug() << "Strange: standard-context for" << topContext->url().str() << "is a proxy-context";
return {TopDUContextPointer(), SimpleRange::invalid()};
return {TopDUContextPointer(), KTextEditor::Range::invalid()};
}
// It's an #include, find out which file was included at the given line
foreach(const DUContext::Import &imported, topContext->importedParentContexts()) {
auto context = imported.context(nullptr);
if (context) {
if(topContext->transformFromLocalRevision(topContext->importPosition(context)).line == wordRange.start.line) {
if(topContext->transformFromLocalRevision(topContext->importPosition(context)).line() == wordRange.start().line()) {
if (auto importedTop = dynamic_cast<TopDUContext*>(context))
return {TopDUContextPointer(importedTop), wordRange};
}
......@@ -169,7 +169,7 @@ QPair<TopDUContextPointer, SimpleRange> importedContextForPosition(const KUrl& u
// The last resort. Check if the file is already included (maybe recursively from another files).
// This is needed as clang doesn't visit (clang_getInclusions) those inclusions.
// TODO: Maybe create an assistant that'll report whether the file is already included?
auto includeName = line.mid(wordRange.start.column, wordRange.end.column - wordRange.start.column);
auto includeName = line.mid(wordRange.start().column(), wordRange.end().column() - wordRange.start().column());
if (!includeName.isEmpty()) {
if (includeName.startsWith(".")) {
......@@ -190,10 +190,10 @@ QPair<TopDUContextPointer, SimpleRange> importedContextForPosition(const KUrl& u
}
}
return {{}, SimpleRange::invalid()};
return {{}, KTextEditor::Range::invalid()};
}
QPair<TopDUContextPointer, Use> macroExpansionForPosition(const KUrl& url, const SimpleCursor& position)
QPair<TopDUContextPointer, Use> macroExpansionForPosition(const KUrl& url, const KTextEditor::Cursor& position)
{
TopDUContext* topContext = DUChainUtils::standardContextForUrl(url);
if (topContext) {
......@@ -211,7 +211,7 @@ QPair<TopDUContextPointer, Use> macroExpansionForPosition(const KUrl& url, const
}
ClangSupport::ClangSupport(QObject* parent, const QVariantList& )
: IPlugin( KDevClangSupportFactory::componentData(), parent )
: IPlugin( "kdevclangsupport", parent )
, ILanguageSupport()
, m_highlighting(new KDevelop::CodeHighlighting(this))
, m_refactoring(new SimpleRefactoring(this))
......@@ -281,9 +281,9 @@ void ClangSupport::createActionsForMainWindow (Sublime::MainWindow* /*window*/,
{
_xmlFile = xmlFile();
KAction* renameDeclarationAction = actions.addAction("code_rename_declaration");
QAction* renameDeclarationAction = actions.addAction("code_rename_declaration");
renameDeclarationAction->setText( i18n("Rename Declaration") );
renameDeclarationAction->setIcon(KIcon("edit-rename"));
renameDeclarationAction->setIcon(QIcon::fromTheme("edit-rename"));
renameDeclarationAction->setShortcut( Qt::CTRL | Qt::ALT | Qt::Key_R);
connect(renameDeclarationAction, SIGNAL(triggered(bool)), m_refactoring, SLOT(executeRenameAction()));
}
......@@ -300,7 +300,7 @@ KDevelop::ContextMenuExtension ClangSupport::contextMenuExtension(KDevelop::Cont
return cm;
}
SimpleRange ClangSupport::specialLanguageObjectRange(const KUrl& url, const SimpleCursor& position)
KTextEditor::Range ClangSupport::specialLanguageObjectRange(const KUrl& url, const KTextEditor::Cursor& position)
{
DUChainReadLocker lock;
const QPair<TopDUContextPointer, Use> macroExpansion = macroExpansionForPosition(url, position);
......@@ -308,26 +308,26 @@ SimpleRange ClangSupport::specialLanguageObjectRange(const KUrl& url, const Simp
return macroExpansion.first->transformFromLocalRevision(macroExpansion.second.m_range);
}
const QPair<TopDUContextPointer, SimpleRange> import = importedContextForPosition(url, position);
const QPair<TopDUContextPointer, KTextEditor::Range> import = importedContextForPosition(url, position);
if(import.first) {
return import.second;
}
return SimpleRange::invalid();
return KTextEditor::Range::invalid();
}
QPair<KUrl, KDevelop::SimpleCursor> ClangSupport::specialLanguageObjectJumpCursor(const KUrl& url, const SimpleCursor& position)
QPair<KUrl, KTextEditor::Cursor> ClangSupport::specialLanguageObjectJumpCursor(const KUrl& url, const KTextEditor::Cursor& position)
{
const QPair<TopDUContextPointer, SimpleRange> import = importedContextForPosition(url, position);
const QPair<TopDUContextPointer, KTextEditor::Range> import = importedContextForPosition(url, position);
DUChainReadLocker lock;
if (import.first) {
return qMakePair(KUrl(import.first->url().str()), SimpleCursor(0,0));
return qMakePair(KUrl(import.first->url().str()), KTextEditor::Cursor(0,0));
}
return {{}, SimpleCursor::invalid()};
return {{}, KTextEditor::Cursor::invalid()};
}
QWidget* ClangSupport::specialLanguageObjectNavigationWidget(const KUrl& url, const SimpleCursor& position)
QWidget* ClangSupport::specialLanguageObjectNavigationWidget(const KUrl& url, const KTextEditor::Cursor& position)
{
DUChainReadLocker lock;
const QPair<TopDUContextPointer, Use> macroExpansion = macroExpansionForPosition(url, position);
......@@ -339,7 +339,7 @@ QWidget* ClangSupport::specialLanguageObjectNavigationWidget(const KUrl& url, co
return new ClangNavigationWidget(macroDefinition, DocumentCursor(IndexedString(url), rangeInRevision));
}
const QPair<TopDUContextPointer, SimpleRange> import = importedContextForPosition(url, position);
const QPair<TopDUContextPointer, KTextEditor::Range> import = importedContextForPosition(url, position);
if (import.first) {
// Prefer a standardContext, because the included one may have become empty due to
......
......@@ -55,12 +55,12 @@ public:
virtual void createActionsForMainWindow(Sublime::MainWindow* window, QString& xmlFile, KActionCollection& actions);
KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context);
virtual KDevelop::SimpleRange specialLanguageObjectRange(const KUrl& url,
const KDevelop::SimpleCursor& position) override;
virtual QPair<KUrl, KDevelop::SimpleCursor> specialLanguageObjectJumpCursor(const KUrl& url,
const KDevelop::SimpleCursor& position) override;
virtual KTextEditor::Range specialLanguageObjectRange(const KUrl& url,
const KTextEditor::Cursor& position) override;
virtual QPair<KUrl, KTextEditor::Cursor> specialLanguageObjectJumpCursor(const KUrl& url,
const KTextEditor::Cursor& position) override;
virtual QWidget* specialLanguageObjectNavigationWidget(const KUrl& url,
const KDevelop::SimpleCursor& position) override;
const KTextEditor::Cursor& position) override;
ClangIndex* index();
......@@ -68,9 +68,9 @@ public:
//BEGIN IBuddyDocumentFinder
virtual bool areBuddies(const KUrl& url1, const KUrl& url2);
virtual bool buddyOrder(const KUrl& url1, const KUrl& url2);
virtual QVector< KUrl > getPotentialBuddies(const KUrl& url) const;
virtual bool areBuddies(const KUrl& url1, const KUrl& url2) override;
virtual bool buddyOrder(const KUrl& url1, const KUrl& url2) override;
virtual QVector< KUrl > getPotentialBuddies(const KUrl& url) const override;
//END IBuddyDocumentFinder
......
......@@ -8,6 +8,7 @@ add_library(kdevclangcodecompletion OBJECT
context.cpp
completionhelper.cpp
)
target_include_directories(kdevclangcodecompletion PRIVATE $<TARGET_PROPERTY:KF5::TextEditor,INTERFACE_INCLUDE_DIRECTORIES>)
set_target_properties(kdevclangcodecompletion PROPERTIES
AUTOMOC TRUE
POSITION_INDEPENDENT_CODE TRUE)
......@@ -28,7 +28,6 @@
#include "../debug.h"
#include <language/duchain/stringhelpers.h>
#include <language/editor/simplecursor.h>
#include <clang-c/Index.h>
......@@ -263,11 +262,11 @@ CompletionHelper::CompletionHelper()
{
}
void CompletionHelper::computeCompletions(const ParseSession& session, const SimpleCursor& position)
void CompletionHelper::computeCompletions(const ParseSession& session, const KTextEditor::Cursor& position)
{
const auto unit = session.unit();
CXSourceLocation location = clang_getLocation(unit, session.file(), 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)) {
debug() << "Completion helper given invalid position " << position
......
......@@ -46,8 +46,8 @@ struct FuncImplementInfo
QString prototype;
};
namespace KDevelop {
class SimpleCursor;
namespace KTextEditor {
class Cursor;
}
class ParseSession;
......@@ -63,7 +63,7 @@ public:
CompletionHelper();
void computeCompletions(const ParseSession& session,
const KDevelop::SimpleCursor& position);
const KTextEditor::Cursor& position);
FunctionOverrideList overrides() const;
FunctionImplementsList implements() const;
......
......@@ -40,9 +40,12 @@
#include "../debug.h"
#include <memory>
#include <KTextEditor/Document>
#include <KTextEditor/View>
#include <KIcon>
using namespace KDevelop;
namespace {
......@@ -82,9 +85,9 @@ public:
return {};
}
void execute(KTextEditor::Document* document, const KTextEditor::Range& word) override
void execute(KTextEditor::View* view, const KTextEditor::Range& word) override
{
document->replaceText(word, m_replacement);
view->document()->replaceText(word, m_replacement);
}
protected:
......@@ -167,7 +170,7 @@ public:
return NormalDeclarationCompletionItem::data(index, role, model);
}
void execute(KTextEditor::Document* document, const KTextEditor::Range& word) override
void execute(KTextEditor::View* view, const KTextEditor::Range& word) override
{
QString repl = m_replacement;
DUChainReadLocker lock;
......@@ -178,13 +181,13 @@ public:
if(m_declaration->isFunctionDeclaration()) {
repl += "()";
document->replaceText(word, repl);
view->document()->replaceText(word, repl);
auto f = m_declaration->type<FunctionType>();
if (f && f->indexedArgumentsSize()) {
document->activeView()->setCursorPosition(word.start() + KTextEditor::Cursor(0, repl.size() - 1));
view->setCursorPosition(word.start() + KTextEditor::Cursor(0, repl.size() - 1));
}
} else {
document->replaceText(word, repl);
view->document()->replaceText(word, repl);
}
}
......@@ -221,7 +224,7 @@ using SimpleItem = CompletionItem<CompletionTreeItem>;
/**
* Return true in case position @p position represents a cursor inside a comment
*/
bool isInsideComment(CXTranslationUnit unit, CXFile file, const KDevelop::SimpleCursor& position)
bool isInsideComment(CXTranslationUnit unit, CXFile file, const KTextEditor::Cursor& position)
{
if (!position.isValid()) {
return false;
......@@ -229,7 +232,7 @@ bool isInsideComment(CXTranslationUnit unit, CXFile file, const KDevelop::Simple
// TODO: This may get very slow for a large TU, investigate if we can improve this function
auto begin = clang_getLocation(unit, file, 1, 1);
auto end = clang_getLocation(unit, file, position.line + 1, position.column + 1);
auto end = clang_getLocation(unit, file, position.line() + 1, position.column() + 1);
CXSourceRange range = clang_getRange(begin, end);
// tokenize the whole range from the start until 'position'
......@@ -245,7 +248,7 @@ bool isInsideComment(CXTranslationUnit unit, CXFile file, const KDevelop::Simple
}
auto range = ClangRange(clang_getTokenExtent(unit, token));
if (range.toSimpleRange().contains(position)) {
if (range.toRange().contains(position)) {
return true;
}
}
......@@ -321,40 +324,43 @@ bool isValidSpecialCompletionIdentifier(const QualifiedIdentifier& identifier)
}
ClangCodeCompletionContext::ClangCodeCompletionContext(const DUContextPointer& context,
const ParseSession& session,
const SimpleCursor& position,
const ParseSessionData::Ptr& sessionData,
const KTextEditor::Cursor& position,
const QString& text
)
: CodeCompletionContext(context, text, CursorInRevision::castFromSimpleCursor(position), 0)
, m_results(nullptr, clang_disposeCodeCompleteResults)
, m_parseSession(session)
, m_parseSessionData(sessionData)
{
ClangString file(clang_getFileName(session.file()));
{
ParseSession session(m_parseSessionData);
ClangString file(clang_getFileName(session.file()));
const unsigned int completeOptions = clang_defaultCodeCompleteOptions();
const unsigned int completeOptions = clang_defaultCodeCompleteOptions();
if (!m_text.isEmpty()) {
debug() << "Unsaved contents found for file" << file << "- creating CXUnsavedFile";
if (!m_text.isEmpty()) {
debug() << "Unsaved contents found for file" << file << "- creating CXUnsavedFile";
CXUnsavedFile unsaved;
const QByteArray content = m_text.toUtf8();
unsaved.Contents = content.constData();
unsaved.Length = content.size() + 1; // + \0-byte
unsaved.Filename = file.c_str();
CXUnsavedFile unsaved;
const QByteArray content = m_text.toUtf8();
unsaved.Contents = content.constData();
unsaved.Length = content.size() + 1; // + \0-byte
unsaved.Filename = file.c_str();
m_results.reset(clang_codeCompleteAt(session.unit(), file.c_str(),
position.line + 1, position.column + 1,
&unsaved, 1u,
completeOptions));
} else {
m_results.reset(clang_codeCompleteAt(session.unit(), file.c_str(),
position.line + 1, position.column + 1,
nullptr, 0u,
completeOptions));
}
m_results.reset(clang_codeCompleteAt(session.unit(), file.c_str(),
position.line() + 1, position.column() + 1,
&unsaved, 1u,
completeOptions));
} else {
m_results.reset(clang_codeCompleteAt(session.unit(), file.c_str(),
position.line() + 1, position.column() + 1,
nullptr, 0u,
completeOptions));
}
if (!m_results) {
kWarning() << "Something went wrong during 'clang_codeCompleteAt' for file" << file.toString();
if (!m_results) {
kWarning() << "Something went wrong during 'clang_codeCompleteAt' for file" << file.toString();
}
}
// check 'isValidPosition' after parsing the new content
......@@ -363,6 +369,7 @@ ClangCodeCompletionContext::ClangCodeCompletionContext(const DUContextPointer& c
return;
}
ParseSession session(m_parseSessionData);
m_completionHelper.computeCompletions(session, position);
}
......@@ -372,7 +379,8 @@ ClangCodeCompletionContext::~ClangCodeCompletionContext()
bool ClangCodeCompletionContext::isValidPosition() const
{
if (isInsideComment(m_parseSession.unit(), m_parseSession.file(), m_position.castToSimpleCursor())) {
ParseSession session(m_parseSessionData);
if (isInsideComment(session.unit(), session.file(), m_position.castToSimpleCursor())) {
debug() << "Invalid completion context: Inside comment";
return false;
}
......
......@@ -46,8 +46,8 @@ public:
Q_DECLARE_FLAGS(ContextFilters, ContextFilter)
ClangCodeCompletionContext(const KDevelop::DUContextPointer& context,
const ParseSession& session,
const KDevelop::SimpleCursor& position,
const ParseSessionData::Ptr& sessionData,
const KTextEditor::Cursor& position,
const QString& text);
~ClangCodeCompletionContext();
......@@ -71,7 +71,7 @@ private:
std::unique_ptr<CXCodeCompleteResults, void(*)(CXCodeCompleteResults*)> m_results;
QList<KDevelop::CompletionTreeElementPointer> m_ungrouped;
CompletionHelper m_completionHelper;
ParseSession m_parseSession;
ParseSessionData::Ptr m_parseSessionData;
ContextFilters m_filters = NoFilter;
};
......
......@@ -43,7 +43,7 @@ public:
virtual ~ClangCodeCompletionWorker() = default;
public slots:
void completionRequested(const KUrl& url, const KDevelop::SimpleCursor& position, const QString& text)
void completionRequested(const KUrl& url, const KTextEditor::Cursor& position, const QString& text)
{
aborting() = false;
......@@ -62,8 +62,8 @@ public slots:
// We hold DUChain lock, and ask for ParseSession, but TUDUChain indirectly holds ParseSession lock.
lock.unlock();
const ParseSession session(ParseSessionData::Ptr::dynamicCast(top->ast()));
if (!session.data()) {
const ParseSessionData::Ptr sessionData(dynamic_cast<ParseSessionData*>(top->ast().data()));
if (!sessionData) {
// TODO: trigger reparse and re-request code completion
kWarning() << "No parse session / AST attached to context for url" << url;
return;
......@@ -75,7 +75,7 @@ public slots:
}
lock.lock();
ClangCodeCompletionContext completionContext(DUContextPointer(top), session, position, text);
ClangCodeCompletionContext completionContext(DUContextPointer(top), sessionData, position, text);
if (aborting()) {
failed();
......@@ -110,7 +110,7 @@ public slots:
ClangCodeCompletionModel::ClangCodeCompletionModel(QObject* parent)
: CodeCompletionModel(parent)
{
qRegisterMetaType<KDevelop::SimpleCursor>();
qRegisterMetaType<KTextEditor::Cursor>();
}
ClangCodeCompletionModel::~ClangCodeCompletionModel()
......@@ -121,8 +121,8 @@ ClangCodeCompletionModel::~ClangCodeCompletionModel()
CodeCompletionWorker* ClangCodeCompletionModel::createCompletionWorker()
{
auto worker = new ClangCodeCompletionWorker(this);
connect(this, SIGNAL(requestCompletion(KUrl,KDevelop::SimpleCursor,QString)),
worker, SLOT(completionRequested(KUrl,KDevelop::SimpleCursor,QString)));
connect(this, SIGNAL(requestCompletion(KUrl,KTextEditor::Cursor,QString)),
worker, SLOT(completionRequested(KUrl,KTextEditor::Cursor,QString)));
return worker;
}
......@@ -131,7 +131,7 @@ void ClangCodeCompletionModel::completionInvokedInternal(KTextEditor::View* view
{
// get text before this range so we can parse this version with clang
auto text = view->document()->text({0, 0, range.start().line(), range.start().column()});
emit requestCompletion(url, SimpleCursor(range.start()), text);
emit requestCompletion(url, KTextEditor::Cursor(range.start()), text);
}
#include "model.moc"
......