[gnome-builder] lsp: implement support for parsing snippets
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] lsp: implement support for parsing snippets
- Date: Tue, 3 Mar 2020 04:33:04 +0000 (UTC)
commit 2a779e331efb4fc6a109374213c3dc984fda3828
Author: Christian Hergert <chergert redhat com>
Date: Mon Mar 2 20:32:28 2020 -0800
lsp: implement support for parsing snippets
Fixes #687
src/libide/lsp/ide-lsp-completion-item.c | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
---
diff --git a/src/libide/lsp/ide-lsp-completion-item.c b/src/libide/lsp/ide-lsp-completion-item.c
index d00afc371..1af194671 100644
--- a/src/libide/lsp/ide-lsp-completion-item.c
+++ b/src/libide/lsp/ide-lsp-completion-item.c
@@ -137,14 +137,36 @@ IdeSnippet *
ide_lsp_completion_item_get_snippet (IdeLspCompletionItem *self)
{
g_autoptr(IdeSnippet) snippet = NULL;
- g_autoptr(IdeSnippetChunk) chunk = NULL;
+ g_autoptr(IdeSnippetChunk) plainchunk = NULL;
+ const gchar *snippet_text = NULL;
+ const gchar *text;
+ gint64 format = 0;
g_return_val_if_fail (IDE_IS_LSP_COMPLETION_ITEM (self), NULL);
+ text = self->label;
+
+ if (JSONRPC_MESSAGE_PARSE (self->variant,
+ "insertTextFormat", JSONRPC_MESSAGE_GET_INT64 (&format),
+ "insertText", JSONRPC_MESSAGE_GET_STRING (&snippet_text)))
+ {
+ if (format == 2 && snippet_text != NULL)
+ {
+ g_autoptr(GError) error = NULL;
+
+ if ((snippet = ide_snippet_parser_parse_one (snippet_text, -1, &error)))
+ return g_steal_pointer (&snippet);
+
+ g_warning ("Failed to parse snippet: %s: %s",
+ error->message, snippet_text);
+ }
+ }
+
snippet = ide_snippet_new (NULL, NULL);
- chunk = ide_snippet_chunk_new ();
- ide_snippet_chunk_set_spec (chunk, self->label);
- ide_snippet_add_chunk (snippet, chunk);
+ plainchunk = ide_snippet_chunk_new ();
+ ide_snippet_chunk_set_text (plainchunk, text);
+ ide_snippet_chunk_set_text_set (plainchunk, TRUE);
+ ide_snippet_add_chunk (snippet, plainchunk);
return g_steal_pointer (&snippet);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]