Skip to content

Commit 044c6af

Browse files
committed
feat: update to work with text modification
1 parent 69d32ac commit 044c6af

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

lsp_client.cpp

+14-11
Original file line numberDiff line numberDiff line change
@@ -409,23 +409,26 @@ void LSPClient::make_did_open_request(const std::string &file_path) {
409409
document_uri_to_version[uri] = 1;
410410
}
411411

412-
void LSPClient::make_did_change_request(const std::string &file_path, const TextDiff &text_diff) {
412+
void LSPClient::make_did_change_request(const std::string &file_path, const TextModification &text_diff) {
413413
std::string full_path = get_full_path(file_path);
414414
std::string uri = to_file_uri(full_path);
415415

416416
int &version = document_uri_to_version[uri];
417417
version++;
418418

419-
JSON did_change_request = {
420-
{"jsonrpc", "2.0"},
421-
{"method", "textDocument/didChange"},
422-
{"params",
423-
{{"textDocument", {{"uri", uri}, {"version", version}}},
424-
{"contentChanges",
425-
{{{"range",
426-
{{"start", {{"line", text_diff.text_range.start_line}, {"character", text_diff.text_range.start_col}}},
427-
{"end", {{"line", text_diff.text_range.end_line}, {"character", text_diff.text_range.end_col}}}}},
428-
{"text", text_diff.new_content}}}}}}};
419+
JSON did_change_request = {{"jsonrpc", "2.0"},
420+
{"method", "textDocument/didChange"},
421+
{"params",
422+
{{"textDocument", {{"uri", uri}, {"version", version}}},
423+
{"contentChanges",
424+
{{{"range",
425+
{{"start",
426+
{{"line", text_diff.text_range_to_replace.start_line},
427+
{"character", text_diff.text_range_to_replace.start_col}}},
428+
{"end",
429+
{{"line", text_diff.text_range_to_replace.end_line},
430+
{"character", text_diff.text_range_to_replace.end_col}}}}},
431+
{"text", text_diff.new_content}}}}}}};
429432

430433
lsp_communication.make_json_lsp_request(did_change_request);
431434
}

lsp_client.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class LSPClient { // NOTE: only tested to work with LSP 3.17 standard
100100

101101
std::string get_full_path(const std::string &file_path) const;
102102
void make_did_open_request(const std::string &file);
103-
void make_did_change_request(const std::string &file_path, const TextDiff &text_diff);
103+
void make_did_change_request(const std::string &file_path, const TextModification &text_diff);
104104
void make_go_to_definition_request(const std::string &file, int line, int col, std::function<void(JSON)> callback);
105105

106106
// old stuff below

0 commit comments

Comments
 (0)