static void ide_gettext_diagnostic_provider_diagnose_async (IdeDiagnosticProvider *provider, IdeFile *file, IdeBuffer *buffer, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { IdeGettextDiagnosticProvider *self = (IdeGettextDiagnosticProvider *)provider; g_autoptr(IdeUnsavedFile) unsaved_file = NULL; IdeGettextDiagnostics *cached; g_autoptr(GTask) task = NULL; g_return_if_fail (IDE_IS_GETTEXT_DIAGNOSTIC_PROVIDER (self)); g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); task = g_task_new (self, cancellable, callback, user_data); g_task_set_source_tag (task, ide_gettext_diagnostic_provider_diagnose_async); if (NULL != (cached = dzl_task_cache_peek (self->diagnostics_cache, file))) { unsaved_file = get_unsaved_file (self, file); if (unsaved_file == NULL || (cached->sequence >= ide_unsaved_file_get_sequence (unsaved_file))) { g_task_return_pointer (task, g_object_ref (cached), g_object_unref); return; } } dzl_task_cache_get_async (self->diagnostics_cache, file, TRUE, cancellable, get_diagnostics_cb, g_steal_pointer (&task)); }
static void subprocess_wait_cb (GObject *object, GAsyncResult *res, gpointer user_data) { GSubprocess *subprocess = (GSubprocess *)object; g_autofree gchar *input_prefix = NULL; g_autoptr(IdeDiagnostics) local_diags = NULL; g_autoptr(GTask) task = user_data; g_autoptr(GPtrArray) array = NULL; g_autoptr(GDataInputStream) stderr_data_input = NULL; GInputStream *stderr_input = NULL; g_autoptr(IdeGettextDiagnostics) diags = NULL; TranslationUnit *unit; GError *error = NULL; g_assert (G_IS_SUBPROCESS (subprocess)); g_assert (G_IS_TASK (task)); unit = g_task_get_task_data (task); g_assert (unit != NULL); if (!g_subprocess_wait_finish (subprocess, res, &error)) { g_task_return_error (task, error); return; } array = g_ptr_array_new_with_free_func ((GDestroyNotify)ide_diagnostic_unref); if (g_subprocess_get_exit_status (subprocess) == 0) goto out; stderr_input = g_subprocess_get_stderr_pipe (subprocess); stderr_data_input = g_data_input_stream_new (stderr_input); input_prefix = g_strdup_printf ("%s:", ide_unsaved_file_get_temp_path (unit->unsaved_file)); for (;;) { g_autofree gchar *line = NULL; gsize length; line = g_data_input_stream_read_line (stderr_data_input, &length, g_task_get_cancellable (task), &error); if (line == NULL) break; if (g_str_has_prefix (line, input_prefix)) { gchar *p = line + strlen (input_prefix); if (g_ascii_isdigit (*p)) { gulong line_number = strtoul (p, &p, 10); IdeSourceLocation *loc; IdeDiagnostic *diag; loc = ide_source_location_new (unit->file, line_number - 1, 0, 0); diag = ide_diagnostic_new (IDE_DIAGNOSTIC_WARNING, g_strstrip (p + 1), loc); g_ptr_array_add (array, diag); } } } out: local_diags = ide_diagnostics_new (g_steal_pointer (&array)); diags = g_object_new (IDE_TYPE_GETTEXT_DIAGNOSTICS, "diagnostics", local_diags, "sequence", ide_unsaved_file_get_sequence (unit->unsaved_file), NULL); g_task_return_pointer (task, g_steal_pointer (&diags), g_object_unref); }