diff --git a/CMakeLists.txt b/CMakeLists.txt index df44b57..543eb68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,93 +1,96 @@ cmake_minimum_required(VERSION 2.8.12) project(kdevrust) set(KDEVRUST_VERSION_MAJOR 0) set(KDEVRUST_VERSION_MINOR 1) set(KDEVRUST_VERSION_PATCH 0) # KDevplatform dependency version set(KDEVPLATFORM_VERSION "${KDEVRUST_VERSION_MAJOR}.${KDEVRUST_VERSION_MINOR}.${KDEVRUST_VERSION_PATCH}") find_package(ECM 5.14.0 REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH}) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/) include(KDECompilerSettings NO_POLICY_SCOPE) include(GenerateExportHeader) include(CMakePackageConfigHelpers) include(ECMAddTests) include(ECMQtDeclareLoggingCategory) include(FeatureSummary) include(KDEInstallDirs) include(KDECMakeSettings) find_package(Qt5 REQUIRED Core Widgets Test) find_package(KF5 REQUIRED COMPONENTS ItemModels ThreadWeaver TextEditor I18n) find_package(KDevPlatform ${KDEVPLATFORM_VERSION} REQUIRED) find_package(ASTRedux MODULE) set_package_properties(ASTRedux PROPERTIES TYPE REQUIRED) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdocumentation") endif() add_definitions( -DTRANSLATION_DOMAIN=\"kdevrust\" ) enable_testing() #add_subdirectory(parser) #add_subdirectory(duchain) #add_subdirectory(codecompletion) include_directories( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} # ${CMAKE_CURRENT_SOURCE_DIR}/duchain # ${CMAKE_CURRENT_SOURCE_DIR}/parser # ${CMAKE_CURRENT_BINARY_DIR}/parser ) set(kdevrustlanguagesupport_PART_SRCS rustlanguagesupport.cpp rustparsejob.cpp rusthighlighting.cpp duchain/contextbuilder.cpp duchain/declarationbuilder.cpp duchain/usebuilder.cpp duchain/rustnode.cpp duchain/rustducontext.cpp duchain/parsesession.cpp duchain/astredux.h duchain/nodetraits.h + codecompletion/completionmodel.cpp + codecompletion/completionworker.cpp + codecompletion/completioncontext.cpp # rustdebug.cpp ) ecm_qt_declare_logging_category(kdevrustlanguagesupport_PART_SRCS HEADER rustdebug.h IDENTIFIER KDEV_RUST CATEGORY_NAME "kdevelop.languages.rust" ) kdevplatform_add_plugin(kdevrustlanguagesupport JSON kdevrustsupport.json SOURCES ${kdevrustlanguagesupport_PART_SRCS} ) target_link_libraries(kdevrustlanguagesupport KDev::Interfaces KDev::Language KF5::ThreadWeaver KF5::TextEditor # kdevrustparser # kdevrustduchain # kdevrustcompletion ${ASTRedux_LIBRARY} ) install(FILES kdevrustsupport.categories DESTINATION ${KDE_INSTALL_CONFDIR}) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/codecompletion/completioncontext.cpp b/codecompletion/completioncontext.cpp new file mode 100644 index 0000000..c135b2c --- /dev/null +++ b/codecompletion/completioncontext.cpp @@ -0,0 +1,28 @@ +#include "completioncontext.h" + +#include "rustdebug.h" + +namespace Rust +{ + +using namespace KDevelop; + +CompletionContext::CompletionContext(DUContextPointer context, + const QString &contextText, + const QString &followingText, + const CursorInRevision &position, + int depth) + : KDevelop::CodeCompletionContext(context, contextText, position, depth), + m_followingText(followingText) +{ + +} + +QList CompletionContext::completionItems(bool &abort, bool fullCompletion) +{ + qCDebug(KDEV_RUST) << "Hello world, no completions yet"; + + return QList(); +} + +} diff --git a/codecompletion/completioncontext.h b/codecompletion/completioncontext.h new file mode 100644 index 0000000..0ec3b39 --- /dev/null +++ b/codecompletion/completioncontext.h @@ -0,0 +1,28 @@ +#ifndef COMPLETIONCONTEXT_H +#define COMPLETIONCONTEXT_H + +#include + +#include + +namespace Rust +{ + +class CompletionContext : public KDevelop::CodeCompletionContext +{ +public: + CompletionContext(KDevelop::DUContextPointer context, + const QString &contextText, + const QString &followingText, + const KDevelop::CursorInRevision &position, + int depth); + + QList completionItems(bool &abort, bool fullCompletion) override; + +private: + QString m_followingText; +}; + +} + +#endif // COMPLETIONCONTEXT_H diff --git a/codecompletion/completionmodel.cpp b/codecompletion/completionmodel.cpp new file mode 100644 index 0000000..e15e0a5 --- /dev/null +++ b/codecompletion/completionmodel.cpp @@ -0,0 +1,18 @@ +#include "completionmodel.h" + +#include "completionworker.h" + +namespace Rust +{ + +CompletionModel::CompletionModel(QObject *parent) + : KDevelop::CodeCompletionModel(parent) +{ +} + +KDevelop::CodeCompletionWorker *CompletionModel::createCompletionWorker() +{ + return new CompletionWorker(this); +} + +} diff --git a/codecompletion/completionmodel.h b/codecompletion/completionmodel.h new file mode 100644 index 0000000..84a2258 --- /dev/null +++ b/codecompletion/completionmodel.h @@ -0,0 +1,21 @@ +#ifndef COMPLETIONMODEL_H +#define COMPLETIONMODEL_H + +#include + +namespace Rust +{ + +class CompletionModel : public KDevelop::CodeCompletionModel +{ + Q_OBJECT +public: + CompletionModel(QObject *parent); + +protected: + KDevelop::CodeCompletionWorker *createCompletionWorker() override; +}; + +} + +#endif // COMPLETIONMODEL_H diff --git a/codecompletion/completionworker.cpp b/codecompletion/completionworker.cpp new file mode 100644 index 0000000..47a04a6 --- /dev/null +++ b/codecompletion/completionworker.cpp @@ -0,0 +1,25 @@ +#include "completionworker.h" +#include "completionmodel.h" +#include "completioncontext.h" + +namespace Rust +{ + +CompletionWorker::CompletionWorker(CompletionModel *parent) + : KDevelop::CodeCompletionWorker(parent) +{ +} + +KDevelop::CodeCompletionContext *CompletionWorker::createCompletionContext(KDevelop::DUContextPointer context, + const QString &contextText, + const QString &followingText, + const KDevelop::CursorInRevision &position) const +{ + if (!context) { + return nullptr; + } + + return new CompletionContext(context, contextText, followingText, position, 0); +} + +} diff --git a/codecompletion/completionworker.h b/codecompletion/completionworker.h new file mode 100644 index 0000000..f83cfc7 --- /dev/null +++ b/codecompletion/completionworker.h @@ -0,0 +1,26 @@ +#ifndef COMPLETIONWORKER_H +#define COMPLETIONWORKER_H + +#include + +namespace Rust +{ + +class CompletionModel; + +class CompletionWorker : public KDevelop::CodeCompletionWorker +{ + Q_OBJECT +public: + CompletionWorker(CompletionModel *parent); + +protected: + KDevelop::CodeCompletionContext *createCompletionContext(KDevelop::DUContextPointer context, + const QString &contextText, + const QString &followingText, + const KDevelop::CursorInRevision &position) const override; +}; + +} + +#endif // COMPLETIONWORKER_H diff --git a/rustlanguagesupport.cpp b/rustlanguagesupport.cpp index 5c7144e..67fc166 100644 --- a/rustlanguagesupport.cpp +++ b/rustlanguagesupport.cpp @@ -1,60 +1,62 @@ #include "rustlanguagesupport.h" #include #include #include #include #include #include +#include #include #include #include #include "rustparsejob.h" +#include "codecompletion/completionmodel.h" K_PLUGIN_FACTORY_WITH_JSON(KDevRustSupportFactory, "kdevrustsupport.json", registerPlugin(); ) using namespace KDevelop; namespace Rust { LanguageSupport::LanguageSupport(QObject *parent, const QVariantList& args) : KDevelop::IPlugin(QStringLiteral("kdevrustsupport"), parent), KDevelop::ILanguageSupport(), m_highlighting(new Highlighting(this)) { Q_UNUSED(args); - qCDebug(KDEV_RUST) << "Hello world, Rust plugin initialized is loaded!"; + new CodeCompletion(this, new CompletionModel(this), name()); } LanguageSupport::~LanguageSupport() { parseLock()->lockForWrite(); parseLock()->unlock(); delete m_highlighting; } QString LanguageSupport::name() const { return "Rust Language Support"; } KDevelop::ParseJob* LanguageSupport::createParseJob(const KDevelop::IndexedString &url) { return new ParseJob(url, this); } ICodeHighlighting *LanguageSupport::codeHighlighting() const { return m_highlighting; } } #include "rustlanguagesupport.moc"