KDevelop5/LanguagePlugin: Difference between revisions
(Created page with "= .desktop file = In order to find your language support plugin, KDE needs a .desktop file with some meta information. * <code>X-KDE-Library=...</code> this must be the same...") |
No edit summary |
||
Line 7: | Line 7: | ||
After installing your plugin, make sure to run <code>kbuildsycoca4</code>. For testing, try duchainify or ktraderclient. | After installing your plugin, make sure to run <code>kbuildsycoca4</code>. For testing, try duchainify or ktraderclient. | ||
= the plugin = | |||
A basic plugin's header looks like this: | |||
<pre> | |||
#include <interfaces/iplugin.h> | |||
#include <language/interfaces/ilanguagesupport.h> | |||
class KDevTestLangPlugin : public KDevelop::IPlugin, public KDevelop::ILanguageSupport | |||
{ | |||
Q_OBJECT | |||
Q_INTERFACES( KDevelop::ILanguageSupport ) | |||
public: | |||
explicit KDevQmlJsPlugin( QObject* parent, const QVariantList& args = QVariantList() ); | |||
virtual KDevelop::ParseJob* createParseJob(const KUrl& url); | |||
virtual QString name() const; | |||
}; | |||
</pre> | |||
An implementation could look like this: | |||
<pre> | |||
#include "kdevqmljsplugin.h" | |||
#include <KPluginFactory> | |||
#include <KAboutData> | |||
#include "qmljsparsejob.h" | |||
K_PLUGIN_FACTORY(KDevQmlJsSupportFactory, registerPlugin<KDevQmlJsPlugin>(); ) | |||
// note: "kdevtestlangsupport" must be the same as you used in X-KDE-PluginInfo-Name! | |||
K_EXPORT_PLUGIN(KDevQmlJsSupportFactory(KAboutData("kdevtestlangsupport","kdevtestlang", ki18n("TestLanguage Support"), "0.1", ki18n("Support for Some Test Language"), KAboutData::License_GPL))) | |||
KDevQmlJsPlugin::KDevQmlJsPlugin(QObject* parent, const QVariantList& ) | |||
: KDevelop::IPlugin( KDevQmlJsSupportFactory::componentData(), parent ) | |||
, KDevelop::ILanguageSupport() | |||
{ | |||
// NOTE: this is important! | |||
KDEV_USE_EXTENSION_INTERFACE(KDevelop::ILanguageSupport) | |||
} | |||
KDevelop::ParseJob* KDevTestLangPlugin::createParseJob(const KUrl& url) | |||
{ | |||
return new TestLangParseJob(url, this); | |||
} | |||
QString KDevTestLangPlugin::name() const | |||
{ | |||
// some unique id for your language | |||
return "testlang"; | |||
} | |||
</pre> |
Revision as of 20:38, 24 October 2012
.desktop file
In order to find your language support plugin, KDE needs a .desktop file with some meta information.
X-KDE-Library=...
this must be the same as the name of your library, i.e. look into theCMakeLists.txt
for yourkde4_add_plugin
line and use the same nameX-KDE-PluginInfo-Name=...
this must be the same as the name of your plugin in the code, i.e. look into your main plugin .cpp file and find theK_EXPORT_PLUGIN
line, more exactly the first argument to theKAboutData
.
After installing your plugin, make sure to run kbuildsycoca4
. For testing, try duchainify or ktraderclient.
the plugin
A basic plugin's header looks like this:
#include <interfaces/iplugin.h> #include <language/interfaces/ilanguagesupport.h> class KDevTestLangPlugin : public KDevelop::IPlugin, public KDevelop::ILanguageSupport { Q_OBJECT Q_INTERFACES( KDevelop::ILanguageSupport ) public: explicit KDevQmlJsPlugin( QObject* parent, const QVariantList& args = QVariantList() ); virtual KDevelop::ParseJob* createParseJob(const KUrl& url); virtual QString name() const; };
An implementation could look like this:
#include "kdevqmljsplugin.h" #include <KPluginFactory> #include <KAboutData> #include "qmljsparsejob.h" K_PLUGIN_FACTORY(KDevQmlJsSupportFactory, registerPlugin<KDevQmlJsPlugin>(); ) // note: "kdevtestlangsupport" must be the same as you used in X-KDE-PluginInfo-Name! K_EXPORT_PLUGIN(KDevQmlJsSupportFactory(KAboutData("kdevtestlangsupport","kdevtestlang", ki18n("TestLanguage Support"), "0.1", ki18n("Support for Some Test Language"), KAboutData::License_GPL))) KDevQmlJsPlugin::KDevQmlJsPlugin(QObject* parent, const QVariantList& ) : KDevelop::IPlugin( KDevQmlJsSupportFactory::componentData(), parent ) , KDevelop::ILanguageSupport() { // NOTE: this is important! KDEV_USE_EXTENSION_INTERFACE(KDevelop::ILanguageSupport) } KDevelop::ParseJob* KDevTestLangPlugin::createParseJob(const KUrl& url) { return new TestLangParseJob(url, this); } QString KDevTestLangPlugin::name() const { // some unique id for your language return "testlang"; }