[gnome-builder: 2/17] rust-analyzer: highlighter and hover
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder: 2/17] rust-analyzer: highlighter and hover
- Date: Mon, 22 Jun 2020 19:22:45 +0000 (UTC)
commit 19d8de205cda2d3c50cb52c8f6efe8b59b10c107
Author: Günther Wagner <info gunibert de>
Date: Tue May 12 20:44:14 2020 +0200
rust-analyzer: highlighter and hover
static functions and hover
cleanup
src/libide/lsp/ide-lsp-hover-provider.c | 66 +++++++++++++---------
src/plugins/rust-analyzer/meson.build | 2 +
.../rust-analyzer-completion-provider.c | 4 +-
.../rust-analyzer-diagnostic-provider.c | 2 +-
.../rust-analyzer/rust-analyzer-formatter.c | 2 +-
.../rust-analyzer/rust-analyzer-highlighter.c | 64 +++++++++++++++++++++
.../rust-analyzer/rust-analyzer-highlighter.h | 31 ++++++++++
.../rust-analyzer/rust-analyzer-hover-provider.c | 60 ++++++++++++++++++++
.../rust-analyzer/rust-analyzer-hover-provider.h | 31 ++++++++++
src/plugins/rust-analyzer/rust-analyzer-service.c | 1 -
.../rust-analyzer/rust-analyzer-symbol-resolver.c | 2 +-
src/plugins/rust-analyzer/rust-analyzer-transfer.c | 3 +-
.../rust-analyzer/rust-analyzer-workbench-addin.c | 4 +-
src/plugins/rust-analyzer/rust-analyzer.c | 8 +++
src/plugins/rust-analyzer/rust-analyzer.plugin | 4 +-
15 files changed, 245 insertions(+), 39 deletions(-)
---
diff --git a/src/libide/lsp/ide-lsp-hover-provider.c b/src/libide/lsp/ide-lsp-hover-provider.c
index 1760363e2..1ca2fc900 100644
--- a/src/libide/lsp/ide-lsp-hover-provider.c
+++ b/src/libide/lsp/ide-lsp-hover-provider.c
@@ -96,40 +96,50 @@ parse_marked_string (GVariant *v)
if (g_variant_is_of_type (v, G_VARIANT_TYPE_VARIANT))
v = child = g_variant_get_variant (v);
- g_variant_iter_init (&iter, v);
- if ((item = g_variant_iter_next_value (&iter)))
+ if (g_variant_is_of_type (v, G_VARIANT_TYPE_DICTIONARY))
{
- GVariant *asv = item;
- g_autoptr(GVariant) child2 = NULL;
+ const gchar *value = "";
- if (g_variant_is_of_type (item, G_VARIANT_TYPE_VARIANT))
- asv = child2 = g_variant_get_variant (item);
-
- if (g_variant_is_of_type (asv, G_VARIANT_TYPE_STRING))
- g_string_append (gstr, g_variant_get_string (asv, NULL));
- else if (g_variant_is_of_type (asv, G_VARIANT_TYPE_VARDICT))
+ g_variant_lookup (v, "value", "&s", &value);
+ if (!ide_str_empty0 (value))
+ g_string_append_printf (gstr, "%s", value);
+ }
+ else
+ {
+ g_variant_iter_init (&iter, v);
+ if ((item = g_variant_iter_next_value (&iter)))
{
- const gchar *lang = "";
- const gchar *value = "";
-
- g_variant_lookup (asv, "language", "&s", &lang);
- g_variant_lookup (asv, "value", "&s", &value);
-
-#if 0
- if (!ide_str_empty0 (lang) && !ide_str_empty0 (value))
- g_string_append_printf (str, "```%s\n%s\n```", lang, value);
- else if (!ide_str_empty0 (value))
- g_string_append (str, value);
-#else
- if (!ide_str_empty0 (value))
- g_string_append_printf (gstr, "```\n%s\n```", value);
-#endif
+ GVariant *asv = item;
+ g_autoptr(GVariant) child2 = NULL;
+
+ if (g_variant_is_of_type (item, G_VARIANT_TYPE_VARIANT))
+ asv = child2 = g_variant_get_variant (item);
+
+ if (g_variant_is_of_type (asv, G_VARIANT_TYPE_STRING))
+ g_string_append (gstr, g_variant_get_string (asv, NULL));
+ else if (g_variant_is_of_type (asv, G_VARIANT_TYPE_VARDICT))
+ {
+ const gchar *lang = "";
+ const gchar *value = "";
+
+ g_variant_lookup (asv, "language", "&s", &lang);
+ g_variant_lookup (asv, "value", "&s", &value);
+
+ #if 0
+ if (!ide_str_empty0 (lang) && !ide_str_empty0 (value))
+ g_string_append_printf (str, "```%s\n%s\n```", lang, value);
+ else if (!ide_str_empty0 (value))
+ g_string_append (str, value);
+ #else
+ if (!ide_str_empty0 (value))
+ g_string_append_printf (gstr, "```\n%s\n```", value);
+ #endif
+ }
+
+ g_variant_unref (item);
}
-
- g_variant_unref (item);
}
-
if (gstr->len)
return ide_marked_content_new_from_data (gstr->str, gstr->len, IDE_MARKED_KIND_MARKDOWN);
diff --git a/src/plugins/rust-analyzer/meson.build b/src/plugins/rust-analyzer/meson.build
index 492ed9844..aa755b504 100644
--- a/src/plugins/rust-analyzer/meson.build
+++ b/src/plugins/rust-analyzer/meson.build
@@ -7,6 +7,8 @@ plugins_sources += files([
'rust-analyzer-symbol-resolver.c',
'rust-analyzer-diagnostic-provider.c',
'rust-analyzer-formatter.c',
+ 'rust-analyzer-highlighter.c',
+ 'rust-analyzer-hover-provider.c',
'rust-analyzer-transfer.c',
'rust-analyzer-workbench-addin.c',
])
diff --git a/src/plugins/rust-analyzer/rust-analyzer-completion-provider.c
b/src/plugins/rust-analyzer/rust-analyzer-completion-provider.c
index 35b8dc84c..d45576f53 100644
--- a/src/plugins/rust-analyzer/rust-analyzer-completion-provider.c
+++ b/src/plugins/rust-analyzer/rust-analyzer-completion-provider.c
@@ -49,8 +49,8 @@ rust_analyzer_completion_provider_load (IdeCompletionProvider *self,
{
RustAnalyzerService *service = NULL;
- g_return_if_fail (RUST_IS_ANALYZER_COMPLETION_PROVIDER (self));
- g_return_if_fail (IDE_IS_CONTEXT (context));
+ g_assert (RUST_IS_ANALYZER_COMPLETION_PROVIDER (self));
+ g_assert (IDE_IS_CONTEXT (context));
service = ide_object_ensure_child_typed (IDE_OBJECT (context), RUST_TYPE_ANALYZER_SERVICE);
g_object_bind_property (service, "client", self, "client", G_BINDING_SYNC_CREATE);
diff --git a/src/plugins/rust-analyzer/rust-analyzer-diagnostic-provider.c
b/src/plugins/rust-analyzer/rust-analyzer-diagnostic-provider.c
index 4650afa84..880e2605a 100644
--- a/src/plugins/rust-analyzer/rust-analyzer-diagnostic-provider.c
+++ b/src/plugins/rust-analyzer/rust-analyzer-diagnostic-provider.c
@@ -49,7 +49,7 @@ rust_analyzer_diagnostic_provider_load (IdeDiagnosticProvider *self)
RustAnalyzerService *service = NULL;
IdeContext *context = NULL;
- g_return_if_fail (RUST_IS_ANALYZER_DIAGNOSTIC_PROVIDER (self));
+ g_assert (RUST_IS_ANALYZER_DIAGNOSTIC_PROVIDER (self));
context = ide_object_get_context (IDE_OBJECT (self));
service = ide_object_ensure_child_typed (IDE_OBJECT (context), RUST_TYPE_ANALYZER_SERVICE);
diff --git a/src/plugins/rust-analyzer/rust-analyzer-formatter.c
b/src/plugins/rust-analyzer/rust-analyzer-formatter.c
index 7995c7ac3..e713b6926 100644
--- a/src/plugins/rust-analyzer/rust-analyzer-formatter.c
+++ b/src/plugins/rust-analyzer/rust-analyzer-formatter.c
@@ -49,7 +49,7 @@ rust_analyzer_formatter_load (IdeFormatter *self)
IdeContext *context = NULL;
RustAnalyzerService *service = NULL;
- g_return_if_fail (RUST_IS_ANALYZER_FORMATTER (self));
+ g_assert (RUST_IS_ANALYZER_FORMATTER (self));
context = ide_object_get_context (IDE_OBJECT (self));
service = ide_object_ensure_child_typed (IDE_OBJECT (context), RUST_TYPE_ANALYZER_SERVICE);
diff --git a/src/plugins/rust-analyzer/rust-analyzer-highlighter.c
b/src/plugins/rust-analyzer/rust-analyzer-highlighter.c
new file mode 100644
index 000000000..8e728aa2d
--- /dev/null
+++ b/src/plugins/rust-analyzer/rust-analyzer-highlighter.c
@@ -0,0 +1,64 @@
+/* rust-analyzer-highlighter.c
+ *
+ * Copyright 2020 Günther Wagner <info gunibert de>
+ *
+ * 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
+ */
+
+#include "rust-analyzer-highlighter.h"
+#include "rust-analyzer-service.h"
+
+struct _RustAnalyzerHighlighter
+{
+ IdeLspHighlighter parent_instance;
+};
+
+static void provider_iface_init (IdeHighlighterInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (RustAnalyzerHighlighter,
+ rust_analyzer_highlighter,
+ IDE_TYPE_LSP_HIGHLIGHTER,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_HIGHLIGHTER, provider_iface_init))
+
+static void
+rust_analyzer_highlighter_class_init (RustAnalyzerHighlighterClass *klass)
+{
+}
+
+static void
+rust_analyzer_highlighter_init (RustAnalyzerHighlighter *self)
+{
+}
+
+static void
+rust_analyzer_highlighter_load (IdeHighlighter *self)
+{
+ IdeContext *context = NULL;
+ RustAnalyzerService *service = NULL;
+
+ g_assert (RUST_IS_ANALYZER_HIGHLIGHTER (self));
+
+ context = ide_object_get_context (IDE_OBJECT (self));
+ service = ide_object_ensure_child_typed (IDE_OBJECT (context), RUST_TYPE_ANALYZER_SERVICE);
+ g_object_bind_property (service, "client", self, "client", G_BINDING_SYNC_CREATE);
+ rust_analyzer_service_ensure_started (service);
+}
+
+static void
+provider_iface_init (IdeHighlighterInterface *iface)
+{
+ iface->load = rust_analyzer_highlighter_load;
+}
diff --git a/src/plugins/rust-analyzer/rust-analyzer-highlighter.h
b/src/plugins/rust-analyzer/rust-analyzer-highlighter.h
new file mode 100644
index 000000000..dcadbf34d
--- /dev/null
+++ b/src/plugins/rust-analyzer/rust-analyzer-highlighter.h
@@ -0,0 +1,31 @@
+/* rust-analyzer-highlighter.h
+ *
+ * Copyright 2020 Günther Wagner <info gunibert de>
+ *
+ * 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-lsp.h>
+
+G_BEGIN_DECLS
+
+#define RUST_TYPE_ANALYZER_HIGHLIGHTER (rust_analyzer_highlighter_get_type())
+
+G_DECLARE_FINAL_TYPE (RustAnalyzerHighlighter, rust_analyzer_highlighter, RUST, ANALYZER_HIGHLIGHTER,
IdeLspHighlighter)
+
+G_END_DECLS
diff --git a/src/plugins/rust-analyzer/rust-analyzer-hover-provider.c
b/src/plugins/rust-analyzer/rust-analyzer-hover-provider.c
new file mode 100644
index 000000000..dd3214fb4
--- /dev/null
+++ b/src/plugins/rust-analyzer/rust-analyzer-hover-provider.c
@@ -0,0 +1,60 @@
+/* rust-analyzer-hover-provider.c
+ *
+ * Copyright 2020 Günther Wagner <info gunibert de>
+ *
+ * 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
+ */
+
+#include "rust-analyzer-hover-provider.h"
+#include "rust-analyzer-service.h"
+
+struct _RustAnalyzerHoverProvider
+{
+ IdeLspHoverProvider parent_instance;
+};
+
+G_DEFINE_TYPE (RustAnalyzerHoverProvider,
+ rust_analyzer_hover_provider,
+ IDE_TYPE_LSP_HOVER_PROVIDER)
+
+static void
+rust_analyzer_hover_provider_prepare (IdeLspHoverProvider *self)
+{
+ IdeContext *context = NULL;
+ RustAnalyzerService *service = NULL;
+
+ g_assert (RUST_IS_ANALYZER_HOVER_PROVIDER (self));
+
+ context = ide_object_get_context (IDE_OBJECT (self));
+ service = ide_object_ensure_child_typed (IDE_OBJECT (context), RUST_TYPE_ANALYZER_SERVICE);
+ g_object_set (self, "category", "Rust", "priority", 200, NULL);
+ g_object_bind_property (service, "client", self, "client", G_BINDING_SYNC_CREATE);
+ rust_analyzer_service_ensure_started (service);
+}
+
+
+static void
+rust_analyzer_hover_provider_class_init (RustAnalyzerHoverProviderClass *klass)
+{
+ IdeLspHoverProviderClass *lsp_class = IDE_LSP_HOVER_PROVIDER_CLASS (klass);
+
+ lsp_class->prepare = rust_analyzer_hover_provider_prepare;
+}
+
+static void
+rust_analyzer_hover_provider_init (RustAnalyzerHoverProvider *self)
+{
+}
diff --git a/src/plugins/rust-analyzer/rust-analyzer-hover-provider.h
b/src/plugins/rust-analyzer/rust-analyzer-hover-provider.h
new file mode 100644
index 000000000..a9d426733
--- /dev/null
+++ b/src/plugins/rust-analyzer/rust-analyzer-hover-provider.h
@@ -0,0 +1,31 @@
+/* rust-analyzer-hover-provider.h
+ *
+ * Copyright 2020 Günther Wagner <info gunibert de>
+ *
+ * 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-lsp.h>
+
+G_BEGIN_DECLS
+
+#define RUST_TYPE_ANALYZER_HOVER_PROVIDER (rust_analyzer_hover_provider_get_type())
+
+G_DECLARE_FINAL_TYPE (RustAnalyzerHoverProvider, rust_analyzer_hover_provider, RUST,
ANALYZER_HOVER_PROVIDER, IdeLspHoverProvider)
+
+G_END_DECLS
diff --git a/src/plugins/rust-analyzer/rust-analyzer-service.c
b/src/plugins/rust-analyzer/rust-analyzer-service.c
index d104eb40d..ec6532eff 100644
--- a/src/plugins/rust-analyzer/rust-analyzer-service.c
+++ b/src/plugins/rust-analyzer/rust-analyzer-service.c
@@ -130,7 +130,6 @@ rust_analyzer_service_set_parent (IdeObject *object,
g_autoptr(GFile) cargo_toml = NULL;
g_return_if_fail (RUST_IS_ANALYZER_SERVICE (object));
- g_return_if_fail (parent != NULL);
context = ide_object_get_context (object);
workdir = ide_context_ref_workdir (context);
diff --git a/src/plugins/rust-analyzer/rust-analyzer-symbol-resolver.c
b/src/plugins/rust-analyzer/rust-analyzer-symbol-resolver.c
index 36935e381..f0fc10e19 100644
--- a/src/plugins/rust-analyzer/rust-analyzer-symbol-resolver.c
+++ b/src/plugins/rust-analyzer/rust-analyzer-symbol-resolver.c
@@ -49,7 +49,7 @@ rust_analyzer_symbol_resolver_load (IdeSymbolResolver *self)
IdeContext *context = NULL;
RustAnalyzerService *service = NULL;
- g_return_if_fail (RUST_IS_ANALYZER_SYMBOL_RESOLVER (self));
+ g_assert (RUST_IS_ANALYZER_SYMBOL_RESOLVER (self));
context = ide_object_get_context (IDE_OBJECT (self));
service = ide_object_ensure_child_typed (IDE_OBJECT (context), RUST_TYPE_ANALYZER_SERVICE);
diff --git a/src/plugins/rust-analyzer/rust-analyzer-transfer.c
b/src/plugins/rust-analyzer/rust-analyzer-transfer.c
index f20e96e4f..dbf638883 100644
--- a/src/plugins/rust-analyzer/rust-analyzer-transfer.c
+++ b/src/plugins/rust-analyzer/rust-analyzer-transfer.c
@@ -58,10 +58,11 @@ _downloaded_chunk (GObject *source_object,
DownloadData *data = user_data;
g_autofree gchar *statusmsg = NULL;
g_autoptr(GError) error = NULL;
+ gsize count;
g_return_if_fail (G_IS_INPUT_STREAM (stream));
- gsize count = g_input_stream_read_finish (stream, result, &error);
+ count = g_input_stream_read_finish (stream, result, &error);
if (error != NULL)
{
ide_task_return_error (data->task, g_steal_pointer (&error));
diff --git a/src/plugins/rust-analyzer/rust-analyzer-workbench-addin.c
b/src/plugins/rust-analyzer/rust-analyzer-workbench-addin.c
index 07ee8cca8..30878efe9 100644
--- a/src/plugins/rust-analyzer/rust-analyzer-workbench-addin.c
+++ b/src/plugins/rust-analyzer/rust-analyzer-workbench-addin.c
@@ -125,8 +125,8 @@ rust_analyzer_workbench_addin_workspace_added (IdeWorkbenchAddin *addin,
{
GSimpleAction *install_rust_analyzer = NULL;
- g_return_if_fail (RUST_IS_ANALYZER_WORKBENCH_ADDIN (addin));
- g_return_if_fail (IDE_IS_WORKSPACE (workspace));
+ g_assert (RUST_IS_ANALYZER_WORKBENCH_ADDIN (addin));
+ g_assert (IDE_IS_WORKSPACE (workspace));
install_rust_analyzer = g_simple_action_new ("install-rust-analyzer", NULL);
g_simple_action_set_enabled (install_rust_analyzer, TRUE);
diff --git a/src/plugins/rust-analyzer/rust-analyzer.c b/src/plugins/rust-analyzer/rust-analyzer.c
index 6fbbfc10b..21948d834 100644
--- a/src/plugins/rust-analyzer/rust-analyzer.c
+++ b/src/plugins/rust-analyzer/rust-analyzer.c
@@ -25,6 +25,8 @@
#include "rust-analyzer-symbol-resolver.h"
#include "rust-analyzer-diagnostic-provider.h"
#include "rust-analyzer-formatter.h"
+#include "rust-analyzer-highlighter.h"
+#include "rust-analyzer-hover-provider.h"
#include "rust-analyzer-workbench-addin.h"
_IDE_EXTERN void
@@ -45,4 +47,10 @@ _rust_analyzer_register_types (PeasObjectModule *module)
peas_object_module_register_extension_type (module,
IDE_TYPE_FORMATTER,
RUST_TYPE_ANALYZER_FORMATTER);
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_HIGHLIGHTER,
+ RUST_TYPE_ANALYZER_HIGHLIGHTER);
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_HOVER_PROVIDER,
+ RUST_TYPE_ANALYZER_HOVER_PROVIDER);
}
diff --git a/src/plugins/rust-analyzer/rust-analyzer.plugin b/src/plugins/rust-analyzer/rust-analyzer.plugin
index 5a1ee9326..42f80d458 100644
--- a/src/plugins/rust-analyzer/rust-analyzer.plugin
+++ b/src/plugins/rust-analyzer/rust-analyzer.plugin
@@ -10,6 +10,6 @@ X-Completion-Provider-Languages=rust
X-Diagnostic-Provider-Languages=rust
X-Symbol-Resolver-Languages=rust
X-Formatter-Languages=rust
-#X-Highlighter-Languages=rust
-#X-Hover-Provider-Languages=rust
+X-Highlighter-Languages=rust
+X-Hover-Provider-Languages=rust
#X-Rename-Provider-Languages=rust
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]