Switch to OOP style code
This commit is contained in:
+20
-26
@@ -2,52 +2,47 @@
|
||||
#include "editor/editor.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
void apply_lsp_edits(Editor *editor, std::vector<TextEdit> edits, bool move) {
|
||||
void Editor::apply_lsp_edits(std::vector<TextEdit> edits, bool move) {
|
||||
if (!edits.size())
|
||||
return;
|
||||
TextEdit first = edits[0];
|
||||
Coord cursor = editor->cursor;
|
||||
Coord cursor = this->cursor;
|
||||
std::sort(
|
||||
edits.begin(), edits.end(),
|
||||
[](const TextEdit &a, const TextEdit &b) { return a.start > b.start; });
|
||||
for (const auto &edit : edits)
|
||||
edit_replace(editor, edit.start, edit.end, edit.text.c_str(),
|
||||
edit.text.size());
|
||||
this->edit_replace(edit.start, edit.end, edit.text.c_str(),
|
||||
edit.text.size());
|
||||
if (move) {
|
||||
std::shared_lock lock(editor->knot_mtx);
|
||||
editor->cursor = first.start;
|
||||
editor->cursor =
|
||||
move_right(editor, editor->cursor,
|
||||
count_clusters(first.text.c_str(), first.text.size(), 0,
|
||||
first.text.size()));
|
||||
this->cursor = first.start;
|
||||
this->cursor = this->move_right(
|
||||
this->cursor, count_clusters(first.text.c_str(), first.text.size(), 0,
|
||||
first.text.size()));
|
||||
} else {
|
||||
if (cursor.row >= editor->root->line_count) {
|
||||
editor->cursor.row = editor->root->line_count - 1;
|
||||
editor->cursor.col = 0;
|
||||
if (cursor.row >= this->root->line_count) {
|
||||
this->cursor.row = this->root->line_count - 1;
|
||||
this->cursor.col = 0;
|
||||
} else {
|
||||
std::shared_lock lock(editor->knot_mtx);
|
||||
uint32_t len;
|
||||
line_to_byte(editor->root, cursor.row, &len);
|
||||
line_to_byte(this->root, cursor.row, &len);
|
||||
len--;
|
||||
editor->cursor.row = cursor.row;
|
||||
editor->cursor.col = cursor.col < len ? cursor.col : len;
|
||||
this->cursor.row = cursor.row;
|
||||
this->cursor.col = cursor.col < len ? cursor.col : len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void editor_lsp_handle(Editor *editor, json msg) {
|
||||
void Editor::lsp_handle(json msg) {
|
||||
if (msg.contains("method") &&
|
||||
msg["method"] == "textDocument/publishDiagnostics") {
|
||||
std::unique_lock lock(editor->v_mtx);
|
||||
editor->warnings.clear();
|
||||
this->warnings.clear();
|
||||
json diagnostics = msg["params"]["diagnostics"];
|
||||
for (size_t i = 0; i < diagnostics.size(); i++) {
|
||||
json d = diagnostics[i];
|
||||
VWarn w;
|
||||
w.line = d["range"]["start"]["line"];
|
||||
w.start = d["range"]["start"]["character"];
|
||||
std::shared_lock lock(editor->knot_mtx);
|
||||
LineIterator *it = begin_l_iter(editor->root, w.line);
|
||||
LineIterator *it = begin_l_iter(this->root, w.line);
|
||||
if (!it)
|
||||
continue;
|
||||
uint32_t len;
|
||||
@@ -59,7 +54,6 @@ void editor_lsp_handle(Editor *editor, json msg) {
|
||||
}
|
||||
if (len > 0 && line[len - 1] == '\n')
|
||||
--len;
|
||||
lock.unlock();
|
||||
w.start = utf16_offset_to_utf8(line, len, w.start);
|
||||
uint32_t end = d["range"]["end"]["character"];
|
||||
if (d["range"]["end"]["line"] == w.line)
|
||||
@@ -102,9 +96,9 @@ void editor_lsp_handle(Editor *editor, json msg) {
|
||||
w.type = 1;
|
||||
if (d.contains("severity"))
|
||||
w.type = d["severity"].get<int>();
|
||||
editor->warnings.push_back(w);
|
||||
this->warnings.push_back(w);
|
||||
}
|
||||
std::sort(editor->warnings.begin(), editor->warnings.end());
|
||||
editor->warnings_dirty = true;
|
||||
std::sort(this->warnings.begin(), this->warnings.end());
|
||||
this->warnings_dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user