diff options
-rw-r--r-- | lsp-parse.c | 6 | ||||
-rw-r--r-- | lsp-write.c | 9 | ||||
-rw-r--r-- | lsp.c | 6 | ||||
-rw-r--r-- | lsp.h | 8 | ||||
-rw-r--r-- | main.c | 6 |
5 files changed, 33 insertions, 2 deletions
diff --git a/lsp-parse.c b/lsp-parse.c index a816ec9..7eb8460 100644 --- a/lsp-parse.c +++ b/lsp-parse.c @@ -158,6 +158,12 @@ static void parse_capabilities(LSP *lsp, const JSON *json, JSONObject capabiliti cap->definition_support = true; } + // check for textDocument/rename support + JSONValue rename_value = json_object_get(json, capabilities, "renameProvider"); + if (rename_value.type != JSON_UNDEFINED) { + cap->rename_support = true; + } + // check for workspace/symbol support JSONValue workspace_symbol_value = json_object_get(json, capabilities, "workspaceSymbolProvider"); if (workspace_symbol_value.type != JSON_UNDEFINED) { diff --git a/lsp-write.c b/lsp-write.c index e5e0d09..41f6d81 100644 --- a/lsp-write.c +++ b/lsp-write.c @@ -273,6 +273,8 @@ static const char *lsp_request_method(LSPRequest *request) { return "textDocument/hover"; case LSP_REQUEST_DEFINITION: return "textDocument/definition"; + case LSP_REQUEST_RENAME: + return "textDocument/rename"; case LSP_REQUEST_WORKSPACE_FOLDERS: return "workspace/workspaceFolders"; case LSP_REQUEST_DID_CHANGE_WORKSPACE_FOLDERS: @@ -535,6 +537,13 @@ static void write_request(LSP *lsp, LSPRequest *request) { write_document_position(o, def->position); write_obj_end(o); } break; + case LSP_REQUEST_RENAME: { + const LSPRequestRename *rename = &request->data.rename; + write_key_obj_start(o, "params"); + write_document_position(o, rename->position); + write_key_string(o, "newName", rename->new_name); + write_obj_end(o); + } break; case LSP_REQUEST_WORKSPACE_SYMBOLS: { const LSPRequestWorkspaceSymbols *syms = &request->data.workspace_symbols; write_key_obj_start(o, "params"); @@ -75,6 +75,9 @@ static void lsp_request_free(LSPRequest *r) { arr_free(w->added); arr_free(w->removed); } break; + case LSP_REQUEST_RENAME: + free(r->data.rename.new_name); + break; case LSP_REQUEST_WORKSPACE_SYMBOLS: free(r->data.workspace_symbols.query); break; @@ -168,6 +171,8 @@ static bool lsp_supports_request(LSP *lsp, const LSPRequest *request) { return cap->definition_support; case LSP_REQUEST_WORKSPACE_SYMBOLS: return cap->workspace_symbols_support; + case LSP_REQUEST_RENAME: + return cap->rename_support; } assert(0); return false; @@ -199,6 +204,7 @@ static bool request_type_is_notification(LSPRequestType type) { case LSP_REQUEST_SIGNATURE_HELP: case LSP_REQUEST_HOVER: case LSP_REQUEST_DEFINITION: + case LSP_REQUEST_RENAME: case LSP_REQUEST_WORKSPACE_SYMBOLS: case LSP_REQUEST_WORKSPACE_FOLDERS: return false; @@ -52,6 +52,7 @@ typedef enum { LSP_REQUEST_SIGNATURE_HELP, // textDocument/signatureHelp LSP_REQUEST_HOVER, // textDocument/hover LSP_REQUEST_DEFINITION, // textDocument/definition + LSP_REQUEST_RENAME, // textDocument/rename LSP_REQUEST_WORKSPACE_SYMBOLS, // workspace/symbol LSP_REQUEST_DID_CHANGE_WORKSPACE_FOLDERS, // workspace/didChangeWorkspaceFolders @@ -152,6 +153,11 @@ typedef struct { } LSPRequestWorkspaceSymbols; typedef struct { + LSPDocumentPosition position; + char *new_name; +} LSPRequestRename; + +typedef struct { LSPDocumentID *removed; // dynamic array LSPDocumentID *added; // dynamic array } LSPRequestDidChangeWorkspaceFolders; @@ -174,6 +180,7 @@ typedef struct { // LSP_REQUEST_SHOW_MESSAGE or LSP_REQUEST_LOG_MESSAGE LSPRequestMessage message; LSPRequestDidChangeWorkspaceFolders change_workspace_folders; + LSPRequestRename rename; } data; } LSPRequest; @@ -380,6 +387,7 @@ typedef struct { // sadly, as of me writing this, clangd and rust-analyzer don't support this // (but jdtls and gopls do) bool workspace_folders_support; + bool rename_support; } LSPCapabilities; typedef struct LSP { @@ -1,9 +1,11 @@ /* @TODO: -- handle multiple symbols with same name - more LSP stuff: - find usages - - refactoring? + - rename + - check for others +- handle multiple symbols with same name in go-to-definition menu +- :go-to-cursor-definition - test full unicode position handling - check if there are any other non-optional/nice-to-have-support-for server-to-client requests - better non-error window/showMessage(Request) |