Commit 19d8de20 authored by Günther Wagner's avatar Günther Wagner

rust-analyzer: highlighter and hover

static functions and hover

cleanup
parent fc97a0ab
Pipeline #179001 passed with stage
in 49 minutes and 7 seconds
...@@ -96,40 +96,50 @@ parse_marked_string (GVariant *v) ...@@ -96,40 +96,50 @@ parse_marked_string (GVariant *v)
if (g_variant_is_of_type (v, G_VARIANT_TYPE_VARIANT)) if (g_variant_is_of_type (v, G_VARIANT_TYPE_VARIANT))
v = child = g_variant_get_variant (v); 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; const gchar *value = "";
g_autoptr(GVariant) child2 = NULL;
if (g_variant_is_of_type (item, G_VARIANT_TYPE_VARIANT)) g_variant_lookup (v, "value", "&s", &value);
asv = child2 = g_variant_get_variant (item); if (!ide_str_empty0 (value))
g_string_append_printf (gstr, "%s", value);
if (g_variant_is_of_type (asv, G_VARIANT_TYPE_STRING)) }
g_string_append (gstr, g_variant_get_string (asv, NULL)); else
else if (g_variant_is_of_type (asv, G_VARIANT_TYPE_VARDICT)) {
g_variant_iter_init (&iter, v);
if ((item = g_variant_iter_next_value (&iter)))
{ {
const gchar *lang = ""; GVariant *asv = item;
const gchar *value = ""; g_autoptr(GVariant) child2 = NULL;
g_variant_lookup (asv, "language", "&s", &lang); if (g_variant_is_of_type (item, G_VARIANT_TYPE_VARIANT))
g_variant_lookup (asv, "value", "&s", &value); asv = child2 = g_variant_get_variant (item);
#if 0 if (g_variant_is_of_type (asv, G_VARIANT_TYPE_STRING))
if (!ide_str_empty0 (lang) && !ide_str_empty0 (value)) g_string_append (gstr, g_variant_get_string (asv, NULL));
g_string_append_printf (str, "```%s\n%s\n```", lang, value); else if (g_variant_is_of_type (asv, G_VARIANT_TYPE_VARDICT))
else if (!ide_str_empty0 (value)) {
g_string_append (str, value); const gchar *lang = "";
#else const gchar *value = "";
if (!ide_str_empty0 (value))
g_string_append_printf (gstr, "```\n%s\n```", value); g_variant_lookup (asv, "language", "&s", &lang);
#endif 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) if (gstr->len)
return ide_marked_content_new_from_data (gstr->str, gstr->len, IDE_MARKED_KIND_MARKDOWN); return ide_marked_content_new_from_data (gstr->str, gstr->len, IDE_MARKED_KIND_MARKDOWN);
......
...@@ -7,6 +7,8 @@ plugins_sources += files([ ...@@ -7,6 +7,8 @@ plugins_sources += files([
'rust-analyzer-symbol-resolver.c', 'rust-analyzer-symbol-resolver.c',
'rust-analyzer-diagnostic-provider.c', 'rust-analyzer-diagnostic-provider.c',
'rust-analyzer-formatter.c', 'rust-analyzer-formatter.c',
'rust-analyzer-highlighter.c',
'rust-analyzer-hover-provider.c',
'rust-analyzer-transfer.c', 'rust-analyzer-transfer.c',
'rust-analyzer-workbench-addin.c', 'rust-analyzer-workbench-addin.c',
]) ])
......
...@@ -49,8 +49,8 @@ rust_analyzer_completion_provider_load (IdeCompletionProvider *self, ...@@ -49,8 +49,8 @@ rust_analyzer_completion_provider_load (IdeCompletionProvider *self,
{ {
RustAnalyzerService *service = NULL; RustAnalyzerService *service = NULL;
g_return_if_fail (RUST_IS_ANALYZER_COMPLETION_PROVIDER (self)); g_assert (RUST_IS_ANALYZER_COMPLETION_PROVIDER (self));
g_return_if_fail (IDE_IS_CONTEXT (context)); g_assert (IDE_IS_CONTEXT (context));
service = ide_object_ensure_child_typed (IDE_OBJECT (context), RUST_TYPE_ANALYZER_SERVICE); 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); g_object_bind_property (service, "client", self, "client", G_BINDING_SYNC_CREATE);
......
...@@ -49,7 +49,7 @@ rust_analyzer_diagnostic_provider_load (IdeDiagnosticProvider *self) ...@@ -49,7 +49,7 @@ rust_analyzer_diagnostic_provider_load (IdeDiagnosticProvider *self)
RustAnalyzerService *service = NULL; RustAnalyzerService *service = NULL;
IdeContext *context = 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)); context = ide_object_get_context (IDE_OBJECT (self));
service = ide_object_ensure_child_typed (IDE_OBJECT (context), RUST_TYPE_ANALYZER_SERVICE); service = ide_object_ensure_child_typed (IDE_OBJECT (context), RUST_TYPE_ANALYZER_SERVICE);
......
...@@ -49,7 +49,7 @@ rust_analyzer_formatter_load (IdeFormatter *self) ...@@ -49,7 +49,7 @@ rust_analyzer_formatter_load (IdeFormatter *self)
IdeContext *context = NULL; IdeContext *context = NULL;
RustAnalyzerService *service = 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)); context = ide_object_get_context (IDE_OBJECT (self));
service = ide_object_ensure_child_typed (IDE_OBJECT (context), RUST_TYPE_ANALYZER_SERVICE); service = ide_object_ensure_child_typed (IDE_OBJECT (context), RUST_TYPE_ANALYZER_SERVICE);
......
/* 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;
}
/* 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
/* 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)
{
}
/* 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
...@@ -130,7 +130,6 @@ rust_analyzer_service_set_parent (IdeObject *object, ...@@ -130,7 +130,6 @@ rust_analyzer_service_set_parent (IdeObject *object,
g_autoptr(GFile) cargo_toml = NULL; g_autoptr(GFile) cargo_toml = NULL;
g_return_if_fail (RUST_IS_ANALYZER_SERVICE (object)); g_return_if_fail (RUST_IS_ANALYZER_SERVICE (object));
g_return_if_fail (parent != NULL);
context = ide_object_get_context (object); context = ide_object_get_context (object);
workdir = ide_context_ref_workdir (context); workdir = ide_context_ref_workdir (context);
......
...@@ -49,7 +49,7 @@ rust_analyzer_symbol_resolver_load (IdeSymbolResolver *self) ...@@ -49,7 +49,7 @@ rust_analyzer_symbol_resolver_load (IdeSymbolResolver *self)
IdeContext *context = NULL; IdeContext *context = NULL;
RustAnalyzerService *service = 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)); context = ide_object_get_context (IDE_OBJECT (self));
service = ide_object_ensure_child_typed (IDE_OBJECT (context), RUST_TYPE_ANALYZER_SERVICE); service = ide_object_ensure_child_typed (IDE_OBJECT (context), RUST_TYPE_ANALYZER_SERVICE);
......
...@@ -58,10 +58,11 @@ _downloaded_chunk (GObject *source_object, ...@@ -58,10 +58,11 @@ _downloaded_chunk (GObject *source_object,
DownloadData *data = user_data; DownloadData *data = user_data;
g_autofree gchar *statusmsg = NULL; g_autofree gchar *statusmsg = NULL;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
gsize count;
g_return_if_fail (G_IS_INPUT_STREAM (stream)); 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) if (error != NULL)
{ {
ide_task_return_error (data->task, g_steal_pointer (&error)); ide_task_return_error (data->task, g_steal_pointer (&error));
......
...@@ -125,8 +125,8 @@ rust_analyzer_workbench_addin_workspace_added (IdeWorkbenchAddin *addin, ...@@ -125,8 +125,8 @@ rust_analyzer_workbench_addin_workspace_added (IdeWorkbenchAddin *addin,
{ {
GSimpleAction *install_rust_analyzer = NULL; GSimpleAction *install_rust_analyzer = NULL;
g_return_if_fail (RUST_IS_ANALYZER_WORKBENCH_ADDIN (addin)); g_assert (RUST_IS_ANALYZER_WORKBENCH_ADDIN (addin));
g_return_if_fail (IDE_IS_WORKSPACE (workspace)); g_assert (IDE_IS_WORKSPACE (workspace));
install_rust_analyzer = g_simple_action_new ("install-rust-analyzer", NULL); install_rust_analyzer = g_simple_action_new ("install-rust-analyzer", NULL);
g_simple_action_set_enabled (install_rust_analyzer, TRUE); g_simple_action_set_enabled (install_rust_analyzer, TRUE);
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include "rust-analyzer-symbol-resolver.h" #include "rust-analyzer-symbol-resolver.h"
#include "rust-analyzer-diagnostic-provider.h" #include "rust-analyzer-diagnostic-provider.h"
#include "rust-analyzer-formatter.h" #include "rust-analyzer-formatter.h"
#include "rust-analyzer-highlighter.h"
#include "rust-analyzer-hover-provider.h"
#include "rust-analyzer-workbench-addin.h" #include "rust-analyzer-workbench-addin.h"
_IDE_EXTERN void _IDE_EXTERN void
...@@ -45,4 +47,10 @@ _rust_analyzer_register_types (PeasObjectModule *module) ...@@ -45,4 +47,10 @@ _rust_analyzer_register_types (PeasObjectModule *module)
peas_object_module_register_extension_type (module, peas_object_module_register_extension_type (module,
IDE_TYPE_FORMATTER, IDE_TYPE_FORMATTER,
RUST_TYPE_ANALYZER_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);
} }
...@@ -10,6 +10,6 @@ X-Completion-Provider-Languages=rust ...@@ -10,6 +10,6 @@ X-Completion-Provider-Languages=rust
X-Diagnostic-Provider-Languages=rust X-Diagnostic-Provider-Languages=rust
X-Symbol-Resolver-Languages=rust X-Symbol-Resolver-Languages=rust
X-Formatter-Languages=rust X-Formatter-Languages=rust
#X-Highlighter-Languages=rust X-Highlighter-Languages=rust
#X-Hover-Provider-Languages=rust X-Hover-Provider-Languages=rust
#X-Rename-Provider-Languages=rust #X-Rename-Provider-Languages=rust
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment