summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-30 16:27:31 -0500
committerpommicket <pommicket@gmail.com>2022-12-30 16:27:31 -0500
commit72624969e99d284984614a33cabb4ed9fea31a0a (patch)
tree0339461c7d415a4a8cb7fa894e6306804b9c3739
parentad841a324e905559ab7640956b0fbe2d2fdb3b77 (diff)
write rename request
-rw-r--r--lsp-parse.c6
-rw-r--r--lsp-write.c9
-rw-r--r--lsp.c6
-rw-r--r--lsp.h8
-rw-r--r--main.c6
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");
diff --git a/lsp.c b/lsp.c
index 875aab2..18b150e 100644
--- a/lsp.c
+++ b/lsp.c
@@ -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;
diff --git a/lsp.h b/lsp.h
index 5d5f3c4..57c81b5 100644
--- a/lsp.h
+++ b/lsp.h
@@ -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 {
diff --git a/main.c b/main.c
index 211b47a..63a07a1 100644
--- a/main.c
+++ b/main.c
@@ -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)