diff options
author | pommicket <pommicket@gmail.com> | 2022-12-26 01:28:49 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-26 01:28:49 -0500 |
commit | 44d607df5d5a9a1c892fe56c4874fbef7f209464 (patch) | |
tree | 988a3a73951300986ea91d23d67bbe37a02d5daf /lsp-parse.c | |
parent | 9602ae4d8582c3ccdb9e8c1561ad306491713be4 (diff) |
start workspace folders stuff
Diffstat (limited to 'lsp-parse.c')
-rw-r--r-- | lsp-parse.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lsp-parse.c b/lsp-parse.c index b5a05d0..de63401 100644 --- a/lsp-parse.c +++ b/lsp-parse.c @@ -266,6 +266,27 @@ static bool parse_completion(LSP *lsp, const JSON *json, LSPResponse *response) return true; } +// fills request->id/id_string appropriately given the request's json +// returns true on success +static WarnUnusedResult bool parse_id(JSON *json, LSPRequest *request) { + JSONValue id_value = json_get(json, "id"); + switch (id_value.type) { + case JSON_NUMBER: { + double id = id_value.val.number; + if (id == (u32)id) { + request->id = (u32)id; + return true; + } + } break; + case JSON_STRING: + request->id_string = json_string_get_alloc(json, id_value.val.string); + return true; + default: break; + } + return false; +} + +// returns true if `request` was actually filled with a request. static bool parse_server2client_request(LSP *lsp, JSON *json, LSPRequest *request) { JSONValue method_value = json_get(json, "method"); if (!lsp_expect_string(lsp, method_value, "request method")) @@ -297,6 +318,18 @@ static bool parse_server2client_request(LSP *lsp, JSON *json, LSPRequest *reques m->type = (LSPWindowMessageType)mtype; m->message = json_string_get_alloc(json, message.val.string); return true; + } else if (streq(method, "workspace/workspaceFolders")) { + // we can deal with this request right here + LSPResponse response = {0}; + request = &response.request; + request->type = LSP_REQUEST_WORKSPACE_FOLDERS; + if (!parse_id(json, request)) { + // we can't even send an error response since we have no ID. + debug_println("Bad ID in workspace/workspaceFolders request. This shouldn't happen."); + return false; + } + lsp_send_response(lsp, &response); + return false; } else if (str_has_prefix(method, "$/")) { // we can safely ignore this } else { |