summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-30 10:17:42 -0500
committerpommicket <pommicket@gmail.com>2022-12-30 10:17:42 -0500
commit61db5a1a07f4fbe953d7cab9b6714fe5157a1265 (patch)
treeb06e2590429dcd108bcd00182fbb09cd250a0d38
parenta0f8332da674d452f7ae4f84f01d4682d464c9b2 (diff)
start workspace/symbol
-rw-r--r--buffer.c2
-rw-r--r--lsp-parse.c6
-rw-r--r--lsp-write.c10
-rw-r--r--lsp.c6
-rw-r--r--lsp.h8
5 files changed, 29 insertions, 3 deletions
diff --git a/buffer.c b/buffer.c
index 679da65..8079bf5 100644
--- a/buffer.c
+++ b/buffer.c
@@ -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");
diff --git a/lsp.c b/lsp.c
index 8b147b2..f45603e 100644
--- a/lsp.c
+++ b/lsp.c
@@ -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;
}
diff --git a/lsp.h b/lsp.h
index a5120cd..2f6b090 100644
--- a/lsp.h
+++ b/lsp.h
@@ -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)