[gnome-builder] gca: add preference to enable pylint in GNOME Code Assistance



commit 6005311aa31d98555464c0fdfc20ccc5282f83b1
Author: Christian Hergert <christian hergert me>
Date:   Sun Feb 21 17:41:32 2016 -0800

    gca: add preference to enable pylint in GNOME Code Assistance
    
    This requires cd0f439a2cb67a1f7f0a6f468c33db5731321402 in the
    gnome-code-assistance module for systems that are missing pylint.

 plugins/gnome-code-assistance/Makefile.am          |   12 +++-
 plugins/gnome-code-assistance/gca-plugin.c         |    8 ++-
 .../ide-gca-diagnostic-provider.c                  |   24 +++++-
 .../ide-gca-preferences-addin.c                    |   86 ++++++++++++++++++++
 .../ide-gca-preferences-addin.h                    |   32 +++++++
 ...gnome.builder.gnome-code-assistance.gschema.xml |    9 ++
 6 files changed, 165 insertions(+), 6 deletions(-)
---
diff --git a/plugins/gnome-code-assistance/Makefile.am b/plugins/gnome-code-assistance/Makefile.am
index 0edef96..52d4c89 100644
--- a/plugins/gnome-code-assistance/Makefile.am
+++ b/plugins/gnome-code-assistance/Makefile.am
@@ -1,7 +1,5 @@
 if ENABLE_GNOME_CODE_ASSISTANCE_PLUGIN
 
-EXTRA_DIST = $(plugin_DATA)
-
 plugindir = $(libdir)/gnome-builder/plugins
 plugin_LTLIBRARIES = libgnome-code-assistance-plugin.la
 dist_plugin_DATA = gnome-code-assistance.plugin
@@ -16,6 +14,8 @@ libgnome_code_assistance_plugin_la_SOURCES = \
        gca-plugin.c \
        ide-gca-diagnostic-provider.c \
        ide-gca-diagnostic-provider.h \
+       ide-gca-preferences-addin.c \
+       ide-gca-preferences-addin.h \
        ide-gca-service.c \
        ide-gca-service.h \
        $(NULL)
@@ -31,6 +31,14 @@ libgnome_code_assistance_plugin_la_LDFLAGS = \
        -module \
        $(NULL)
 
+gsettings_SCHEMAS = org.gnome.builder.gnome-code-assistance.gschema.xml
+
+.PRECIOUS: $(gsettings_SCHEMAS)
+
+ GSETTINGS_RULES@
+
+EXTRA_DIST = $(gsettings_SCHEMAS) $(plugin_DATA)
+
 include $(top_srcdir)/plugins/Makefile.plugin
 
 endif
diff --git a/plugins/gnome-code-assistance/gca-plugin.c b/plugins/gnome-code-assistance/gca-plugin.c
index 159a517..5300e35 100644
--- a/plugins/gnome-code-assistance/gca-plugin.c
+++ b/plugins/gnome-code-assistance/gca-plugin.c
@@ -17,11 +17,11 @@
  */
 
 #include <libpeas/peas.h>
+#include <ide.h>
 
-#include "ide-diagnostic-provider.h"
 #include "ide-gca-diagnostic-provider.h"
+#include "ide-gca-preferences-addin.h"
 #include "ide-gca-service.h"
-#include "ide-service.h"
 
 void
 peas_register_types (PeasObjectModule *module)
@@ -33,4 +33,8 @@ peas_register_types (PeasObjectModule *module)
   peas_object_module_register_extension_type (module,
                                               IDE_TYPE_DIAGNOSTIC_PROVIDER,
                                               IDE_TYPE_GCA_DIAGNOSTIC_PROVIDER);
+
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_PREFERENCES_ADDIN,
+                                              IDE_TYPE_GCA_PREFERENCES_ADDIN);
 }
diff --git a/plugins/gnome-code-assistance/ide-gca-diagnostic-provider.c 
b/plugins/gnome-code-assistance/ide-gca-diagnostic-provider.c
index d8bd48b..1184a94 100644
--- a/plugins/gnome-code-assistance/ide-gca-diagnostic-provider.c
+++ b/plugins/gnome-code-assistance/ide-gca-diagnostic-provider.c
@@ -55,6 +55,8 @@ G_DEFINE_TYPE_EXTENDED (IdeGcaDiagnosticProvider, ide_gca_diagnostic_provider, I
                         G_IMPLEMENT_INTERFACE (IDE_TYPE_DIAGNOSTIC_PROVIDER,
                                                diagnostic_provider_iface_init))
 
+static GSettings *gca_settings;
+
 static void
 diagnose_state_free (gpointer data)
 {
@@ -312,12 +314,31 @@ parse_cb (GObject      *object,
   IDE_EXIT;
 }
 
+static GVariant *
+get_parse_options (void)
+{
+  if (G_UNLIKELY (gca_settings == NULL))
+    gca_settings = g_settings_new ("org.gnome.builder.gnome-code-assistance");
+
+  if (g_settings_get_boolean (gca_settings, "enable-pylint"))
+    {
+      GVariantBuilder builder;
+
+      g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
+      g_variant_builder_add (&builder, "{sv}", "pylint", g_variant_new_boolean (TRUE));
+      return g_variant_builder_end (&builder);
+    }
+
+  return g_variant_new ("a{sv}", 0);
+}
+
 static void
 get_proxy_cb (GObject      *object,
               GAsyncResult *result,
               gpointer      user_data)
 {
   g_autoptr(GTask) task = user_data;
+  g_autoptr(GVariant) options = NULL;
   IdeGcaService *service = (IdeGcaService *)object;
   DiagnoseState *state;
   GcaService *proxy;
@@ -326,7 +347,6 @@ get_proxy_cb (GObject      *object,
   GFile *gfile;
   g_autofree gchar *path = NULL;
   GVariant *cursor = NULL;
-  GVariant *options = NULL;
 
   IDE_ENTRY;
 
@@ -371,7 +391,7 @@ get_proxy_cb (GObject      *object,
 
   /* TODO: Plumb support for cursors down to this level? */
   cursor = g_variant_new ("(xx)", (gint64)0, (gint64)0);
-  options = g_variant_new ("a{sv}", 0);
+  options = g_variant_ref_sink (get_parse_options ());
 
   gca_service_call_parse (proxy,
                           path,
diff --git a/plugins/gnome-code-assistance/ide-gca-preferences-addin.c 
b/plugins/gnome-code-assistance/ide-gca-preferences-addin.c
new file mode 100644
index 0000000..0c194a0
--- /dev/null
+++ b/plugins/gnome-code-assistance/ide-gca-preferences-addin.c
@@ -0,0 +1,86 @@
+/* ide-gca-preferences-addin.c
+ *
+ * Copyright (C) 2016 Christian Hergert <christian hergert me>
+ *
+ * This program 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.
+ *
+ * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib/gi18n.h>
+#include <ide.h>
+
+#include "ide-gca-preferences-addin.h"
+
+static void preferences_addin_iface_init (IdePreferencesAddinInterface *iface);
+
+struct _IdeGcaPreferencesAddin
+{
+  GObject parent;
+  guint   pylint;
+};
+
+G_DEFINE_TYPE_EXTENDED (IdeGcaPreferencesAddin, ide_gca_preferences_addin, G_TYPE_OBJECT, 0,
+                        G_IMPLEMENT_INTERFACE (IDE_TYPE_PREFERENCES_ADDIN,
+                                               preferences_addin_iface_init))
+
+static void
+ide_gca_preferences_addin_class_init (IdeGcaPreferencesAddinClass *klass)
+{
+}
+
+static void
+ide_gca_preferences_addin_init (IdeGcaPreferencesAddin *self)
+{
+}
+
+static void
+ide_gca_preferences_addin_load (IdePreferencesAddin *addin,
+                                IdePreferences      *preferences)
+{
+  IdeGcaPreferencesAddin *self = (IdeGcaPreferencesAddin *)addin;
+
+  g_assert (IDE_IS_GCA_PREFERENCES_ADDIN (self));
+  g_assert (IDE_IS_PREFERENCES (preferences));
+
+  self->pylint = ide_preferences_add_switch (preferences,
+                                             "code-insight",
+                                             "diagnostics",
+                                             "org.gnome.builder.gnome-code-assistance",
+                                             "enable-pylint",
+                                             NULL,
+                                             "false",
+                                             _("Pylint"),
+                                             _("Enable the use of pylint, which may execute code in your 
project"),
+                                             /* translators: these are keywords used to search for 
preferences */
+                                             _("pylint python lint code execute execution"),
+                                             500);
+}
+
+static void
+ide_gca_preferences_addin_unload (IdePreferencesAddin *addin,
+                                  IdePreferences      *preferences)
+{
+  IdeGcaPreferencesAddin *self = (IdeGcaPreferencesAddin *)addin;
+
+  g_assert (IDE_IS_GCA_PREFERENCES_ADDIN (self));
+  g_assert (IDE_IS_PREFERENCES (preferences));
+
+  ide_preferences_remove_id (preferences, self->pylint);
+}
+
+static void
+preferences_addin_iface_init (IdePreferencesAddinInterface *iface)
+{
+  iface->load = ide_gca_preferences_addin_load;
+  iface->unload = ide_gca_preferences_addin_unload;
+}
diff --git a/plugins/gnome-code-assistance/ide-gca-preferences-addin.h 
b/plugins/gnome-code-assistance/ide-gca-preferences-addin.h
new file mode 100644
index 0000000..6d3cc11
--- /dev/null
+++ b/plugins/gnome-code-assistance/ide-gca-preferences-addin.h
@@ -0,0 +1,32 @@
+/* ide-gca-preferences-addin.h
+ *
+ * Copyright (C) 2016 Christian Hergert <christian hergert me>
+ *
+ * This program 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.
+ *
+ * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_GCA_PREFERENCES_ADDIN_H
+#define IDE_GCA_PREFERENCES_ADDIN_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_GCA_PREFERENCES_ADDIN (ide_gca_preferences_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (IdeGcaPreferencesAddin, ide_gca_preferences_addin, IDE, GCA_PREFERENCES_ADDIN, GObject)
+
+G_END_DECLS
+
+#endif /* IDE_GCA_PREFERENCES_ADDIN_H */
diff --git a/plugins/gnome-code-assistance/org.gnome.builder.gnome-code-assistance.gschema.xml 
b/plugins/gnome-code-assistance/org.gnome.builder.gnome-code-assistance.gschema.xml
new file mode 100644
index 0000000..9a64887
--- /dev/null
+++ b/plugins/gnome-code-assistance/org.gnome.builder.gnome-code-assistance.gschema.xml
@@ -0,0 +1,9 @@
+<schemalist>
+  <schema id="org.gnome.builder.gnome-code-assistance" 
path="/org/gnome/builder/plugins/gnome-code-assistance/" gettext-domain="gnome-builder">
+    <key name="enable-pylint" type="b">
+      <default>false</default>
+      <summary>Enable Pylint</summary>
+      <description>Enable the use of pylint to find additional diagnostics in python programs. This may 
result in the execution of code in your project.</description>
+    </key>
+  </schema>
+</schemalist>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]