Skip to content

Commit 0bfd21f

Browse files
committed
Fix initialize request for workspace folders when no project open
1 parent 6b02c53 commit 0bfd21f

File tree

1 file changed

+113
-99
lines changed

1 file changed

+113
-99
lines changed

lsp/src/lsp-server.c

Lines changed: 113 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -459,128 +459,142 @@ static void initialize_cb(GVariant *return_value, GError *error, gpointer user_d
459459

460460
static void perform_initialize(LspServer *server)
461461
{
462-
GVariant *node;
463-
464462
gchar *locale = lsp_utils_get_locale();
465-
gchar *project_base_uri = NULL;
466463
gchar *project_base = lsp_utils_get_project_base_path();
464+
GVariant *workspace_folders = NULL;
465+
GVariant *node, *capabilities;
466+
gchar *project_base_uri = NULL;
467+
GVariantDict dct;
467468

468469
if (project_base)
469470
project_base_uri = g_filename_to_uri(project_base, NULL, NULL);
470471

471-
node = JSONRPC_MESSAGE_NEW(
472-
"processId", JSONRPC_MESSAGE_PUT_INT64(getpid()),
473-
"clientInfo", "{",
474-
"name", JSONRPC_MESSAGE_PUT_STRING("Geany"),
475-
"version", JSONRPC_MESSAGE_PUT_STRING("0.1"), //VERSION
472+
capabilities = JSONRPC_MESSAGE_NEW(
473+
"window", "{",
474+
"workDoneProgress", JSONRPC_MESSAGE_PUT_BOOLEAN(TRUE),
476475
"}",
477-
"locale", JSONRPC_MESSAGE_PUT_STRING(locale),
478-
"rootPath", JSONRPC_MESSAGE_PUT_STRING(project_base),
479-
"workspaceFolders", "[", "{",
480-
"uri", JSONRPC_MESSAGE_PUT_STRING (project_base_uri),
481-
"name", JSONRPC_MESSAGE_PUT_STRING (project_base),
482-
"}", "]",
483-
"rootUri", JSONRPC_MESSAGE_PUT_STRING(project_base_uri),
484-
"capabilities", "{",
485-
"window", "{",
486-
"workDoneProgress", JSONRPC_MESSAGE_PUT_BOOLEAN(TRUE),
476+
"textDocument", "{",
477+
"synchronization", "{",
478+
"willSave", JSONRPC_MESSAGE_PUT_BOOLEAN(FALSE),
479+
"willSaveWaitUntil", JSONRPC_MESSAGE_PUT_BOOLEAN(FALSE),
480+
"didSave", JSONRPC_MESSAGE_PUT_BOOLEAN(TRUE),
487481
"}",
488-
"textDocument", "{",
489-
"synchronization", "{",
490-
"willSave", JSONRPC_MESSAGE_PUT_BOOLEAN(FALSE),
491-
"willSaveWaitUntil", JSONRPC_MESSAGE_PUT_BOOLEAN(FALSE),
492-
"didSave", JSONRPC_MESSAGE_PUT_BOOLEAN(TRUE),
493-
"}",
494-
"completion", "{",
495-
"completionItem", "{",
482+
"completion", "{",
483+
"completionItem", "{",
496484
// "snippetSupport", JSONRPC_MESSAGE_PUT_BOOLEAN (TRUE),
497-
"documentationFormat", "[",
498-
"plaintext",
499-
"]",
500-
"}",
501-
"completionItemKind", "{",
502-
"valueSet", "[",
503-
LSP_COMPLETION_KINDS,
504-
"]",
505-
"}",
506-
"contxtSupport", JSONRPC_MESSAGE_PUT_BOOLEAN(TRUE),
507-
"}",
508-
"hover", "{",
509-
"contentFormat", "[",
485+
"documentationFormat", "[",
510486
"plaintext",
511487
"]",
512488
"}",
513-
"documentSymbol", "{",
514-
"symbolKind", "{",
515-
"valueSet", "[",
516-
LSP_SYMBOL_KINDS,
517-
"]",
518-
"}",
519-
"hierarchicalDocumentSymbolSupport", JSONRPC_MESSAGE_PUT_BOOLEAN(TRUE),
520-
"}",
521-
"semanticTokens", "{",
522-
"requests", "{",
523-
"range", JSONRPC_MESSAGE_PUT_BOOLEAN(FALSE),
524-
"full", "{",
525-
"delta", JSONRPC_MESSAGE_PUT_BOOLEAN(TRUE),
526-
"}",
527-
"}",
528-
"tokenTypes", "[",
529-
// specify all possible token types - gopls returns incorrect offsets without it
530-
// TODO: investigate more and possibly report upstream
531-
"namespace",
532-
"type",
533-
"class",
534-
"enum",
535-
"interface",
536-
"struct",
537-
"typeParameter",
538-
"parameter",
539-
"variable",
540-
"property",
541-
"enumMember",
542-
"event",
543-
"function",
544-
"method",
545-
"macro",
546-
"keyword",
547-
"modifier",
548-
"comment",
549-
"string",
550-
"number",
551-
"regexp",
552-
"operator",
553-
"decorator",
489+
"completionItemKind", "{",
490+
"valueSet", "[",
491+
LSP_COMPLETION_KINDS,
554492
"]",
555-
"tokenModifiers", "[",
556-
"]",
557-
"formats", "[",
558-
"relative",
493+
"}",
494+
"contxtSupport", JSONRPC_MESSAGE_PUT_BOOLEAN(TRUE),
495+
"}",
496+
"hover", "{",
497+
"contentFormat", "[",
498+
"plaintext",
499+
"]",
500+
"}",
501+
"documentSymbol", "{",
502+
"symbolKind", "{",
503+
"valueSet", "[",
504+
LSP_SYMBOL_KINDS,
559505
"]",
560-
"overlappingTokenSupport", JSONRPC_MESSAGE_PUT_BOOLEAN(FALSE),
561-
"multilineTokenSupport", JSONRPC_MESSAGE_PUT_BOOLEAN(FALSE),
562-
"serverCancelSupport", JSONRPC_MESSAGE_PUT_BOOLEAN(FALSE),
563-
"augmentsSyntaxTokens", JSONRPC_MESSAGE_PUT_BOOLEAN(TRUE),
564506
"}",
507+
"hierarchicalDocumentSymbolSupport", JSONRPC_MESSAGE_PUT_BOOLEAN(TRUE),
565508
"}",
566-
"workspace", "{",
567-
"applyEdit", JSONRPC_MESSAGE_PUT_BOOLEAN(TRUE),
568-
"symbol", "{",
569-
"symbolKind", "{",
570-
"valueSet", "[",
571-
LSP_SYMBOL_KINDS,
572-
"]",
509+
"semanticTokens", "{",
510+
"requests", "{",
511+
"range", JSONRPC_MESSAGE_PUT_BOOLEAN(FALSE),
512+
"full", "{",
513+
"delta", JSONRPC_MESSAGE_PUT_BOOLEAN(TRUE),
573514
"}",
574515
"}",
516+
"tokenTypes", "[",
517+
// specify all possible token types - gopls returns incorrect offsets without it
518+
// TODO: investigate more and possibly report upstream
519+
"namespace",
520+
"type",
521+
"class",
522+
"enum",
523+
"interface",
524+
"struct",
525+
"typeParameter",
526+
"parameter",
527+
"variable",
528+
"property",
529+
"enumMember",
530+
"event",
531+
"function",
532+
"method",
533+
"macro",
534+
"keyword",
535+
"modifier",
536+
"comment",
537+
"string",
538+
"number",
539+
"regexp",
540+
"operator",
541+
"decorator",
542+
"]",
543+
"tokenModifiers", "[",
544+
"]",
545+
"formats", "[",
546+
"relative",
547+
"]",
548+
"overlappingTokenSupport", JSONRPC_MESSAGE_PUT_BOOLEAN(FALSE),
549+
"multilineTokenSupport", JSONRPC_MESSAGE_PUT_BOOLEAN(FALSE),
550+
"serverCancelSupport", JSONRPC_MESSAGE_PUT_BOOLEAN(FALSE),
551+
"augmentsSyntaxTokens", JSONRPC_MESSAGE_PUT_BOOLEAN(TRUE),
575552
"}",
576553
"}",
577-
"trace", JSONRPC_MESSAGE_PUT_STRING("off"),
578-
"initializationOptions", "{",
579-
JSONRPC_MESSAGE_PUT_VARIANT(
580-
lsp_utils_parse_json_file(server->config.initialization_options_file, server->config.initialization_options)),
554+
"workspace", "{",
555+
"applyEdit", JSONRPC_MESSAGE_PUT_BOOLEAN(TRUE),
556+
"symbol", "{",
557+
"symbolKind", "{",
558+
"valueSet", "[",
559+
LSP_SYMBOL_KINDS,
560+
"]",
561+
"}",
562+
"}",
563+
"workspaceFolders", JSONRPC_MESSAGE_PUT_BOOLEAN(TRUE),
581564
"}"
582565
);
583566

567+
node = JSONRPC_MESSAGE_NEW(
568+
"clientInfo", "{",
569+
"name", JSONRPC_MESSAGE_PUT_STRING("Geany LSP Client Plugin"),
570+
"version", JSONRPC_MESSAGE_PUT_STRING(VERSION),
571+
"}",
572+
"processId", JSONRPC_MESSAGE_PUT_INT64(getpid()),
573+
"locale", JSONRPC_MESSAGE_PUT_STRING(locale),
574+
"trace", JSONRPC_MESSAGE_PUT_STRING("off"),
575+
"rootPath", JSONRPC_MESSAGE_PUT_STRING(project_base),
576+
"rootUri", JSONRPC_MESSAGE_PUT_STRING(project_base_uri)
577+
);
578+
579+
if (project_base)
580+
{
581+
workspace_folders = JSONRPC_MESSAGE_NEW_ARRAY(
582+
"{",
583+
"uri", JSONRPC_MESSAGE_PUT_STRING(project_base_uri),
584+
"name", JSONRPC_MESSAGE_PUT_STRING(project_base),
585+
"}");
586+
}
587+
588+
g_variant_dict_init(&dct, node);
589+
590+
if (workspace_folders)
591+
g_variant_dict_insert_value(&dct, "workspaceFolders", workspace_folders);
592+
g_variant_dict_insert_value(&dct, "initializationOptions",
593+
lsp_utils_parse_json_file(server->config.initialization_options_file, server->config.initialization_options));
594+
g_variant_dict_insert_value(&dct, "capabilities", capabilities);
595+
596+
node = g_variant_take_ref(g_variant_dict_end(&dct));
597+
584598
//printf("%s\n\n\n", lsp_utils_json_pretty_print(node));
585599

586600
msgwin_status_add(_("Sending initialize request to LSP server %s"), server->config.cmd);

0 commit comments

Comments
 (0)