From e7df23c2131ca95587c53d9982c98655a2306520 Mon Sep 17 00:00:00 2001 From: 27Onion Nebell Date: Sat, 14 Dec 2024 10:22:43 +0800 Subject: [PATCH] fix: parse `initializationOptions` even more correctly But because of some problem within the V's json decode generator it's not possible to handle it prefectly with V's json module yet (optional type not handled correctly for sumtype & other types except struct) fomat --- src/lsp/initialize.v | 14 +++++++++----- src/server/general.v | 5 ++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/lsp/initialize.v b/src/lsp/initialize.v index a7774fc..ada1b1d 100644 --- a/src/lsp/initialize.v +++ b/src/lsp/initialize.v @@ -1,14 +1,18 @@ module lsp +// TODO: These LSPAny need to change to `?LSPAny` too. +type LSPAny = []LSPAny | map[string]LSPAny | f64 | bool | string + // method: ‘initialize’ // response: InitializeResult pub struct InitializeParams { pub mut: - process_id int = -2 @[json: processId] - client_info ClientInfo @[json: clientInfo] - root_uri DocumentUri @[json: rootUri] - root_path DocumentUri @[json: rootPath] - initialization_options string @[json: initializationOptions; skip] + process_id int = -2 @[json: processId] + client_info ClientInfo @[json: clientInfo] + root_uri DocumentUri @[json: rootUri] + root_path DocumentUri @[json: rootPath] + // TODO: Change this to `?LSPAny` once V fixed its JSON decoder codegen. (or shall we use json2?) + initialization_options LSPAny @[json: initializationOptions] capabilities ClientCapabilities trace string workspace_folders []WorkspaceFolder @[skip] diff --git a/src/server/general.v b/src/server/general.v index 7ecc1a3..d7f2f93 100644 --- a/src/server/general.v +++ b/src/server/general.v @@ -25,7 +25,10 @@ pub fn (mut ls LanguageServer) initialize(params lsp.InitializeParams, mut wr Re ls.status = .initialized ls.progress.support_work_done_progress = params.capabilities.window.work_done_progress - ls.initialization_options = params.initialization_options.fields() + options := params.initialization_options + if options is string { + ls.initialization_options = options.fields() + } ls.print_info(params.process_id, params.client_info) ls.setup()