[gnome-builder] libide/foundry: add API to short-circuit diagnose



commit d47af5ba9879f0e8dcf4183bd1aee7771410a90d
Author: Christian Hergert <chergert redhat com>
Date:   Mon Apr 25 18:14:07 2022 -0700

    libide/foundry: add API to short-circuit diagnose
    
    This can be useful if you need to determine if you can diagnost based on
    a language id, but you want to support most/all language ids by default.

 src/libide/foundry/ide-diagnostic-tool.c | 24 ++++++++++++++++++++++++
 src/libide/foundry/ide-diagnostic-tool.h |  4 ++++
 2 files changed, 28 insertions(+)
---
diff --git a/src/libide/foundry/ide-diagnostic-tool.c b/src/libide/foundry/ide-diagnostic-tool.c
index 996e69c5a..cd213c247 100644
--- a/src/libide/foundry/ide-diagnostic-tool.c
+++ b/src/libide/foundry/ide-diagnostic-tool.c
@@ -226,6 +226,21 @@ setup_launcher:
   IDE_RETURN (g_steal_pointer (&launcher));
 }
 
+static gboolean
+ide_diagnostic_tool_real_can_diagnose (IdeDiagnosticTool *self,
+                                       GFile             *file,
+                                       GBytes            *bytes,
+                                       const char        *language_id)
+{
+  IDE_ENTRY;
+
+  g_assert (IDE_IS_DIAGNOSTIC_TOOL (self));
+  g_assert (!file || G_IS_FILE (file));
+  g_assert (file != NULL || bytes != NULL);
+
+  IDE_RETURN (TRUE);
+}
+
 static void
 ide_diagnostic_tool_constructed (GObject *object)
 {
@@ -328,6 +343,7 @@ ide_diagnostic_tool_class_init (IdeDiagnosticToolClass *klass)
   klass->create_launcher = ide_diagnostic_tool_real_create_launcher;
   klass->configure_launcher = ide_diagnostic_tool_real_configure_launcher;
   klass->get_stdin_bytes = ide_diagnostic_tool_real_get_stdin_bytes;
+  klass->can_diagnose = ide_diagnostic_tool_real_can_diagnose;
 
   /**
    * IdeDiagnosticTool:program-name:
@@ -465,6 +481,14 @@ ide_diagnostic_tool_diagnose_async (IdeDiagnosticProvider *provider,
   task = ide_task_new (self, cancellable, callback, user_data);
   ide_task_set_source_tag (task, ide_diagnostic_tool_diagnose_async);
 
+  if (!IDE_DIAGNOSTIC_TOOL_GET_CLASS (self)->can_diagnose (self, file, contents, lang_id))
+    {
+      ide_task_return_new_error (task,
+                                 G_IO_ERROR,
+                                 G_IO_ERROR_NOT_SUPPORTED,
+                                 "Not supported");
+      IDE_EXIT;
+    }
 
   state = g_slice_new0 (DiagnoseState);
   state->file = file ? g_object_ref (file) : NULL;
diff --git a/src/libide/foundry/ide-diagnostic-tool.h b/src/libide/foundry/ide-diagnostic-tool.h
index b2891edc2..fe8e3a8c8 100644
--- a/src/libide/foundry/ide-diagnostic-tool.h
+++ b/src/libide/foundry/ide-diagnostic-tool.h
@@ -55,6 +55,10 @@ struct _IdeDiagnosticToolClass
                                                   GFile                  *file,
                                                   const char             *stdout_buf,
                                                   const char             *stderr_buf);
+  gboolean               (*can_diagnose)         (IdeDiagnosticTool      *self,
+                                                  GFile                  *file,
+                                                  GBytes                 *contents,
+                                                  const char             *language_id);
 };
 
 IDE_AVAILABLE_IN_42


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