[gedit-code-assistance] Moved backends to peas based plugin system
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-code-assistance] Moved backends to peas based plugin system
- Date: Tue, 13 Mar 2012 17:25:18 +0000 (UTC)
commit b3141300ae902f420aa3368397de23906293c229
Author: Jesse van den Kieboom <jesse vandenkieboom epfl ch>
Date: Tue Mar 13 18:24:39 2012 +0100
Moved backends to peas based plugin system
Makefile.am | 2 +-
backends/Makefile.am | 7 +
backends/c/Makefile.am | 40 ++++++
{src/backends => backends}/c/gcp-c-backend.vala | 32 ++---
.../c/gcp-c-compile-args.vala | 0
.../c/gcp-c-config.vala.in | 0
{src/backends => backends}/c/gcp-c-document.vala | 0
.../c/gcp-c-semantic-value.vala | 0
.../c/gcp-c-translation-unit.vala | 0
{src/backends => backends}/c/gcp-c-translator.vala | 0
backends/c/gcpbackendc.plugin.in | 12 ++
configure.ac | 138 ++++++++++++++------
src/Makefile.am | 48 +++++--
src/gcp-backend-implementation.vala | 90 +++++++++++++
src/gcp-backend-manager.vala | 73 +++++++++--
src/gcp-backend.vala | 70 +---------
src/gcp-diagnostic-colors.vala | 2 +-
src/gcp-diagnostic-message.vala | 2 +-
src/gcp-diagnostic-support.vala | 2 +-
src/gcp-diagnostic-tags.vala | 2 +-
src/gcp-document.vala | 2 +-
src/gcp-plugin.vala | 2 +-
src/gcp-scrollbar-marker.vala | 8 +-
src/gcp-semantic-value-support.vala | 2 +-
src/gcp-semantic-value.vala | 2 +-
src/gcp-symbol-browser-support.vala | 2 +-
src/gcp-unsaved-file.vala | 2 +-
src/gcp-view.vala | 4 +-
vapi/config.vapi | 11 ++
vapi/gcp-utils.vapi | 9 ++
vapi/gcp.vapi | 13 --
vapi/gobject-introspection-1.0.vapi | 32 +++++
vapi/libpeas-1.0.vapi | 1 +
33 files changed, 430 insertions(+), 180 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 825c1ae..f4b790a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = data src vapi
+SUBDIRS = data src vapi backends
ACLOCAL_AMFLAGS = -I m4
diff --git a/backends/Makefile.am b/backends/Makefile.am
new file mode 100644
index 0000000..b10ba8a
--- /dev/null
+++ b/backends/Makefile.am
@@ -0,0 +1,7 @@
+SUBDIRS =
+
+if CLANG_ENABLED
+SUBDIRS += c
+endif
+
+-include $(top_srcdir)/git.mk
diff --git a/backends/c/Makefile.am b/backends/c/Makefile.am
new file mode 100644
index 0000000..bb003b2
--- /dev/null
+++ b/backends/c/Makefile.am
@@ -0,0 +1,40 @@
+plugindir = $(GCP_BACKENDS_LIBS_DIR)
+
+plugin_LTLIBRARIES = libgcpbackendc.la
+
+SOURCES = \
+ gcp-c-backend.vala \
+ gcp-c-config.vala \
+ gcp-c-document.vala \
+ gcp-c-compile-args.vala \
+ gcp-c-translation-unit.vala \
+ gcp-c-semantic-value.vala \
+ gcp-c-translator.vala
+
+BUILT_SOURCES = $(vala_sources:.vala=.c)
+
+libgcpbackendc_la_SOURCES = $(SOURCES)
+
+libgcpbackendc_la_CFLAGS = $(GCP_CFLAGS) $(LLVM_CFLAGS) $(GEDIT_CFLAGS) -I$(top_srcdir)/src -w
+libgcpbackendc_la_LDFLAGS = -module -shared -avoid-version $(GCP_LIBS) $(LLVM_LIBS)
+
+valapkgs = gio-2.0 gee-1.0 clang gcp gtk+-3.0 gtksourceview-3.0 gedit-3.0 libpeas-1.0
+
+VALAFLAGS = \
+ --vapidir $(top_srcdir)/src \
+ --vapidir $(top_srcdir)/vapi \
+ $(foreach pkg,$(valapkgs),--pkg $(pkg))
+
+plugin_DATA = gcpbackendc.plugin
+
+EXTRA_DIST = \
+ gcpbackendc.plugin
+
+CLEANFILES = \
+ libgcpbackendc_la_vala.stamp \
+ $(BUILT_SOURCES)
+
+install-data-hook:
+ rm -f $(GCP_BACKENDS_LIBS_DIR)/libgcpbackendc.la
+
+-include $(top_srcdir)/git.mk
diff --git a/src/backends/c/gcp-c-backend.vala b/backends/c/gcp-c-backend.vala
similarity index 92%
rename from src/backends/c/gcp-c-backend.vala
rename to backends/c/gcp-c-backend.vala
index 2785940..e31a444 100644
--- a/src/backends/c/gcp-c-backend.vala
+++ b/backends/c/gcp-c-backend.vala
@@ -22,20 +22,14 @@ using Gee;
namespace Gcp.C
{
-class Backend : Gcp.Backend
+class Backend : Gcp.BackendImplementation
{
- private static string[] s_langs;
private CX.Index d_index;
private CompileArgs d_compileArgs;
private HashMap<File, LinkedList<Document>> d_documentMap;
private uint d_changedId;
- static construct
- {
- s_langs = {"c", "cpp", "chdr", "objc"};
- }
-
- public Backend()
+ construct
{
d_index = new CX.Index(true, false);
d_compileArgs = new CompileArgs();
@@ -125,21 +119,13 @@ class Backend : Gcp.Backend
}
}
- public override string[] supported_languages
- {
- get
- {
- return s_langs;
- }
- }
-
private UnsavedFile[] unsaved_files
{
owned get
{
ArrayList<Gcp.Document> docs = new ArrayList<Gcp.Document>();
- foreach (Gcp.Document doc in documents)
+ foreach (Gcp.Document doc in this)
{
if (doc.location != null && doc.text != null)
{
@@ -172,7 +158,7 @@ class Backend : Gcp.Backend
{
UnsavedFile[] uf = unsaved_files;
- foreach (Gcp.Document doc in documents)
+ foreach (Gcp.Document doc in this)
{
if (!doc.tainted)
{
@@ -231,4 +217,14 @@ class Backend : Gcp.Backend
}
+[ModuleInit]
+public void peas_register_types (TypeModule module)
+{
+ Peas.ObjectModule mod = module as Peas.ObjectModule;
+
+ mod.register_extension_type (typeof (Gcp.Backend),
+ typeof (Gcp.C.Backend));
+}
+
+
/* vi:ex:ts=4 */
diff --git a/src/backends/c/gcp-c-compile-args.vala b/backends/c/gcp-c-compile-args.vala
similarity index 100%
rename from src/backends/c/gcp-c-compile-args.vala
rename to backends/c/gcp-c-compile-args.vala
diff --git a/src/gcp-config.vala.in b/backends/c/gcp-c-config.vala.in
similarity index 100%
rename from src/gcp-config.vala.in
rename to backends/c/gcp-c-config.vala.in
diff --git a/src/backends/c/gcp-c-document.vala b/backends/c/gcp-c-document.vala
similarity index 100%
rename from src/backends/c/gcp-c-document.vala
rename to backends/c/gcp-c-document.vala
diff --git a/src/backends/c/gcp-c-semantic-value.vala b/backends/c/gcp-c-semantic-value.vala
similarity index 100%
rename from src/backends/c/gcp-c-semantic-value.vala
rename to backends/c/gcp-c-semantic-value.vala
diff --git a/src/backends/c/gcp-c-translation-unit.vala b/backends/c/gcp-c-translation-unit.vala
similarity index 100%
rename from src/backends/c/gcp-c-translation-unit.vala
rename to backends/c/gcp-c-translation-unit.vala
diff --git a/src/backends/c/gcp-c-translator.vala b/backends/c/gcp-c-translator.vala
similarity index 100%
rename from src/backends/c/gcp-c-translator.vala
rename to backends/c/gcp-c-translator.vala
diff --git a/backends/c/gcpbackendc.plugin.in b/backends/c/gcpbackendc.plugin.in
new file mode 100644
index 0000000..4159bc3
--- /dev/null
+++ b/backends/c/gcpbackendc.plugin.in
@@ -0,0 +1,12 @@
+[Plugin]
+Module=gcpbackendc
+IAge=3
+Name=Code Assistance C Backend
+Hidden=yes
+Builtin=yes
+Description=Code assistance backend for the C, C++ and Objective-C languages
+Authors=Jesse van den Kieboom <jessevdk gnome org>
+Copyright=Copyright  2012 Jesse van den Kieboom
+Website=http://www.gedit.org
+Version= VERSION@
+X-Languages=c,cpp,objc,chdr
diff --git a/configure.ac b/configure.ac
index 61e0134..0088f89 100644
--- a/configure.ac
+++ b/configure.ac
@@ -17,7 +17,7 @@ AM_PROG_CC_STDC
AC_HEADER_STDC
AM_PROG_LIBTOOL
-AM_INIT_AUTOMAKE([1.11 tar-ustar dist-xz no-dist-gzip -Wno-portability subdir-objects])
+AM_INIT_AUTOMAKE([1.11 tar-ustar dist-xz no-dist-gzip -Wno-portability])
AM_MAINTAINER_MODE([enable])
AM_SILENT_RULES([yes])
@@ -50,44 +50,52 @@ AC_SUBST(GCP_CFLAGS)
AC_PATH_PROG([LLVM_CONFIG], [llvm-config], [])
if test "x$LLVM_CONFIG" = "x"; then
- AC_MSG_ERROR([could not find llvm-config])
+ AC_MSG_WARN([could not find llvm-config])
+else
+ dnl find out the libdir of llvm
+ LLVM_LIBS=$($LLVM_CONFIG --ldflags)
+ LLVM_CFLAGS=$($LLVM_CONFIG --cflags)
+
+ dnl ================================================================
+ dnl Find clang headers and lib
+ dnl ================================================================
+ OLDCFLAGS="$CFLAGS"
+ OLDLDFLAGS="$LDFLAGS"
+
+ CFLAGS="$OLDCFLAGS $LLVM_CFLAGS"
+ LDFLAGS="$OLDLDFLAGS $LLVM_LIBS"
+
+ AC_CHECK_LIB([clang],
+ [clang_createIndex],
+ [LLVM_LIBS="$LLVM_LIBS -lclang"
+ clang_enabled="yes"],
+ [AC_MSG_WARN([could not find clang library])
+ clang_enabled="no"])
+
+ if test "x$clang_enabled" = "xyes"; then
+ AC_CHECK_HEADER([clang-c/Index.h],
+ [],
+ [AC_MSG_WARN([could not find clang header Index.h])
+ clang_enabled="no"])
+ fi
+
+ if test "x$clang_enabled" = "xyes"; then
+ LLVM_LIBS="$LLVM_LIBS -lclang"
+ fi
+
+ AC_SUBST(LLVM_CFLAGS)
+ AC_SUBST(LLVM_LIBS)
+
+ CFLAGS="$OLDCFLAGS"
+ LDFLAGS="$OLDLDFLAGS"
+
+ LLVM_VERSION=$($LLVM_CONFIG --version)
+ AC_DEFINE_UNQUOTED([LLVM_VERSION], "$LLVM_VERSION", [LLVM version])
+
+ AC_SUBST(LLVM_VERSION)
fi
-dnl find out the libdir of llvm
-LLVM_LIBS=$($LLVM_CONFIG --ldflags)
-LLVM_CFLAGS=$($LLVM_CONFIG --cflags)
-
-dnl ================================================================
-dnl Find clang headers and lib
-dnl ================================================================
-
-OLDCFLAGS="$CFLAGS"
-OLDLDFLAGS="$LDFLAGS"
-
-CFLAGS="$OLDCFLAGS $LLVM_CFLAGS"
-LDFLAGS="$OLDLDFLAGS $LLVM_LIBS"
-
-AC_CHECK_LIB([clang],
- [clang_createIndex],
- [],
- [AC_MSG_ERROR([could not find clang library])])
-
-AC_CHECK_HEADER([clang-c/Index.h],
- [],
- [AC_MSG_ERROR([could not find clang header Index.h])])
-
-LLVM_LIBS="$LLVM_LIBS -lclang"
-
-AC_SUBST(LLVM_CFLAGS)
-AC_SUBST(LLVM_LIBS)
-
-CFLAGS="$OLDCFLAGS"
-LDFLAGS="$OLDLDFLAGS"
-
-LLVM_VERSION=$($LLVM_CONFIG --version)
-AC_DEFINE_UNQUOTED([LLVM_VERSION], "$LLVM_VERSION", [LLVM version])
-
-AC_SUBST(LLVM_VERSION)
+AM_CONDITIONAL(CLANG_ENABLED, test "x$clang_enabled" = "xyes")
AC_ARG_ENABLE([local],
AS_HELP_STRING([--enable-local],[enable local install (in user directory)]),
@@ -99,6 +107,12 @@ dnl Find gedit
dnl ================================================================
PKG_CHECK_MODULES([GEDIT], [gedit >= 3.0])
+GEDIT_GIR_DIR="${datadir}/gedit/gir-1.0"
+AC_SUBST(GEDIT_GIR_DIR)
+
+GEDIT_API_VERSION=3.0
+AC_SUBST(GEDIT_API_VERSION)
+
if test "x$enable_local" = "xyes"; then
geditlibdir="$HOME/.local/share"
geditdatadir="$HOME/.local/share"
@@ -110,19 +124,63 @@ fi
GEDIT_PLUGIN_DIR="$geditlibdir/gedit/plugins"
GEDIT_DATA_DIR="$geditdatadir/gedit/plugins"
+GCP_BACKENDS_LIBS_DIR="$GEDIT_PLUGIN_DIR/gcp/backends"
+GCP_BACKENDS_DATA_DIR="$GEDIT_DATA_DIR/gcp/backends"
+
+GCP_LIBS_DIR="$GEDIT_PLUGIN_DIR/gcp"
+AC_SUBST(GCP_LIBS_DIR)
+
+GCP_DATA_DIR="$GEDIT_DATA_DIR/gcp"
+AC_SUBST(GCP_DATA_DIR)
AC_SUBST(GEDIT_PLUGIN_DIR)
AC_SUBST(GEDIT_DATA_DIR)
+AC_SUBST(GCP_BACKENDS_LIBS_DIR)
+AC_SUBST(GCP_BACKENDS_DATA_DIR)
+
AC_SUBST(GEDIT_CFLAGS)
AC_SUBST(GEDIT_LIBS)
+GOBJECT_INTROSPECTION_CHECK([0.9.3])
+
+dnl adl_RECURSIVE_EVAL(VALUE, RESULT)
+dnl =================================
+dnl Interpolate the VALUE in loop until it doesn't change,
+dnl and set the result to $RESULT.
+dnl WARNING: It's easy to get an infinite loop with some unsane input.
+AC_DEFUN([adl_RECURSIVE_EVAL],
+[_lcl_receval="$1"
+$2=`(test "x$prefix" = xNONE && prefix="$ac_default_prefix"
+ test "x$exec_prefix" = xNONE && exec_prefix="${prefix}"
+ _lcl_receval_old=''
+ while test "[$]_lcl_receval_old" != "[$]_lcl_receval"; do
+ _lcl_receval_old="[$]_lcl_receval"
+ eval _lcl_receval="\"[$]_lcl_receval\""
+ done
+ echo "[$]_lcl_receval")`])
+
+adl_RECURSIVE_EVAL("$GCP_BACKENDS_LIBS_DIR", [GCP_BACKENDS_DIR_EX])
+adl_RECURSIVE_EVAL("$GCP_BACKENDS_DATA_DIR", [GCP_BACKENDS_DATA_DIR_EX])
+
+adl_RECURSIVE_EVAL("$GCP_LIBS_DIR", [GCP_LIBS_DIR_EX])
+adl_RECURSIVE_EVAL("$GCP_DATA_DIR", [GCP_DATA_DIR_EX])
+
+AC_DEFINE_UNQUOTED([GCP_BACKENDS_DIR], "$GCP_BACKENDS_DIR_EX", [Backends dir])
+AC_DEFINE_UNQUOTED([GCP_BACKENDS_DATA_DIR], "$GCP_BACKENDS_DATA_DIR_EX", [Backends data dir])
+
+AC_DEFINE_UNQUOTED([GCP_LIBS_DIR], "$GCP_LIBS_DIR_EX", [Library dir])
+AC_DEFINE_UNQUOTED([GCP_DATA_DIR], "$GCP_DATA_DIR_EX", [Data dir])
+
AC_CONFIG_FILES([
Makefile
data/Makefile
data/gcp.plugin
src/Makefile
-src/gcp-config.vala
+backends/Makefile
+backends/c/Makefile
+backends/c/gcp-c-config.vala
+backends/c/gcpbackendc.plugin
vapi/Makefile
])
@@ -138,6 +196,8 @@ Configuration:
valac: $VALAC
gedit plugin dir: $GEDIT_PLUGIN_DIR
gedit data dir: $GEDIT_DATA_DIR
- llvm version: $LLVM_VERSION
+
+ backends:
+ c: $clang_enabled ($LLVM_VERSION)
"
diff --git a/src/Makefile.am b/src/Makefile.am
index 8c3208d..5c9759b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,6 +20,7 @@ vala_sources = \
gcp-document.vala \
gcp-scrollbar-marker.vala \
gcp-backend.vala \
+ gcp-backend-implementation.vala \
gcp-backend-manager.vala \
gcp-unsaved-file.vala \
gcp-semantic-value.vala \
@@ -31,16 +32,7 @@ vala_sources = \
gcp-diagnostic-tags.vala \
gcp-diagnostic-support.vala \
gcp-diagnostic-message.vala \
- gcp-log.vala \
- gcp-config.vala
-
-vala_sources += \
- backends/c/gcp-c-backend.vala \
- backends/c/gcp-c-document.vala \
- backends/c/gcp-c-compile-args.vala \
- backends/c/gcp-c-translation-unit.vala \
- backends/c/gcp-c-semantic-value.vala \
- backends/c/gcp-c-translator.vala
+ gcp-log.vala
SOURCES = \
$(vala_sources) \
@@ -53,21 +45,47 @@ BUILT_SOURCES = $(vala_sources:.vala=.c)
libgcp_la_SOURCES = $(SOURCES)
-libgcp_la_CFLAGS = $(GCP_CFLAGS) $(GEDIT_CFLAGS) $(LLVM_CFLAGS) -w
-libgcp_la_LDFLAGS = -module -shared -avoid-version $(GCP_LIBS) $(LLVM_LIBS) $(GEDIT_LIBS)
+libgcp_la_CFLAGS = $(GCP_CFLAGS) $(GEDIT_CFLAGS) -I$(top_srcdir) -w
+libgcp_la_LDFLAGS = -module -shared -avoid-version $(GCP_LIBS) $(GEDIT_LIBS)
+
+valapkgs = \
+ gio-2.0 \
+ gee-1.0 \
+ gcp-utils \
+ gtk+-3.0 \
+ gtksourceview-3.0 \
+ gedit-3.0 \
+ libpeas-1.0 \
+ gobject-introspection-1.0 \
+ config
+
+INTROSPECTION_COMPILER_ARGS = --includedir $(GEDIT_GIR_DIR)
+
+-include $(INTROSPECTION_MAKEFILE)
+
+girdir = $(GCP_DATA_DIR)/gir-1.0
+gir_DATA = Gcp-3.0.gir
+
+typelibdir = $(GCP_LIBS_DIR)/girepository-1.0
+typelib_DATA = $(gir_DATA:.gir=.typelib)
-valapkgs = gio-2.0 gee-1.0 clang gcp gtk+-3.0 gtksourceview-3.0 gedit-3.0 libpeas-1.0
+headerdir = $(prefix)/include/gedit-$(GEDIT_API_VERSION)/gcp
+header_DATA = gcp.h
VALAFLAGS = \
--vapidir $(top_srcdir)/vapi \
+ --header gcp.h \
+ --vapi gcp.vapi \
+ --library libgcp \
+ --gir Gcp-3.0.gir \
$(foreach pkg,$(valapkgs),--pkg $(pkg))
CLEANFILES = \
libgcp_la_vala.stamp \
$(BUILT_SOURCES)
-MAINTAINERCLEANFILES = $(generated)
+MAINTAINERCLEANFILES = $(generated) $(gir_DATA) $(typelib_DATA)
-EXTRA_DIST = $(NOINSTHFILES)
+EXTRA_DIST = $(NOINSTHFILES) $(gir_DATA) $(typelib_DATA)
-include $(top_srcdir)/git.mk
diff --git a/src/gcp-backend-implementation.vala b/src/gcp-backend-implementation.vala
new file mode 100644
index 0000000..8bc1bb0
--- /dev/null
+++ b/src/gcp-backend-implementation.vala
@@ -0,0 +1,90 @@
+/*
+ * This file is part of gedit-code-assistant.
+ *
+ * Copyright (C) 2011 - Jesse van den Kieboom
+ *
+ * gedit-code-assistant is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * gedit-code-assistant is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gedit-code-assistant. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gee;
+
+namespace Gcp
+{
+
+public abstract class BackendImplementation : Object, Backend
+{
+ private ArrayList<Document> d_documents;
+
+ public int size
+ {
+ get { return d_documents.size; }
+ }
+
+ public new Document get(int idx)
+ {
+ return d_documents[idx];
+ }
+
+ construct
+ {
+ d_documents = new ArrayList<Document>();
+ }
+
+ public abstract Document create_document(Gedit.Document document);
+
+ public Document ?register_document(Gedit.Document ?document)
+ {
+ if (document == null)
+ {
+ return null;
+ }
+
+ Document ret = create_document(document);
+ d_documents.add(ret);
+
+ ret.changed.connect(on_document_changed);
+
+ return ret;
+ }
+
+ public void unregister_document(Document ?document)
+ {
+ if (document == null)
+ {
+ return;
+ }
+
+ destroy_document(document);
+ d_documents.remove(document);
+ }
+
+ protected virtual void destroy_document(Document document)
+ {
+ document.changed.disconnect(on_document_changed);
+ }
+
+ protected virtual void on_document_changed(Document doc)
+ {
+ SymbolBrowserSupport? s = doc as SymbolBrowserSupport;
+
+ if (s != null)
+ {
+ s.symbol_browser.tainted = true;
+ }
+ }
+}
+
+}
+
+/* vi:ex:ts=4 */
diff --git a/src/gcp-backend-manager.vala b/src/gcp-backend-manager.vala
index 940ac16..5f002cb 100644
--- a/src/gcp-backend-manager.vala
+++ b/src/gcp-backend-manager.vala
@@ -26,38 +26,85 @@ class BackendManager
{
private static BackendManager s_instance;
- private HashMap<string, Backend> d_backends;
-
- private BackendManager()
+ class BackendInfo : Object
{
- d_backends = new HashMap<string, Backend>();
+ public Backend ?backend { get; set; }
+ public Peas.PluginInfo info { get; set; }
- register_backends();
+ public BackendInfo(Peas.PluginInfo info)
+ {
+ Object(info: info);
+ }
}
- private void register_backend(Backend backend)
+ private HashMap<string, BackendInfo> d_backends;
+ private Peas.Engine d_engine;
+
+ private BackendManager()
{
- foreach (string lang in backend.supported_languages)
+ d_backends = new HashMap<string, BackendInfo>();
+
+ d_engine = new Peas.Engine();
+
+ d_engine.add_search_path(Gcp.Config.GCP_BACKENDS_DIR,
+ Gcp.Config.GCP_BACKENDS_DATA_DIR);
+
+ d_engine.enable_loader("python");
+
+ // require the gcp gir
+ string tpdir = Path.build_filename(Gcp.Config.GCP_LIBS_DIR,
+ "girepository-1.0");
+
+ var repo = Introspection.Repository.get_default();
+
+ try
+ {
+ repo.require_private(tpdir, "Gcp", "3.0");
+ }
+ catch (Introspection.RepositoryError error)
{
- d_backends[lang] = backend;
+ warning("Could not load Gcp typelib: %s", error.message);
}
+
+ register_backends();
}
private void register_backends()
{
- register_backend(new C.Backend());
+ foreach (Peas.PluginInfo info in d_engine.get_plugin_list())
+ {
+ string? langs = info.get_external_data("Languages");
+
+ if (langs == null)
+ {
+ continue;
+ }
+
+ BackendInfo binfo = new BackendInfo(info);
+
+ foreach (string lang in langs.split(","))
+ {
+ d_backends[lang] = binfo;
+ }
+ }
}
public Backend? get(string language)
{
- if (d_backends.has_key(language))
+ if (!d_backends.has_key(language))
{
- return d_backends[language];
+ return null;
}
- else
+
+ BackendInfo info = d_backends[language];
+
+ if (info.backend == null)
{
- return null;
+ d_engine.load_plugin(info.info);
+ info.backend = (Gcp.Backend)d_engine.create_extension(info.info, typeof(Gcp.Backend));
}
+
+ return info.backend;
}
public static BackendManager instance
diff --git a/src/gcp-backend.vala b/src/gcp-backend.vala
index 77a87a0..65333cf 100644
--- a/src/gcp-backend.vala
+++ b/src/gcp-backend.vala
@@ -17,76 +17,16 @@
* along with gedit-code-assistant. If not, see <http://www.gnu.org/licenses/>.
*/
-using Gee;
-
namespace Gcp
{
-abstract class Backend : Object
+public interface Backend : Object
{
- private ArrayList<Document> d_documents;
-
- public Backend()
- {
- d_documents = new ArrayList<Document>();
- }
-
- public abstract string[] supported_languages
- {
- get;
- }
-
- public Gee.List<Document> documents
- {
- owned get
- {
- return d_documents.read_only_view;
- }
- }
-
- protected abstract Document create_document(Gedit.Document document);
-
- public Document ?register(Gedit.Document ?document)
- {
- if (document == null)
- {
- return null;
- }
-
- Document ret = create_document(document);
- d_documents.add(ret);
-
- ret.changed.connect(on_document_changed);
-
- return ret;
- }
-
- protected virtual void destroy_document(Document document)
- {
- document.changed.disconnect(on_document_changed);
- }
-
- public virtual void unregister(Document ?document)
- {
- if (document == null)
- {
- return;
- }
-
- destroy_document(document);
-
- d_documents.remove(document);
- }
-
- protected virtual void on_document_changed(Document doc)
- {
- SymbolBrowserSupport? s = doc as SymbolBrowserSupport;
+ public abstract int size { get; }
+ public abstract new Document get(int idx);
- if (s != null)
- {
- s.symbol_browser.tainted = true;
- }
- }
+ public abstract Document ?register_document(Gedit.Document ?document);
+ public abstract void unregister_document(Document ?document);
}
}
diff --git a/src/gcp-diagnostic-colors.vala b/src/gcp-diagnostic-colors.vala
index ec9c41a..bc9f02c 100644
--- a/src/gcp-diagnostic-colors.vala
+++ b/src/gcp-diagnostic-colors.vala
@@ -21,7 +21,7 @@ using Gtk;
namespace Gcp
{
- class DiagnosticColors
+ public class DiagnosticColors
{
private Gdk.RGBA d_errorColor;
private Gdk.RGBA d_warningColor;
diff --git a/src/gcp-diagnostic-message.vala b/src/gcp-diagnostic-message.vala
index 982fd5e..1ec3c37 100644
--- a/src/gcp-diagnostic-message.vala
+++ b/src/gcp-diagnostic-message.vala
@@ -4,7 +4,7 @@ using Gee;
namespace Gcp
{
-class DiagnosticMessage : EventBox
+public class DiagnosticMessage : EventBox
{
private Diagnostic[] d_diagnostics;
private Box? d_vbox;
diff --git a/src/gcp-diagnostic-support.vala b/src/gcp-diagnostic-support.vala
index 57ec992..0b52f3d 100644
--- a/src/gcp-diagnostic-support.vala
+++ b/src/gcp-diagnostic-support.vala
@@ -22,7 +22,7 @@ using Gee;
namespace Gcp
{
-interface DiagnosticSupport : Document
+public interface DiagnosticSupport : Document
{
public abstract DiagnosticTags tags { get; set; }
diff --git a/src/gcp-diagnostic-tags.vala b/src/gcp-diagnostic-tags.vala
index 29ecd06..f9abc2f 100644
--- a/src/gcp-diagnostic-tags.vala
+++ b/src/gcp-diagnostic-tags.vala
@@ -30,7 +30,7 @@ namespace Gcp
private TextTag? d_locationTag;
private TextTag? d_fixitTag;
- class DiagnosticTags
+ public class DiagnosticTags
{
public DiagnosticTags(TextView view)
{
diff --git a/src/gcp-document.vala b/src/gcp-document.vala
index a308027..f1a75c5 100644
--- a/src/gcp-document.vala
+++ b/src/gcp-document.vala
@@ -22,7 +22,7 @@ using Gtk;
namespace Gcp
{
-class Document : GLib.Object
+public class Document : GLib.Object
{
private Gedit.Document d_document;
private bool d_untitled;
diff --git a/src/gcp-plugin.vala b/src/gcp-plugin.vala
index 5e98460..99189fa 100644
--- a/src/gcp-plugin.vala
+++ b/src/gcp-plugin.vala
@@ -18,7 +18,7 @@
*/
[ModuleInit]
-public void peas_register_types (TypeModule module)
+internal void peas_register_types (TypeModule module)
{
Peas.ObjectModule mod = module as Peas.ObjectModule;
diff --git a/src/gcp-scrollbar-marker.vala b/src/gcp-scrollbar-marker.vala
index 46150cc..54413b3 100644
--- a/src/gcp-scrollbar-marker.vala
+++ b/src/gcp-scrollbar-marker.vala
@@ -93,14 +93,14 @@ public class ScrollbarMarker
{
StyleContext ctx = d_scrollbar.get_style_context();
- int stepper_size = UtilsC.get_style_property_int(ctx,
+ int stepper_size = GcpUtilsC.get_style_property_int(ctx,
"stepper-size");
- int stepper_spacing = UtilsC.get_style_property_int(ctx,
+ int stepper_spacing = GcpUtilsC.get_style_property_int(ctx,
"stepper-spacing");
- d_border = UtilsC.get_style_property_int(ctx, "trough-border");
- d_width = UtilsC.get_style_property_int(ctx, "slider-width");
+ d_border = GcpUtilsC.get_style_property_int(ctx, "trough-border");
+ d_width = GcpUtilsC.get_style_property_int(ctx, "slider-width");
d_spacing = stepper_size + stepper_spacing + 2;
}
diff --git a/src/gcp-semantic-value-support.vala b/src/gcp-semantic-value-support.vala
index f715354..92c121b 100644
--- a/src/gcp-semantic-value-support.vala
+++ b/src/gcp-semantic-value-support.vala
@@ -1,7 +1,7 @@
namespace Gcp
{
-interface SemanticValueSupport : Gcp.Document
+public interface SemanticValueSupport : Gcp.Document
{
public delegate void WithSemanticValueCallback(SourceIndex<SemanticValue> diagnostics);
diff --git a/src/gcp-semantic-value.vala b/src/gcp-semantic-value.vala
index 63e9cfc..55873c1 100644
--- a/src/gcp-semantic-value.vala
+++ b/src/gcp-semantic-value.vala
@@ -1,7 +1,7 @@
namespace Gcp
{
-abstract class SemanticValue : Object, SourceRangeSupport
+public abstract class SemanticValue : Object, SourceRangeSupport
{
public enum Kind
{
diff --git a/src/gcp-symbol-browser-support.vala b/src/gcp-symbol-browser-support.vala
index f25ad07..4423483 100644
--- a/src/gcp-symbol-browser-support.vala
+++ b/src/gcp-symbol-browser-support.vala
@@ -27,7 +27,7 @@ namespace Gcp
* browsing.
*
*/
-interface SymbolBrowserSupport : Document
+public interface SymbolBrowserSupport : Document
{
/**
* Get symbol browser
diff --git a/src/gcp-unsaved-file.vala b/src/gcp-unsaved-file.vala
index 7a9355c..1f718bf 100644
--- a/src/gcp-unsaved-file.vala
+++ b/src/gcp-unsaved-file.vala
@@ -20,7 +20,7 @@
namespace Gcp
{
-struct UnsavedFile
+public struct UnsavedFile
{
public string filename;
public string contents;
diff --git a/src/gcp-view.vala b/src/gcp-view.vala
index e543594..0cb5fbd 100644
--- a/src/gcp-view.vala
+++ b/src/gcp-view.vala
@@ -324,7 +324,7 @@ class View : Object
d_buffer.cursor_moved.disconnect(on_cursor_semantics_moved);
}
- d_backend.unregister(d_document);
+ d_backend.unregister_document(d_document);
}
d_backend = null;
@@ -413,7 +413,7 @@ class View : Object
if (d_view.buffer != null)
{
- d_document = d_backend.register(d_view.buffer as Gedit.Document);
+ d_document = d_backend.register_document(d_view.buffer as Gedit.Document);
DiagnosticSupport? diag = d_document as DiagnosticSupport;
diff --git a/vapi/config.vapi b/vapi/config.vapi
new file mode 100644
index 0000000..70216bb
--- /dev/null
+++ b/vapi/config.vapi
@@ -0,0 +1,11 @@
+[CCode(cprefix = "", lower_case_cprefix = "", cheader_filename = "config.h")]
+namespace Gcp.Config
+{
+ public const string GCP_BACKENDS_DIR;
+ public const string GCP_BACKENDS_DATA_DIR;
+ public const string GCP_LIBS_DIR;
+ public const string GCP_DATA_DIR;
+ public const string VERSION;
+}
+
+// ex:ts=4 noet
diff --git a/vapi/gcp-utils.vapi b/vapi/gcp-utils.vapi
new file mode 100644
index 0000000..9ef2391
--- /dev/null
+++ b/vapi/gcp-utils.vapi
@@ -0,0 +1,9 @@
+[CCode(lower_case_cprefix = "gcp_utils_c", cheader_filename = "gcp-utils-c.h")]
+namespace GcpUtilsC
+{
+ [CCode (cname = "gcp_utils_c_get_style_property_int")]
+ public static int get_style_property_int(Gtk.StyleContext context,
+ string name);
+}
+
+/* vi:ex:ts=4 */
diff --git a/vapi/gobject-introspection-1.0.vapi b/vapi/gobject-introspection-1.0.vapi
new file mode 100644
index 0000000..4d67432
--- /dev/null
+++ b/vapi/gobject-introspection-1.0.vapi
@@ -0,0 +1,32 @@
+[CCode (cprefix = "GI", lower_case_cprefix = "g_i", cheader_filename = "girepository.h")]
+namespace Introspection
+{
+ [CCode (cprefix = "G_IREPOSITORY_ERROR_")]
+ public errordomain RepositoryError {
+ TYPELIB_NOT_FOUND,
+ NAMESPACE_MISMATCH,
+ NAMESPACE_VERSION_CONFLICT,
+ LIBRARY_NOT_FOUND
+ }
+
+ [CCode (cname="int", cprefix = "G_IREPOSITORY_LOAD_FLAG_")]
+ public enum RepositoryLoadFlags {
+ LAZY = 1
+ }
+
+ [CCode (ref_function = "", unref_function = "")]
+ public class Repository {
+ public static unowned Repository get_default();
+ public static void prepend_search_path(string directory);
+ public static unowned GLib.SList<string> get_search_path();
+
+ public unowned Typelib? require(string namespace_, string? version = null, RepositoryLoadFlags flags = 0) throws RepositoryError;
+ public unowned Typelib? require_private(string typelib_dir, string namespace_, string? version = null, RepositoryLoadFlags flags = 0) throws RepositoryError;
+ }
+
+ [Compact]
+ [CCode (cname = "GTypelib", cprefix = "g_typelib_", free_function = "g_typelib_free")]
+ public class Typelib {
+ public unowned string get_namespace();
+ }
+}
diff --git a/vapi/libpeas-1.0.vapi b/vapi/libpeas-1.0.vapi
index 9e3ff77..1db1265 100644
--- a/vapi/libpeas-1.0.vapi
+++ b/vapi/libpeas-1.0.vapi
@@ -88,6 +88,7 @@ namespace Peas {
public unowned string get_name ();
public unowned string get_version ();
public unowned string get_website ();
+ public string? get_external_data (string key);
public bool has_dependency (string module_name);
public bool is_available () throws GLib.Error;
public bool is_builtin ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]