rust-analyzer-completion-provider.c 2.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
/* rust-analyzer-completion-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-completion-provider.h"
#include "rust-analyzer-service.h"

struct _RustAnalyzerCompletionProvider
{
  IdeLspCompletionProvider parent_instance;
};

static void provider_iface_init (IdeCompletionProviderInterface *iface);

G_DEFINE_TYPE_WITH_CODE (RustAnalyzerCompletionProvider,
                         rust_analyzer_completion_provider,
                         IDE_TYPE_LSP_COMPLETION_PROVIDER,
                         G_IMPLEMENT_INTERFACE (IDE_TYPE_COMPLETION_PROVIDER, provider_iface_init))

static void
rust_analyzer_completion_provider_class_init (RustAnalyzerCompletionProviderClass *klass)
{
}

static void
rust_analyzer_completion_provider_init (RustAnalyzerCompletionProvider *self)
{
}

static void
rust_analyzer_completion_provider_load (IdeCompletionProvider *self,
                                        IdeContext            *context)
{
Günther Wagner's avatar
Günther Wagner committed
50
  RustAnalyzerService *service;
51

52 53
  g_assert (RUST_IS_ANALYZER_COMPLETION_PROVIDER (self));
  g_assert (IDE_IS_CONTEXT (context));
54 55

  service = ide_object_ensure_child_typed (IDE_OBJECT (context), RUST_TYPE_ANALYZER_SERVICE);
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
  g_object_bind_property (service, "client", self, "client", G_BINDING_SYNC_CREATE);
  rust_analyzer_service_ensure_started (service);
}

static gint
rust_analyzer_completion_provider_get_priority (IdeCompletionProvider *provider,
                                                IdeCompletionContext  *context)
{
  return -1000;
}

static void
provider_iface_init (IdeCompletionProviderInterface *iface)
{
  iface->load = rust_analyzer_completion_provider_load;
  iface->get_priority = rust_analyzer_completion_provider_get_priority;
}