diff --git a/rustlanguagesupport.cpp b/rustlanguagesupport.cpp index b168aad..020ade8 100644 --- a/rustlanguagesupport.cpp +++ b/rustlanguagesupport.cpp @@ -1,62 +1,83 @@ #include "rustlanguagesupport.h" #include #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); new CodeCompletion(this, new CompletionModel(this), name()); } LanguageSupport::~LanguageSupport() { parseLock()->lockForWrite(); parseLock()->unlock(); delete m_highlighting; } QString LanguageSupport::name() const { return "Rust"; } KDevelop::ParseJob *LanguageSupport::createParseJob(const KDevelop::IndexedString &url) { return new ParseJob(url, this); } ICodeHighlighting *LanguageSupport::codeHighlighting() const { return m_highlighting; } +SourceFormatterItemList LanguageSupport::sourceFormatterItems() const +{ + SourceFormatterStyle rustFormatter("rustfmt"); + rustFormatter.setCaption("rustfmt"); + rustFormatter.setDescription(i18n("Format source with rustfmt.")); + rustFormatter.setMimeTypes(SourceFormatterStyle::MimeList { + SourceFormatterStyle::MimeHighlightPair { "text/rust", "Rust" }, + SourceFormatterStyle::MimeHighlightPair { "text/x-rust", "Rust" } + }); + + QString rustfmtPath = QStandardPaths::findExecutable("rustfmt"); + if (rustfmtPath.isEmpty()) { + qCDebug(KDEV_RUST) << "Could not find the rustfmt executable"; + rustfmtPath = "/usr/bin/rustfmt"; + } + rustFormatter.setContent(rustfmtPath + " --skip-children $TMPFILE"); + + return SourceFormatterItemList { SourceFormatterStyleItem { "customscript", rustFormatter } }; +} + } #include "rustlanguagesupport.moc" diff --git a/rustlanguagesupport.h b/rustlanguagesupport.h index ab3aae6..9228a6a 100644 --- a/rustlanguagesupport.h +++ b/rustlanguagesupport.h @@ -1,40 +1,42 @@ #ifndef KDEVRUSTLANGUAGESUPPORT_H #define KDEVRUSTLANGUAGESUPPORT_H #include #include #include #include #include #include #include "rusthighlighting.h" #include "duchain/astredux.h" namespace Rust { class LanguageSupport : public KDevelop::IPlugin , public KDevelop::ILanguageSupport { Q_OBJECT Q_INTERFACES( KDevelop::ILanguageSupport ) public: LanguageSupport(QObject *parent, const QVariantList &args = QVariantList()); ~LanguageSupport() override; QString name() const override; KDevelop::ParseJob *createParseJob(const KDevelop::IndexedString &url) override; KDevelop::ICodeHighlighting *codeHighlighting() const override; + KDevelop::SourceFormatterItemList sourceFormatterItems() const override; + private: Highlighting *m_highlighting; }; } #endif // KDEVRUSTLANGUAGESUPPORT_H