diff options
author | pommicket <pommicket@gmail.com> | 2022-12-30 10:17:42 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-30 10:17:42 -0500 |
commit | 61db5a1a07f4fbe953d7cab9b6714fe5157a1265 (patch) | |
tree | b06e2590429dcd108bcd00182fbb09cd250a0d38 | |
parent | a0f8332da674d452f7ae4f84f01d4682d464c9b2 (diff) |
start workspace/symbol
-rw-r--r-- | buffer.c | 2 | ||||
-rw-r--r-- | lsp-parse.c | 6 | ||||
-rw-r--r-- | lsp-write.c | 10 | ||||
-rw-r--r-- | lsp.c | 6 | ||||
-rw-r--r-- | lsp.h | 8 |
5 files changed, 29 insertions, 3 deletions
@@ -314,6 +314,8 @@ static void buffer_send_lsp_did_open(TextBuffer *buffer, LSP *lsp, char *buffer_ LSP *buffer_lsp(TextBuffer *buffer) { if (!buffer_is_named_file(buffer)) return NULL; + if (buffer->view_only) + return NULL; // we don't really want to start up an LSP in /usr/include LSP *true_lsp = ted_get_lsp(buffer->ted, buffer->filename, buffer_language(buffer)); LSP *curr_lsp = ted_get_lsp_by_id(buffer->ted, buffer->lsp_opened_in); if (true_lsp != curr_lsp) { diff --git a/lsp-parse.c b/lsp-parse.c index a6ef49f..42a3c7b 100644 --- a/lsp-parse.c +++ b/lsp-parse.c @@ -161,6 +161,12 @@ static void parse_capabilities(LSP *lsp, const JSON *json, JSONObject capabiliti cap->definition_support = true; } + // check for workspace/symbol support + JSONValue workspace_symbol_value = json_object_get(json, capabilities, "workspaceSymbolProvider"); + if (workspace_symbol_value.type != JSON_UNDEFINED) { + cap->workspace_symbols_support = true; + } + JSONObject workspace = json_object_get_object(json, capabilities, "workspace"); // check WorkspaceFoldersServerCapabilities JSONObject workspace_folders = json_object_get_object(json, workspace, "workspaceFolders"); diff --git a/lsp-write.c b/lsp-write.c index 82ba5b4..4068479 100644 --- a/lsp-write.c +++ b/lsp-write.c @@ -277,13 +277,13 @@ static const char *lsp_request_method(LSPRequest *request) { return "workspace/didChangeWorkspaceFolders"; case LSP_REQUEST_JDTLS_CONFIGURATION: return "workspace/didChangeConfiguration"; + case LSP_REQUEST_WORKSPACE_SYMBOLS: + return "workspace/symbol"; } assert(0); return "$/ignore"; } - - static const size_t max_header_size = 64; static JSONWriter message_writer_new(LSP *lsp) { JSONWriter writer = json_writer_new(lsp); @@ -500,6 +500,12 @@ static void write_request(LSP *lsp, LSPRequest *request) { write_document_position(o, def->position); write_obj_end(o); } break; + case LSP_REQUEST_WORKSPACE_SYMBOLS: { + const LSPRequestWorkspaceSymbols *syms = &request->data.workspace_symbols; + write_key_obj_start(o, "params"); + write_key_string(o, "query", syms->query); + write_obj_end(o); + } break; case LSP_REQUEST_DID_CHANGE_WORKSPACE_FOLDERS: { const LSPRequestDidChangeWorkspaceFolders *w = &request->data.change_workspace_folders; write_key_obj_start(o, "params"); @@ -67,6 +67,9 @@ static void lsp_request_free(LSPRequest *r) { arr_free(w->added); arr_free(w->removed); } break; + case LSP_REQUEST_WORKSPACE_SYMBOLS: + free(r->data.workspace_symbols.query); + break; } memset(r, 0, sizeof *r); } @@ -151,6 +154,8 @@ static bool lsp_supports_request(LSP *lsp, const LSPRequest *request) { return cap->hover_support; case LSP_REQUEST_DEFINITION: return cap->definition_support; + case LSP_REQUEST_WORKSPACE_SYMBOLS: + return cap->workspace_symbols_support; } assert(0); return false; @@ -181,6 +186,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_WORKSPACE_SYMBOLS: case LSP_REQUEST_WORKSPACE_FOLDERS: return false; } @@ -51,6 +51,7 @@ typedef enum { LSP_REQUEST_SIGNATURE_HELP, // textDocument/signatureHelp LSP_REQUEST_HOVER, // textDocument/hover LSP_REQUEST_DEFINITION, // textDocument/definition + LSP_REQUEST_WORKSPACE_SYMBOLS, // workspace/symbol LSP_REQUEST_DID_CHANGE_WORKSPACE_FOLDERS, // workspace/didChangeWorkspaceFolders // server-to-client @@ -128,12 +129,15 @@ typedef struct { } LSPRequestDefinition; typedef struct { + char *query; +} LSPRequestWorkspaceSymbols; + +typedef struct { LSPDocumentID *removed; // dynamic array LSPDocumentID *added; // dynamic array } LSPRequestDidChangeWorkspaceFolders; typedef struct { - // id is set by lsp.c; you shouldn't set it. u32 id; LSPRequestType type; char *id_string; // if not NULL, this is the ID (only for server-to-client messages; we always use integer IDs) @@ -146,6 +150,7 @@ typedef struct { LSPRequestSignatureHelp signature_help; LSPRequestHover hover; LSPRequestDefinition definition; + LSPRequestWorkspaceSymbols workspace_symbols; // LSP_REQUEST_SHOW_MESSAGE or LSP_REQUEST_LOG_MESSAGE LSPRequestMessage message; LSPRequestDidChangeWorkspaceFolders change_workspace_folders; @@ -331,6 +336,7 @@ typedef struct { bool completion_support; bool hover_support; bool definition_support; + bool workspace_symbols_support; // support for multiple root folders // sadly, as of me writing this, clangd and rust-analyzer don't support this // (but jdtls and gopls do) |