Add lsp warnings and updates support (and other minor fixes)

This commit is contained in:
2025-12-25 18:14:45 +00:00
parent 69b981097e
commit f3c87431a3
15 changed files with 928 additions and 61 deletions

View File

@@ -7,6 +7,7 @@
#include "./utils.h"
#include "ts_def.h"
#include <cstdint>
#include <shared_mutex>
#define CHAR 0
#define WORD 1
@@ -95,16 +96,14 @@ struct SpanCursor {
struct VHint {
Coord pos;
char *text; // Can only be a single line with ascii only
uint32_t len;
std::string hint;
bool operator<(const VHint &other) const { return pos < other.pos; }
};
struct VWarn {
uint32_t line;
char *text; // Can only be a single line
uint32_t len;
std::string text;
int8_t type; // For hl
bool operator<(const VWarn &other) const { return line < other.line; }
@@ -158,11 +157,13 @@ struct Editor {
Spans def_spans;
uint32_t hooks[94];
bool jumper_set;
std::shared_mutex v_mtx;
std::vector<VHint> hints;
std::vector<VWarn> warnings;
VAI ai;
std::shared_mutex lsp_mtx;
struct LSPInstance *lsp;
int lsp_version = 1;
};
inline const Fold *fold_for_line(const std::vector<Fold> &folds,
@@ -262,6 +263,6 @@ void apply_line_deletion(Editor *editor, uint32_t removal_start,
uint32_t leading_indent(const char *line, uint32_t len);
uint32_t get_indent(Editor *editor, Coord cursor);
bool closing_after_cursor(const char *line, uint32_t len, uint32_t col);
// void editor_lsp_handle(Editor *editor, json msg);
void editor_lsp_handle(Editor *editor, json msg);
#endif

View File

@@ -7,21 +7,21 @@
#include <unordered_map>
static const std::unordered_map<std::string, Language> kLanguages = {
{"bash", {"bash", tree_sitter_bash}},
{"c", {"c", tree_sitter_c, 1}},
{"cpp", {"cpp", tree_sitter_cpp, 1}},
{"h", {"h", tree_sitter_cpp, 1}},
{"css", {"css", tree_sitter_css}},
{"fish", {"fish", tree_sitter_fish}},
{"go", {"go", tree_sitter_go}},
{"haskell", {"haskell", tree_sitter_haskell}},
{"html", {"html", tree_sitter_html}},
{"javascript", {"javascript", tree_sitter_javascript}},
{"json", {"json", tree_sitter_json}},
{"lua", {"lua", tree_sitter_lua}},
{"make", {"make", tree_sitter_make}},
{"python", {"python", tree_sitter_python}},
{"ruby", {"ruby", tree_sitter_ruby}},
{"bash", {"bash", LANG(bash)}},
{"c", {"c", LANG(c), 1}},
{"cpp", {"cpp", LANG(cpp), 1}},
{"h", {"h", LANG(cpp), 1}},
{"css", {"css", LANG(css)}},
{"fish", {"fish", LANG(fish)}},
{"go", {"go", LANG(go)}},
{"haskell", {"haskell", LANG(haskell)}},
{"html", {"html", LANG(html)}},
{"javascript", {"javascript", LANG(javascript)}},
{"json", {"json", LANG(json)}},
{"lua", {"lua", LANG(lua)}},
{"make", {"make", LANG(make)}},
{"python", {"python", LANG(python)}},
{"ruby", {"ruby", LANG(ruby)}},
};
static const std::unordered_map<uint8_t, LSP> kLsps = {

View File

@@ -3,34 +3,36 @@
#include "./pch.h"
#define LANG(name) tree_sitter_##name
#define TS_DEF(name) extern "C" const TSLanguage *LANG(name)();
struct Language {
std::string name;
const TSLanguage *(*fn)();
uint8_t lsp_id = 0;
};
extern "C" {
const TSLanguage *tree_sitter_bash();
const TSLanguage *tree_sitter_c();
const TSLanguage *tree_sitter_cpp();
const TSLanguage *tree_sitter_css();
const TSLanguage *tree_sitter_fish();
const TSLanguage *tree_sitter_go();
const TSLanguage *tree_sitter_haskell();
const TSLanguage *tree_sitter_html();
const TSLanguage *tree_sitter_javascript();
const TSLanguage *tree_sitter_json();
const TSLanguage *tree_sitter_lua();
const TSLanguage *tree_sitter_make();
const TSLanguage *tree_sitter_python();
const TSLanguage *tree_sitter_ruby();
const TSLanguage *tree_sitter_rust();
TS_DEF(bash)
TS_DEF(c)
TS_DEF(cpp)
TS_DEF(css)
TS_DEF(fish)
TS_DEF(go)
TS_DEF(haskell)
TS_DEF(html)
TS_DEF(javascript)
TS_DEF(json)
TS_DEF(lua)
TS_DEF(make)
TS_DEF(python)
TS_DEF(ruby)
TS_DEF(rust)
// TO ADD
// sql
// wasm
// conf
// yaml, toml
// godot
}
#endif

View File

@@ -82,6 +82,8 @@ extern std::mutex screen_mutex;
Coord start_screen();
void end_screen();
void update(uint32_t row, uint32_t col, std::string utf8, uint32_t fg,
uint32_t bg, uint8_t flags);
void update(uint32_t row, uint32_t col, const char *utf8, uint32_t fg,
uint32_t bg, uint8_t flags);
void set_cursor(int row, int col, int type, bool show_cursor_param);

View File

@@ -62,6 +62,7 @@ void log(const char *fmt, ...);
std::string get_exe_dir();
char *load_file(const char *path, uint32_t *out_len);
char *detect_file_type(const char *filename);
int utf8_byte_offset_to_utf16(const char *s, size_t byte_pos);
Language language_for_file(const char *filename);
void copy_to_clipboard(const char *text, size_t len);
char *get_from_clipboard(uint32_t *out_len);