summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ide-code-action.c6
-rw-r--r--lsp-parse.c21
-rw-r--r--lsp.c10
-rw-r--r--lsp.h11
4 files changed, 42 insertions, 6 deletions
diff --git a/ide-code-action.c b/ide-code-action.c
index f357e6d..6244756 100644
--- a/ide-code-action.c
+++ b/ide-code-action.c
@@ -142,6 +142,12 @@ static void code_action_perform(Ted *ted, const LSPCodeAction *action) {
LSPServerRequestID request_id = c->last_request;
LSP *lsp = ted_get_lsp_by_id(ted, request_id.lsp);
ted_perform_workspace_edit(ted, lsp, response, &action->edit);
+ switch (action->command.kind) {
+ case LSP_COMMAND_NONE: break;
+ case LSP_COMMAND_WORKSPACE_EDIT:
+ ted_perform_workspace_edit(ted, lsp, response, &action->command.data.edit);
+ break;
+ }
code_action_close(ted);
}
diff --git a/lsp-parse.c b/lsp-parse.c
index 00032db..bb4a10d 100644
--- a/lsp-parse.c
+++ b/lsp-parse.c
@@ -1090,10 +1090,25 @@ static bool parse_formatting_response(LSP *lsp, const JSON *json, LSPResponse *r
return true;
}
-static bool parse_command(LSP *lsp, const JSON *json, JSONObject command_in, LSPCommand *command_out) {
+static bool parse_command(LSP *lsp, LSPResponse *response, const JSON *json, JSONObject command_in, LSPCommand *command_out) {
JSONString command_str = json_object_get_string(json, command_in, "command");
+ JSONArray arguments = json_object_get_array(json, command_in, "arguments");
char command[64];
json_string_get(json, command_str, command, sizeof command);
+ if (strcmp(command, "java.apply.workspaceEdit") == 0) {
+ // why does this exist??
+ if (arguments.len != 1) {
+ lsp_set_error(lsp, "Expected 1 argument to %s; got %" PRIu32, command, arguments.len);
+ return false;
+ }
+ JSONObject edit = json_array_get_object(json, arguments, 0);
+ if (!parse_workspace_edit(lsp, response, json, edit, &command_out->data.edit)) {
+ lsp_workspace_edit_free(&command_out->data.edit);
+ return false;
+ }
+ command_out->kind = LSP_COMMAND_WORKSPACE_EDIT;
+ return true;
+ }
lsp_set_error(lsp, "Unrecognized command: %s\n", command);
(void)command_out;
return false;
@@ -1131,7 +1146,7 @@ static bool parse_code_action_response(LSP *lsp, const JSON *json, LSPResponse *
bool understood = true;
if (command_val.type == JSON_STRING) {
// this action is a Command
- understood &= parse_command(lsp, json, action, &action_out.command);
+ understood &= parse_command(lsp, response, json, action, &action_out.command);
} else {
// this action is a CodeAction
JSONValue edit = json_object_get(json, action, "edit");
@@ -1139,7 +1154,7 @@ static bool parse_code_action_response(LSP *lsp, const JSON *json, LSPResponse *
understood &= parse_workspace_edit(lsp, response, json, edit.val.object, &action_out.edit);
}
if (command_val.type == JSON_OBJECT) {
- understood &= parse_command(lsp, json, command_val.val.object, &action_out.command);
+ understood &= parse_command(lsp, response, json, command_val.val.object, &action_out.command);
}
}
if (understood)
diff --git a/lsp.c b/lsp.c
index 32ccf29..13e9862 100644
--- a/lsp.c
+++ b/lsp.c
@@ -153,7 +153,7 @@ void lsp_request_free(LSPRequest *r) {
memset(r, 0, sizeof *r);
}
-static void lsp_workspace_edit_free(LSPWorkspaceEdit *edit) {
+void lsp_workspace_edit_free(LSPWorkspaceEdit *edit) {
arr_foreach_ptr(edit->changes, LSPWorkspaceChange, c) {
if (c->type == LSP_CHANGE_EDITS) {
arr_free(c->data.edit.edits);
@@ -196,6 +196,12 @@ void lsp_response_free(LSPResponse *r) {
case LSP_REQUEST_CODE_ACTION: {
LSPResponseCodeAction *c = &r->data.code_action;
arr_foreach_ptr(c->actions, LSPCodeAction, action) {
+ switch (action->command.kind) {
+ case LSP_COMMAND_WORKSPACE_EDIT:
+ lsp_workspace_edit_free(&action->command.data.edit);
+ break;
+ default: break;
+ }
lsp_workspace_edit_free(&action->edit);
}
arr_free(c->actions);
@@ -465,7 +471,7 @@ static bool lsp_receive(LSP *lsp, size_t max_size) {
arr_hdr_(lsp->received_data)->len = (u32)received_so_far;
lsp->received_data[received_so_far] = '\0';// null terminate
#if LSP_SHOW_S2C
- const int limit = 1000;
+ const int limit = 10000;
debug_println("%s%.*s%s%s",term_italics(stdout),limit,lsp->received_data,
strlen(lsp->received_data) > (size_t)limit ? "..." : "",
term_clear(stdout));
diff --git a/lsp.h b/lsp.h
index 9ed1a47..a7fa9b0 100644
--- a/lsp.h
+++ b/lsp.h
@@ -575,8 +575,16 @@ typedef struct {
LSPTextEdit *edits;
} LSPResponseFormatting;
+typedef enum {
+ LSP_COMMAND_NONE,
+ LSP_COMMAND_WORKSPACE_EDIT,
+} LSPCommandKind;
+
typedef struct {
- int type;
+ LSPCommandKind kind;
+ union {
+ LSPWorkspaceEdit edit;
+ } data;
} LSPCommand;
typedef enum {
@@ -969,6 +977,7 @@ size_t json_escape_to(char *out, size_t out_sz, const char *in);
char *json_escape(const char *str);
LSPString lsp_response_add_json_string(LSPResponse *response, const JSON *json, JSONString string);
LSPString lsp_request_add_json_string(LSPRequest *request, const JSON *json, JSONString string);
+void lsp_workspace_edit_free(LSPWorkspaceEdit *edit);
/// free resources used by lsp-write.c
void lsp_write_quit(void);
// convert JSON value back into string