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,8 +96,18 @@ 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 (g_variant_is_of_type (v, G_VARIANT_TYPE_DICTIONARY))
{
const gchar *value = "";
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)))
{
GVariant *asv = item;
......@@ -116,20 +126,20 @@ parse_marked_string (GVariant *v)
g_variant_lookup (asv, "language", "&s", &lang);
g_variant_lookup (asv, "value", "&s", &value);
#if 0
#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
#else
if (!ide_str_empty0 (value))
g_string_append_printf (gstr, "```\n%s\n```", value);
#endif
#endif
}
g_variant_unref (item);
}
}
if (gstr->len)
return ide_marked_content_new_from_data (gstr->str, gstr->len, IDE_MARKED_KIND_MARKDOWN);
......
......@@ -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',
])
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
/* 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,
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);
......
......@@ -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);
......
......@@ -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));
......
......@@ -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);
......
......@@ -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);
}
......@@ -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
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