summaryrefslogtreecommitdiff
path: root/lsp-write-request.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-22 16:27:06 -0500
committerpommicket <pommicket@gmail.com>2022-12-22 16:27:06 -0500
commit6bb4da5fab94d2ed3d093b996674fd1cc28eda2f (patch)
treed986574a0100cd4d35782585a8309815f8bf1b49 /lsp-write-request.c
parentf2296487cf9b2e86261eaf1d448b723f3ef70202 (diff)
document IDs instead of documents
Diffstat (limited to 'lsp-write-request.c')
-rw-r--r--lsp-write-request.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/lsp-write-request.c b/lsp-write-request.c
index de314aa..e5d671d 100644
--- a/lsp-write-request.c
+++ b/lsp-write-request.c
@@ -33,12 +33,14 @@ static const char *lsp_language_id(Language lang) {
typedef struct {
+ LSP *lsp;
StrBuilder builder;
bool is_first;
} JSONWriter;
-static JSONWriter json_writer_new(void) {
+static JSONWriter json_writer_new(LSP *lsp) {
return (JSONWriter){
+ .lsp = lsp,
.builder = str_builder_new(),
.is_first = true
};
@@ -118,15 +120,16 @@ static void write_key_string(JSONWriter *o, const char *key, const char *s) {
write_string(o, s);
}
-static void write_file_uri(JSONWriter *o, const char *path) {
- char *escaped_path = json_escape(path);
+static void write_file_uri(JSONWriter *o, DocumentID document) {
+ // @OPTIM : could store escaped document paths instead of document paths
+ char *escaped_path = json_escape(o->lsp->document_paths[document]);
str_builder_appendf(&o->builder, "\"file:///%s\"", escaped_path);
free(escaped_path);
}
-static void write_key_file_uri(JSONWriter *o, const char *key, const char *path) {
+static void write_key_file_uri(JSONWriter *o, const char *key, DocumentID document) {
write_key(o, key);
- write_file_uri(o, path);
+ write_file_uri(o, document);
}
static void write_position(JSONWriter *o, LSPPosition position) {
@@ -199,7 +202,7 @@ static bool request_type_is_notification(LSPRequestType type) {
}
static void write_request(LSP *lsp, LSPRequest *request) {
- JSONWriter writer = json_writer_new();
+ JSONWriter writer = json_writer_new(lsp);
JSONWriter *o = &writer;
u32 max_header_size = 64;