Fix lsp bugs
- Fix: Incorrect setting of incremental edits for lsp and more
This commit is contained in:
@@ -156,7 +156,7 @@ struct Editor {
|
||||
std::vector<VWarn> warnings;
|
||||
VAI ai;
|
||||
std::shared_mutex lsp_mtx;
|
||||
struct LSPInstance *lsp;
|
||||
std::shared_ptr<struct LSPInstance> lsp;
|
||||
int lsp_version = 1;
|
||||
};
|
||||
|
||||
|
||||
@@ -29,28 +29,33 @@ struct LSPInstance {
|
||||
int pid{-1};
|
||||
int stdin_fd{-1};
|
||||
int stdout_fd{-1};
|
||||
bool initialized = false;
|
||||
bool incremental_sync = true;
|
||||
std::atomic<bool> initialized = false;
|
||||
std::atomic<bool> exited = false;
|
||||
bool incremental_sync = false;
|
||||
uint32_t last_id = 0;
|
||||
Queue<json> inbox;
|
||||
Queue<json> outbox;
|
||||
Queue<std::pair<Language, Editor *>> open_queue;
|
||||
std::unordered_map<uint32_t, LSPPending *> pending;
|
||||
std::vector<Editor *> editors;
|
||||
};
|
||||
|
||||
extern std::shared_mutex active_lsps_mtx;
|
||||
extern std::unordered_map<uint8_t, LSPInstance *> active_lsps;
|
||||
extern std::unordered_map<uint8_t, std::shared_ptr<LSPInstance>> active_lsps;
|
||||
|
||||
void lsp_worker();
|
||||
void lsp_handle(LSPInstance *lsp, json message);
|
||||
void lsp_handle(std::shared_ptr<LSPInstance> lsp, json message);
|
||||
|
||||
LSPInstance *get_or_init_lsp(uint8_t lsp_id);
|
||||
std::shared_ptr<LSPInstance> get_or_init_lsp(uint8_t lsp_id);
|
||||
void close_lsp(uint8_t lsp_id);
|
||||
|
||||
void request_add_to_lsp(Language language, Editor *editor);
|
||||
void open_editor(std::shared_ptr<LSPInstance> lsp,
|
||||
std::pair<Language, Editor *> entry);
|
||||
void add_to_lsp(Language language, Editor *editor);
|
||||
void remove_from_lsp(Editor *editor);
|
||||
|
||||
void lsp_send(LSPInstance *lsp, json message, LSPPending *pending);
|
||||
void lsp_send(std::shared_ptr<LSPInstance> lsp, json message,
|
||||
LSPPending *pending);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -155,6 +155,15 @@ static const std::unordered_map<uint8_t, LSP> kLsps = {
|
||||
"make-language-server",
|
||||
nullptr,
|
||||
}}},
|
||||
{22,
|
||||
{"sql-language-server",
|
||||
{
|
||||
"sql-language-server",
|
||||
"up",
|
||||
"--method",
|
||||
"stdio",
|
||||
nullptr,
|
||||
}}},
|
||||
};
|
||||
|
||||
static const std::unordered_map<std::string, Language> kLanguages = {
|
||||
@@ -170,6 +179,7 @@ static const std::unordered_map<std::string, Language> kLanguages = {
|
||||
{"html", {"html", LANG(html), 10}},
|
||||
{"javascript", {"javascript", LANG(javascript), 11}},
|
||||
{"json", {"json", LANG(json), 6}},
|
||||
{"jsonc", {"jsonc", LANG(json), 6}},
|
||||
{"erb", {"erb", LANG(embedded_template), 10}},
|
||||
{"ruby", {"ruby", LANG(ruby), 3}},
|
||||
{"lua", {"lua", LANG(lua), 12}},
|
||||
@@ -181,7 +191,8 @@ static const std::unordered_map<std::string, Language> kLanguages = {
|
||||
{"nginx", {"nginx", LANG(nginx), 17}},
|
||||
{"toml", {"toml", LANG(toml), 18}},
|
||||
{"yaml", {"yaml", LANG(yaml), 19}},
|
||||
{"sql", {"sql", LANG(sql), 20}},
|
||||
{"sql", {"sql", LANG(sql), 20}}, // Can use `22` for more accuracy but need
|
||||
// config to connect to database
|
||||
{"make", {"make", LANG(make), 21}},
|
||||
{"gdscript", {"gdscript", LANG(gdscript)}}, // TODO: connect to godot
|
||||
{"diff", {"diff", LANG(diff)}},
|
||||
@@ -212,7 +223,7 @@ static const std::unordered_map<std::string, std::string> kExtToLang = {
|
||||
{"js", "javascript"},
|
||||
{"jsx", "javascript"},
|
||||
{"json", "json"},
|
||||
{"jsonc", "json"},
|
||||
{"jsonc", "jsonc"},
|
||||
{"lua", "lua"},
|
||||
{"mk", "make"},
|
||||
{"makefile", "make"},
|
||||
|
||||
@@ -12,8 +12,9 @@ template <typename T> struct Queue {
|
||||
std::lock_guard<std::mutex> lock(m);
|
||||
q.push(val);
|
||||
}
|
||||
T front() {
|
||||
std::lock_guard<std::mutex> lock(m);
|
||||
std::optional<T> front() {
|
||||
if (q.empty())
|
||||
return std::nullopt;
|
||||
return q.front();
|
||||
}
|
||||
bool pop(T &val) {
|
||||
|
||||
Reference in New Issue
Block a user