[gnome-builder: 1/17] rust-analyzer: guards and contracts for functions
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder: 1/17] rust-analyzer: guards and contracts for functions
- Date: Mon, 22 Jun 2020 19:22:40 +0000 (UTC)
commit fc97a0ab1f99f714fdb5edac75089d86e9bcac86
Author: Günther Wagner <info gunibert de>
Date: Tue May 12 07:16:13 2020 +0200
rust-analyzer: guards and contracts for functions
.../rust-analyzer/rust-analyzer-completion-provider.c | 7 ++++++-
.../rust-analyzer/rust-analyzer-diagnostic-provider.c | 9 +++++++--
src/plugins/rust-analyzer/rust-analyzer-formatter.c | 9 +++++++--
src/plugins/rust-analyzer/rust-analyzer-service.c | 17 ++++++++++++++---
.../rust-analyzer/rust-analyzer-symbol-resolver.c | 9 +++++++--
src/plugins/rust-analyzer/rust-analyzer-transfer.c | 12 +++++++++---
.../rust-analyzer/rust-analyzer-workbench-addin.c | 11 +++++++++--
7 files changed, 59 insertions(+), 15 deletions(-)
---
diff --git a/src/plugins/rust-analyzer/rust-analyzer-completion-provider.c
b/src/plugins/rust-analyzer/rust-analyzer-completion-provider.c
index 6b88d081c..35b8dc84c 100644
--- a/src/plugins/rust-analyzer/rust-analyzer-completion-provider.c
+++ b/src/plugins/rust-analyzer/rust-analyzer-completion-provider.c
@@ -47,7 +47,12 @@ static void
rust_analyzer_completion_provider_load (IdeCompletionProvider *self,
IdeContext *context)
{
- RustAnalyzerService *service = ide_object_ensure_child_typed (IDE_OBJECT (context),
RUST_TYPE_ANALYZER_SERVICE);
+ RustAnalyzerService *service = NULL;
+
+ g_return_if_fail (RUST_IS_ANALYZER_COMPLETION_PROVIDER (self));
+ g_return_if_fail (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);
rust_analyzer_service_ensure_started (service);
}
diff --git a/src/plugins/rust-analyzer/rust-analyzer-diagnostic-provider.c
b/src/plugins/rust-analyzer/rust-analyzer-diagnostic-provider.c
index dd5e16c78..4650afa84 100644
--- a/src/plugins/rust-analyzer/rust-analyzer-diagnostic-provider.c
+++ b/src/plugins/rust-analyzer/rust-analyzer-diagnostic-provider.c
@@ -46,8 +46,13 @@ rust_analyzer_diagnostic_provider_init (RustAnalyzerDiagnosticProvider *self)
static void
rust_analyzer_diagnostic_provider_load (IdeDiagnosticProvider *self)
{
- IdeContext *context = ide_object_get_context (IDE_OBJECT (self));
- RustAnalyzerService *service = ide_object_ensure_child_typed (IDE_OBJECT (context),
RUST_TYPE_ANALYZER_SERVICE);
+ RustAnalyzerService *service = NULL;
+ IdeContext *context = NULL;
+
+ g_return_if_fail (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);
rust_analyzer_service_ensure_started (service);
g_object_bind_property (service, "client", self, "client", G_BINDING_SYNC_CREATE);
}
diff --git a/src/plugins/rust-analyzer/rust-analyzer-formatter.c
b/src/plugins/rust-analyzer/rust-analyzer-formatter.c
index 8ddee6981..7995c7ac3 100644
--- a/src/plugins/rust-analyzer/rust-analyzer-formatter.c
+++ b/src/plugins/rust-analyzer/rust-analyzer-formatter.c
@@ -46,8 +46,13 @@ rust_analyzer_formatter_init (RustAnalyzerFormatter *self)
static void
rust_analyzer_formatter_load (IdeFormatter *self)
{
- IdeContext *context = ide_object_get_context (IDE_OBJECT (self));
- RustAnalyzerService *service = ide_object_ensure_child_typed (IDE_OBJECT (context),
RUST_TYPE_ANALYZER_SERVICE);
+ IdeContext *context = NULL;
+ RustAnalyzerService *service = NULL;
+
+ g_return_if_fail (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);
g_object_bind_property (service, "client", self, "client", G_BINDING_SYNC_CREATE);
rust_analyzer_service_ensure_started (service);
}
diff --git a/src/plugins/rust-analyzer/rust-analyzer-service.c
b/src/plugins/rust-analyzer/rust-analyzer-service.c
index 96c286305..d104eb40d 100644
--- a/src/plugins/rust-analyzer/rust-analyzer-service.c
+++ b/src/plugins/rust-analyzer/rust-analyzer-service.c
@@ -63,6 +63,8 @@ _cargo_toml_changed_cb (GFileMonitor *monitor,
{
RustAnalyzerService *self = RUST_ANALYZER_SERVICE (user_data);
+ g_return_if_fail (RUST_IS_ANALYZER_SERVICE (self));
+
if (self->supervisor != NULL)
{
IdeSubprocess *subprocess = ide_subprocess_supervisor_get_subprocess (self->supervisor);
@@ -231,6 +233,8 @@ _handle_notification (IdeLspClient *client,
const gchar *token = NULL;
const gchar *kind = NULL;
+ g_return_if_fail (IDE_IS_LSP_CLIENT (client));
+
if (!ide_str_equal0 (method, "$/progress"))
return;
@@ -272,12 +276,15 @@ rust_analyzer_service_lsp_started (IdeSubprocessSupervisor *supervisor,
IdeSubprocess *subprocess,
gpointer user_data)
{
+ RustAnalyzerService *self = RUST_ANALYZER_SERVICE (user_data);
g_autoptr(GIOStream) io_stream = NULL;
GInputStream *input;
GOutputStream *output;
IdeLspClient *client = NULL;
- RustAnalyzerService *self = RUST_ANALYZER_SERVICE (user_data);
+ g_return_if_fail (RUST_IS_ANALYZER_SERVICE (self));
+ g_return_if_fail (IDE_IS_SUBPROCESS_SUPERVISOR (supervisor));
+ g_return_if_fail (IDE_IS_SUBPROCESS (subprocess));
input = ide_subprocess_get_stdout_pipe (subprocess);
output = ide_subprocess_get_stdin_pipe (subprocess);
@@ -300,12 +307,14 @@ rust_analyzer_service_lsp_started (IdeSubprocessSupervisor *supervisor,
static gboolean
rust_analyzer_service_check_rust_analyzer_bin (RustAnalyzerService *self)
{
- // Check if `rust-analyzer` can be found on PATH or if there is an executable
- // in typical location
+ /* Check if `rust-analyzer` can be found on PATH or if there is an executable
+ in typical location */
g_autoptr(GFile) rust_analyzer_bin_file = NULL;
g_autofree gchar *rust_analyzer_bin = NULL;
g_autoptr(GFileInfo) file_info = NULL;
+ g_return_val_if_fail (RUST_IS_ANALYZER_SERVICE (self), FALSE);
+
rust_analyzer_bin = g_find_program_in_path ("rust-analyzer");
if (rust_analyzer_bin == NULL)
{
@@ -339,6 +348,8 @@ rust_analyzer_service_check_rust_analyzer_bin (RustAnalyzerService *self)
void
rust_analyzer_service_ensure_started (RustAnalyzerService *self)
{
+ g_return_if_fail (RUST_IS_ANALYZER_SERVICE (self));
+
if (self->state == RUST_ANALYZER_SERVICE_INIT)
{
if (!rust_analyzer_service_check_rust_analyzer_bin (self))
diff --git a/src/plugins/rust-analyzer/rust-analyzer-symbol-resolver.c
b/src/plugins/rust-analyzer/rust-analyzer-symbol-resolver.c
index 980138b89..36935e381 100644
--- a/src/plugins/rust-analyzer/rust-analyzer-symbol-resolver.c
+++ b/src/plugins/rust-analyzer/rust-analyzer-symbol-resolver.c
@@ -46,8 +46,13 @@ rust_analyzer_symbol_resolver_init (RustAnalyzerSymbolResolver *self)
static void
rust_analyzer_symbol_resolver_load (IdeSymbolResolver *self)
{
- IdeContext *context = ide_object_get_context (IDE_OBJECT (self));
- RustAnalyzerService *service = ide_object_ensure_child_typed (IDE_OBJECT (context),
RUST_TYPE_ANALYZER_SERVICE);
+ IdeContext *context = NULL;
+ RustAnalyzerService *service = NULL;
+
+ g_return_if_fail (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);
rust_analyzer_service_ensure_started (service);
g_object_bind_property (service, "client", self, "client", G_BINDING_SYNC_CREATE);
}
diff --git a/src/plugins/rust-analyzer/rust-analyzer-transfer.c
b/src/plugins/rust-analyzer/rust-analyzer-transfer.c
index 4ccae579e..f20e96e4f 100644
--- a/src/plugins/rust-analyzer/rust-analyzer-transfer.c
+++ b/src/plugins/rust-analyzer/rust-analyzer-transfer.c
@@ -54,10 +54,12 @@ _downloaded_chunk (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
- g_autofree gchar *statusmsg = NULL;
- g_autoptr(GError) error = NULL;
GInputStream *stream = G_INPUT_STREAM (source_object);
DownloadData *data = user_data;
+ g_autofree gchar *statusmsg = NULL;
+ g_autoptr(GError) error = NULL;
+
+ g_return_if_fail (G_IS_INPUT_STREAM (stream));
gsize count = g_input_stream_read_finish (stream, result, &error);
if (error != NULL)
@@ -98,12 +100,15 @@ _download_lsp (GObject *source_object,
gpointer user_data)
{
g_autoptr(IdeTask) task = IDE_TASK (user_data);
+ SoupRequest *request = SOUP_REQUEST (source_object);
g_autoptr(GFile) file = NULL;
g_autoptr(GError) error = NULL;
- SoupRequest *request = SOUP_REQUEST (source_object);
GInputStream *stream = NULL;
DownloadData *data;
+ g_return_if_fail (SOUP_IS_REQUEST (request));
+ g_return_if_fail (IDE_IS_TASK (task));
+
stream = soup_request_send_finish (request, result, NULL);
data = g_slice_new0 (DownloadData);
@@ -134,6 +139,7 @@ rust_analyzer_transfer_execute_async (IdeTransfer *transfer,
g_autoptr(SoupRequest) request = NULL;
g_autoptr(GError) error = NULL;
+ g_return_if_fail (RUST_IS_ANALYZER_TRANSFER (self));
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
task = ide_task_new (self, cancellable, callback, user_data);
diff --git a/src/plugins/rust-analyzer/rust-analyzer-workbench-addin.c
b/src/plugins/rust-analyzer/rust-analyzer-workbench-addin.c
index 375f38aad..07ee8cca8 100644
--- a/src/plugins/rust-analyzer/rust-analyzer-workbench-addin.c
+++ b/src/plugins/rust-analyzer/rust-analyzer-workbench-addin.c
@@ -61,8 +61,8 @@ rust_analyzer_service_downloaded_lsp (GObject *object,
GAsyncResult *res,
gpointer user_data)
{
- RustAnalyzerService *service = NULL;
IdeContext *context = IDE_CONTEXT (user_data);
+ RustAnalyzerService *service = NULL;
g_return_if_fail (IDE_IS_CONTEXT (context));
@@ -78,6 +78,8 @@ rust_analyzer_workbench_addin_remove_lsp (IdeTransfer *transfer,
g_autofree gchar *rust_analyzer_path = NULL;
g_autoptr(GFile) rust_analyzer_bin = NULL;
+ g_return_if_fail (IDE_IS_TRANSFER (transfer));
+
rust_analyzer_path = g_build_filename (g_get_home_dir (), ".cargo", "bin", "rust-analyzer", NULL);
rust_analyzer_bin = g_file_new_for_path (rust_analyzer_path);
g_file_trash (rust_analyzer_bin, NULL, NULL);
@@ -88,12 +90,14 @@ rust_analyzer_workbench_addin_install_rust_analyzer (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
+ IdeContext *context = IDE_CONTEXT (user_data);
g_autoptr(RustAnalyzerTransfer) transfer = NULL;
IdeNotifications *notifications = NULL;
IdeNotification *notification = NULL;
IdeTransferManager *transfer_manager = NULL;
- IdeContext *context = IDE_CONTEXT (user_data);
+ g_return_if_fail (G_IS_SIMPLE_ACTION (action));
+ g_return_if_fail (IDE_IS_CONTEXT (context));
notifications = ide_object_get_child_typed (IDE_OBJECT (context), IDE_TYPE_NOTIFICATIONS);
notification = ide_notifications_find_by_id (notifications, "org.gnome-builder.rust-analyzer");
@@ -121,6 +125,9 @@ 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));
+
install_rust_analyzer = g_simple_action_new ("install-rust-analyzer", NULL);
g_simple_action_set_enabled (install_rust_analyzer, TRUE);
g_signal_connect (install_rust_analyzer,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]