Commit 1e4b762e authored by Christian Hergert's avatar Christian Hergert
Browse files

lsp: allow clients to reply to workspace/configuration

If a workspace/configuration call is made by the language
server to our IdeLspClient, we want to reply with something
useful to the peer.

Since this content can be different for every LSP, we'll defer
to the plugin to provide the content. Some params we'll want to
make easier for the plugin to determine, but this seems like the
quickest first step to make that possible. We can add additional
abstractions for the others later.

Related #1074
parent 6954ddeb
......@@ -71,8 +71,9 @@ enum {
};
enum {
PUBLISHED_DIAGNOSTICS,
LOAD_CONFIGURATION,
NOTIFICATION,
PUBLISHED_DIAGNOSTICS,
SUPPORTS_LANGUAGE,
N_SIGNALS
};
......@@ -696,6 +697,36 @@ ide_lsp_client_send_notification (IdeLspClient *self,
IDE_EXIT;
}
static gboolean
ide_lsp_client_handle_call (IdeLspClient *self,
const gchar *method,
GVariant *id,
GVariant *params,
JsonrpcClient *client)
{
IDE_ENTRY;
g_assert (IDE_IS_LSP_CLIENT (self));
g_assert (method != NULL);
g_assert (id != NULL);
g_assert (JSONRPC_IS_CLIENT (client));
if (strcmp (method, "workspace/configuration") == 0)
{
g_autoptr(GVariant) config = NULL;
g_signal_emit (self, signals [LOAD_CONFIGURATION], 0, &config);
if (config != NULL)
{
jsonrpc_client_reply_async (client, id, config, NULL, NULL, NULL);
IDE_RETURN (TRUE);
}
}
IDE_RETURN (FALSE);
}
static void
ide_lsp_client_finalize (GObject *object)
{
......@@ -824,6 +855,27 @@ ide_lsp_client_class_init (IdeLspClientClass *klass)
g_object_class_install_properties (object_class, N_PROPS, properties);
/**
* IdeLspClient::load-configuration:
* @self: a #IdeLspClient
*
* Loads the configuration object to reply to a workspace/configuration
* request from the peer.
*
* Returns: (transfer full): a #GVariant containing the result or %NULL
* to proceed to the next signal handler.
*
* Since: 3.36
*/
signals [LOAD_CONFIGURATION] =
g_signal_new ("load-configuration",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (IdeLspClientClass, load_configuration),
g_signal_accumulator_first_wins, NULL,
NULL,
G_TYPE_VARIANT, 0);
signals [NOTIFICATION] =
g_signal_new ("notification",
G_TYPE_FROM_CLASS (klass),
......@@ -1078,6 +1130,12 @@ ide_lsp_client_start (IdeLspClient *self)
self,
G_CONNECT_SWAPPED);
g_signal_connect_object (priv->rpc_client,
"handle-call",
G_CALLBACK (ide_lsp_client_handle_call),
self,
G_CONNECT_SWAPPED);
jsonrpc_client_call_async (priv->rpc_client,
"initialize",
params,
......
......@@ -44,17 +44,18 @@ struct _IdeLspClientClass
{
IdeObjectClass parent_class;
void (*notification) (IdeLspClient *self,
const gchar *method,
GVariant *params);
gboolean (*supports_language) (IdeLspClient *self,
const gchar *language_id);
void (*published_diagnostics) (IdeLspClient *self,
GFile *file,
IdeDiagnostics *diagnostics);
void (*notification) (IdeLspClient *self,
const gchar *method,
GVariant *params);
gboolean (*supports_language) (IdeLspClient *self,
const gchar *language_id);
void (*published_diagnostics) (IdeLspClient *self,
GFile *file,
IdeDiagnostics *diagnostics);
GVariant *(*load_configuration) (IdeLspClient *self);
/*< private >*/
gpointer _reserved[16];
gpointer _reserved[15];
};
IDE_AVAILABLE_IN_3_32
......
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