Lsp completion logic

This commit is contained in:
2026-01-04 03:27:17 +00:00
parent ac04754318
commit a905e333fc
24 changed files with 624 additions and 136 deletions
+27
View File
@@ -1,6 +1,8 @@
#include "editor/editor.h"
#include "editor/folds.h"
#include "lsp/lsp.h"
#include "utils/utils.h"
#include <cstdint>
void edit_erase(Editor *editor, Coord pos, int64_t len) {
if (len == 0)
@@ -278,3 +280,28 @@ void edit_insert(Editor *editor, Coord pos, char *data, uint32_t len) {
}
}
}
void edit_replace(Editor *editor, Coord start, Coord end, const char *text,
uint32_t len) {
std::shared_lock lock(editor->knot_mtx);
uint32_t start_line_byte = line_to_byte(editor->root, start.row, nullptr);
uint32_t end_len;
uint32_t end_line_byte_start = line_to_byte(editor->root, end.row, &end_len);
uint32_t end_line_byte = end_line_byte_start + len;
lock.unlock();
char *buf =
read(editor->root, start_line_byte, end_line_byte - start_line_byte);
if (!buf)
return;
uint32_t start_col = utf16_offset_to_utf8(buf, start.col);
uint32_t end_col = utf16_offset_to_utf8(
buf + (end_line_byte_start - start_line_byte), end.col);
uint32_t erase_len =
count_clusters(buf, end_line_byte - start_line_byte, start_col,
(end_line_byte_start - start_line_byte) + end_col);
free(buf);
if (erase_len != 0)
edit_erase(editor, end, -erase_len);
if (len > 0)
edit_insert(editor, start, const_cast<char *>(text), len);
}