[gnome-builder] plugins/rstcheck: port to C
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] plugins/rstcheck: port to C
- Date: Tue, 12 Jul 2022 06:39:18 +0000 (UTC)
commit 66b279a56b38bc21356ab84c408d295a2d0a57c0
Author: Christian Hergert <chergert redhat com>
Date: Mon Jul 11 23:16:30 2022 -0700
plugins/rstcheck: port to C
.../rstcheck/gbp-rstcheck-diagnostic-provider.c | 118 +++++++++++++++++++++
.../rstcheck/gbp-rstcheck-diagnostic-provider.h | 31 ++++++
src/plugins/rstcheck/meson.build | 19 ++--
src/plugins/rstcheck/rstcheck-plugin.c | 37 +++++++
src/plugins/rstcheck/rstcheck.gresource.xml | 6 ++
src/plugins/rstcheck/rstcheck.plugin | 10 +-
src/plugins/rstcheck/rstcheck_plugin.py | 49 ---------
7 files changed, 208 insertions(+), 62 deletions(-)
---
diff --git a/src/plugins/rstcheck/gbp-rstcheck-diagnostic-provider.c
b/src/plugins/rstcheck/gbp-rstcheck-diagnostic-provider.c
new file mode 100644
index 000000000..a4fbe07e8
--- /dev/null
+++ b/src/plugins/rstcheck/gbp-rstcheck-diagnostic-provider.c
@@ -0,0 +1,118 @@
+/* gbp-rstcheck-diagnostic-provider.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-rstcheck-diagnostic-provider"
+
+#include "config.h"
+
+#include "gbp-rstcheck-diagnostic-provider.h"
+
+struct _GbpRstcheckDiagnosticProvider
+{
+ IdeDiagnosticTool parent_instance;
+};
+
+G_DEFINE_FINAL_TYPE (GbpRstcheckDiagnosticProvider, gbp_rstcheck_diagnostic_provider,
IDE_TYPE_DIAGNOSTIC_TOOL)
+
+static GRegex *rstcheck_regex;
+static GHashTable *severities;
+
+static void
+gbp_rstcheck_diagnostic_provider_configure_launcher (IdeDiagnosticTool *tool,
+ IdeSubprocessLauncher *launcher,
+ GFile *file,
+ GBytes *contents,
+ const char *language_id)
+{
+ g_assert (GBP_IS_RSTCHECK_DIAGNOSTIC_PROVIDER (tool));
+ g_assert (IDE_IS_SUBPROCESS_LAUNCHER (launcher));
+ g_assert (G_IS_FILE (file));
+
+ ide_subprocess_launcher_push_argv (launcher, "-");
+}
+
+static void
+gbp_rstcheck_diagnostic_provider_populate_diagnostics (IdeDiagnosticTool *tool,
+ IdeDiagnostics *diagnostics,
+ GFile *file,
+ const char *stdout_data,
+ const char *stderr_data)
+{
+ IdeLineReader reader;
+ char *line;
+ gsize len;
+
+ g_assert (GBP_IS_RSTCHECK_DIAGNOSTIC_PROVIDER (tool));
+ g_assert (IDE_IS_DIAGNOSTICS (diagnostics));
+ g_assert (G_IS_FILE (file));
+ g_assert (rstcheck_regex != NULL);
+
+ if (ide_str_empty0 (stderr_data))
+ return;
+
+ /* Safe to stomp over "const" here since it's just for our consumption */
+ ide_line_reader_init (&reader, (char *)stderr_data, -1);
+ while ((line = ide_line_reader_next (&reader, &len)))
+ {
+ g_autoptr(IdeLocation) location = NULL;
+ g_auto(GStrv) tokens = NULL;
+ IdeDiagnosticSeverity severity;
+
+ if (line[0] == 0)
+ continue;
+
+ tokens = g_regex_split (rstcheck_regex, line, 0);
+
+ g_assert (tokens != NULL);
+ g_assert (tokens[0] != NULL);
+ g_assert (g_strv_length (tokens) >= 5);
+
+ if (tokens[1] == NULL)
+ continue;
+
+ location = ide_location_new (file, atoi (tokens[1]) - 1, 0);
+ severity = GPOINTER_TO_INT (g_hash_table_lookup (severities, tokens[2]));
+ ide_diagnostics_take (diagnostics, ide_diagnostic_new (severity, g_strstrip (tokens[4]), location));
+ }
+}
+
+static void
+gbp_rstcheck_diagnostic_provider_class_init (GbpRstcheckDiagnosticProviderClass *klass)
+{
+ IdeDiagnosticToolClass *diagnostic_tool_class = IDE_DIAGNOSTIC_TOOL_CLASS (klass);
+
+ diagnostic_tool_class->configure_launcher = gbp_rstcheck_diagnostic_provider_configure_launcher;
+ diagnostic_tool_class->populate_diagnostics = gbp_rstcheck_diagnostic_provider_populate_diagnostics;
+
+ rstcheck_regex = g_regex_new ("\\:([0-9]+)\\:\\s\\(([A-Z]+)\\/([0-9]{1})\\)\\s", G_REGEX_OPTIMIZE, 0,
NULL);
+
+ severities = g_hash_table_new (g_str_hash, g_str_equal);
+ g_hash_table_insert (severities, (char *)"INFO", GINT_TO_POINTER (IDE_DIAGNOSTIC_NOTE));
+ g_hash_table_insert (severities, (char *)"WARNING", GINT_TO_POINTER (IDE_DIAGNOSTIC_WARNING));
+ g_hash_table_insert (severities, (char *)"ERROR", GINT_TO_POINTER (IDE_DIAGNOSTIC_ERROR));
+ g_hash_table_insert (severities, (char *)"SEVERE", GINT_TO_POINTER (IDE_DIAGNOSTIC_FATAL));
+ g_hash_table_insert (severities, (char *)"NONE", GINT_TO_POINTER (IDE_DIAGNOSTIC_NOTE));
+}
+
+static void
+gbp_rstcheck_diagnostic_provider_init (GbpRstcheckDiagnosticProvider *self)
+{
+ ide_diagnostic_tool_set_program_name (IDE_DIAGNOSTIC_TOOL (self), "rstcheck");
+}
diff --git a/src/plugins/rstcheck/gbp-rstcheck-diagnostic-provider.h
b/src/plugins/rstcheck/gbp-rstcheck-diagnostic-provider.h
new file mode 100644
index 000000000..22b3fc047
--- /dev/null
+++ b/src/plugins/rstcheck/gbp-rstcheck-diagnostic-provider.h
@@ -0,0 +1,31 @@
+/* gbp-rstcheck-diagnostic-provider.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <libide-foundry.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_RSTCHECK_DIAGNOSTIC_PROVIDER (gbp_rstcheck_diagnostic_provider_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpRstcheckDiagnosticProvider, gbp_rstcheck_diagnostic_provider, GBP,
RSTCHECK_DIAGNOSTIC_PROVIDER, IdeDiagnosticTool)
+
+G_END_DECLS
diff --git a/src/plugins/rstcheck/meson.build b/src/plugins/rstcheck/meson.build
index 799ff1d1e..2f4148a78 100644
--- a/src/plugins/rstcheck/meson.build
+++ b/src/plugins/rstcheck/meson.build
@@ -1,13 +1,16 @@
if get_option('plugin_rstcheck')
-install_data('rstcheck_plugin.py', install_dir: plugindir)
-
-configure_file(
- input: 'rstcheck.plugin',
- output: 'rstcheck.plugin',
- configuration: config_h,
- install: true,
- install_dir: plugindir,
+plugins_sources += files([
+ 'rstcheck-plugin.c',
+ 'gbp-rstcheck-diagnostic-provider.c',
+])
+
+plugin_rstcheck_resources = gnome.compile_resources(
+ 'rstcheck-resources',
+ 'rstcheck.gresource.xml',
+ c_name: 'gbp_rstcheck',
)
+plugins_sources += plugin_rstcheck_resources
+
endif
diff --git a/src/plugins/rstcheck/rstcheck-plugin.c b/src/plugins/rstcheck/rstcheck-plugin.c
new file mode 100644
index 000000000..4a77ff89e
--- /dev/null
+++ b/src/plugins/rstcheck/rstcheck-plugin.c
@@ -0,0 +1,37 @@
+/* rstcheck-plugin.c
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "rstcheck-plugin"
+
+#include "config.h"
+
+#include <libpeas/peas.h>
+
+#include <libide-code.h>
+
+#include "gbp-rstcheck-diagnostic-provider.h"
+
+_IDE_EXTERN void
+_gbp_rstcheck_register_types (PeasObjectModule *module)
+{
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_DIAGNOSTIC_PROVIDER,
+ GBP_TYPE_RSTCHECK_DIAGNOSTIC_PROVIDER);
+}
diff --git a/src/plugins/rstcheck/rstcheck.gresource.xml b/src/plugins/rstcheck/rstcheck.gresource.xml
new file mode 100644
index 000000000..00173bf61
--- /dev/null
+++ b/src/plugins/rstcheck/rstcheck.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/plugins/rstcheck">
+ <file>rstcheck.plugin</file>
+ </gresource>
+</gresources>
diff --git a/src/plugins/rstcheck/rstcheck.plugin b/src/plugins/rstcheck/rstcheck.plugin
index 3696685f6..91c4ea6c2 100644
--- a/src/plugins/rstcheck/rstcheck.plugin
+++ b/src/plugins/rstcheck/rstcheck.plugin
@@ -1,11 +1,11 @@
[Plugin]
Authors=Veli Tasalı <me velitasali com>
Builtin=true
-Copyright=Copyright © 2022 Veli Tasalı
+Copyright=Copyright © 2022 Veli Tasalı, Copyright © 2022 Christian Hergert
Description=Provides reStructuredText linting using rstcheck
-Loader=python3
-Module=rstcheck_plugin
-Name=Rstcheck
+Embedded=_gbp_rstcheck_register_types
+Module=rstcheck
+Name=reStructuredText Diagnostics
+X-Category=diagnostics
X-Diagnostic-Provider-Languages-Priority=100
X-Diagnostic-Provider-Languages=rst
-X-Builder-ABI=@PACKAGE_ABI@
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]