popup and diagnose ui
This commit is contained in:
@@ -7,6 +7,6 @@
|
||||
|
||||
void abAppend(struct abuf *ab, const char *s, int len);
|
||||
|
||||
void abFree(struct abuf *ab);
|
||||
void abFree(const struct abuf *ab);
|
||||
|
||||
#endif // APPEND_BUFFER_H_
|
||||
|
||||
+8
-11
@@ -7,23 +7,20 @@
|
||||
#include "data.h"
|
||||
|
||||
|
||||
|
||||
void createContextBuffer(const int x, const int y, const char * text);
|
||||
|
||||
int lspStart(LspClient *lsp, const char *project_root);
|
||||
void lspShutdown(LspClient *lsp);
|
||||
int lspStart(LspClient* lsp, const char* project_root);
|
||||
void lspShutdown(LspClient* lsp);
|
||||
|
||||
// Document sync — call these from your buffer open/save/edit hooks
|
||||
void lspDidOpen(LspClient *lsp, struct buffer_t *buf);
|
||||
void lspDidChange(LspClient *lsp, struct buffer_t *buf);
|
||||
void lspDidClose(LspClient *lsp, struct buffer_t *buf);
|
||||
void lspDidOpen(LspClient* lsp, struct buffer_t* buf);
|
||||
void lspDidChange(LspClient* lsp, struct buffer_t* buf);
|
||||
void lspDidClose(LspClient* lsp, struct buffer_t* buf);
|
||||
|
||||
// Requests
|
||||
void lspRequestCompletion(LspClient *lsp, struct buffer_t *buf,
|
||||
void lspRequestCompletion(LspClient* lsp, struct buffer_t* buf,
|
||||
int line, int col,
|
||||
int screen_x, int screen_y);
|
||||
void lspRequestHover(LspClient *lsp, struct buffer_t *buf, int line, int col);
|
||||
void lspRequestDefinition(LspClient *lsp, struct buffer_t *buf, int line, int col);
|
||||
void lspRequestHover(LspClient* lsp, struct buffer_t* buf, int line, int col);
|
||||
void lspRequestDefinition(LspClient* lsp, struct buffer_t* buf, int line, int col);
|
||||
|
||||
|
||||
#endif //BELUGA_COMPLETION_H
|
||||
|
||||
+158
-146
@@ -17,85 +17,94 @@ typedef struct lsp_client_t LspClient;
|
||||
* \param
|
||||
* */
|
||||
|
||||
typedef struct row {
|
||||
int size; /**< Size of the line */
|
||||
int cap; /**< Size of the render line */
|
||||
char *chars; /**< Characters of the line */
|
||||
typedef struct row
|
||||
{
|
||||
int size; /**< Size of the line */
|
||||
int cap; /**< Size of the render line */
|
||||
char* chars; /**< Characters of the line */
|
||||
} row_t;
|
||||
|
||||
typedef struct context_buffer_t
|
||||
{
|
||||
int editor_x, editor_y;
|
||||
int width, height;
|
||||
row_t *rows;
|
||||
int editor_x, editor_y;
|
||||
int width, height;
|
||||
row_t* rows;
|
||||
} ContextBuffer;
|
||||
|
||||
/**
|
||||
* @brief Split modes for screen layout
|
||||
*/
|
||||
typedef enum {
|
||||
SPLIT_NONE = 0, // Single buffer fullscreen
|
||||
SPLIT_VERTICAL, // Left-right split
|
||||
SPLIT_HORIZONTAL // Top-bottom split
|
||||
typedef enum
|
||||
{
|
||||
SPLIT_NONE = 0, // Single buffer fullscreen
|
||||
SPLIT_VERTICAL, // Left-right split
|
||||
SPLIT_HORIZONTAL // Top-bottom split
|
||||
} SplitMode;
|
||||
|
||||
/**
|
||||
* @brief Represents an editor viewport/pane
|
||||
*/
|
||||
typedef struct {
|
||||
int buffer_id; // Which buffer this pane displays
|
||||
int height; // Height of this pane
|
||||
int width; // Width of this pane
|
||||
typedef struct
|
||||
{
|
||||
int buffer_id; // Which buffer this pane displays
|
||||
int height; // Height of this pane
|
||||
int width; // Width of this pane
|
||||
int origin_x, origin_y;
|
||||
int cursor_x; // Local cursor x in this pane
|
||||
int cursor_y; // Local cursor y in this pane
|
||||
int cursor_x; // Local cursor x in this pane
|
||||
int cursor_y; // Local cursor y in this pane
|
||||
int x_offset, y_offset;
|
||||
int is_active; // Is this pane currently active
|
||||
int is_active; // Is this pane currently active
|
||||
} EditorPane;
|
||||
|
||||
/**
|
||||
* @brief Screen layout manager
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
SplitMode mode;
|
||||
EditorPane *panes;
|
||||
EditorPane* panes;
|
||||
int num_panes;
|
||||
int active_pane; // Index of active pane
|
||||
int active_pane; // Index of active pane
|
||||
} ScreenLayout;
|
||||
|
||||
|
||||
typedef struct theme {
|
||||
char *BACKGROUND_COLOR;
|
||||
char *COLOR_KEYWORD;
|
||||
char *COLOR_TYPE;
|
||||
char *COLOR_STRING;
|
||||
char *COLOR_COMMENT;
|
||||
char *COLOR_NUMBER;
|
||||
char *COLOR_DEFAULT;
|
||||
|
||||
typedef struct theme
|
||||
{
|
||||
char* BACKGROUND_COLOR;
|
||||
char* COLOR_KEYWORD;
|
||||
char* COLOR_TYPE;
|
||||
char* COLOR_STRING;
|
||||
char* COLOR_COMMENT;
|
||||
char* COLOR_NUMBER;
|
||||
char* COLOR_DEFAULT;
|
||||
} theme_t;
|
||||
|
||||
enum bufferStatus_e {
|
||||
IDLE,
|
||||
READ_ONLY,
|
||||
READ_AND_WRITE,
|
||||
enum bufferStatus_e
|
||||
{
|
||||
IDLE,
|
||||
READ_ONLY,
|
||||
READ_AND_WRITE,
|
||||
};
|
||||
|
||||
struct const_t {
|
||||
int TAB_LENGTH;
|
||||
int QUIT_TIMES;
|
||||
char *THEME;
|
||||
struct const_t
|
||||
{
|
||||
int TAB_LENGTH;
|
||||
int QUIT_TIMES;
|
||||
char* THEME;
|
||||
int LSP;
|
||||
};
|
||||
|
||||
struct prefix_t {
|
||||
char prefix_name[64];
|
||||
int prefix_id;
|
||||
struct prefix_t
|
||||
{
|
||||
char prefix_name[64];
|
||||
int prefix_id;
|
||||
};
|
||||
|
||||
struct keyBind_t {
|
||||
char *key_sequence;
|
||||
int prefix_id;
|
||||
Lisp command;
|
||||
struct keyBind_t
|
||||
{
|
||||
char* key_sequence;
|
||||
int prefix_id;
|
||||
Lisp command;
|
||||
};
|
||||
|
||||
// In data.h — add these
|
||||
@@ -104,142 +113,144 @@ struct keyBind_t {
|
||||
|
||||
#define LSP_MAX_PENDING 64
|
||||
|
||||
typedef enum {
|
||||
LSP_NOT_STARTED = 0,
|
||||
LSP_INITIALIZING,
|
||||
LSP_READY,
|
||||
LSP_SHUTDOWN,
|
||||
typedef enum
|
||||
{
|
||||
LSP_NOT_STARTED = 0,
|
||||
LSP_INITIALIZING,
|
||||
LSP_READY,
|
||||
LSP_SHUTDOWN,
|
||||
} LspState;
|
||||
|
||||
typedef struct {
|
||||
int id;
|
||||
void (*callback)(struct lsp_client_t *lsp, const char *json);
|
||||
typedef struct
|
||||
{
|
||||
int id;
|
||||
void (*callback)(struct lsp_client_t* lsp, const char* json);
|
||||
} LspPending;
|
||||
|
||||
typedef struct lsp_client_t {
|
||||
// ── Process ───────────────────────────────────────────────────────────────
|
||||
pid_t pid;
|
||||
int write_fd;
|
||||
int read_fd;
|
||||
int completion_just_arrived;
|
||||
int completion_requested;
|
||||
typedef struct lsp_client_t
|
||||
{
|
||||
// ── Process ───────────────────────────────────────────────────────────────
|
||||
pid_t pid;
|
||||
int write_fd;
|
||||
int read_fd;
|
||||
int completion_just_arrived;
|
||||
int completion_requested;
|
||||
|
||||
int wake_pipe[2]; // [0] = read end (main loop), [1] = write end (reader thread)
|
||||
// ── State ─────────────────────────────────────────────────────────────────
|
||||
LspState state;
|
||||
int next_id;
|
||||
|
||||
// ── Pending requests ──────────────────────────────────────────────────────
|
||||
LspPending pending[LSP_MAX_PENDING];
|
||||
int pending_count;
|
||||
|
||||
int wake_pipe[2]; // [0] = read end (main loop), [1] = write end (reader thread)
|
||||
// ── Threading ─────────────────────────────────────────────────────────────
|
||||
pthread_t reader_thread;
|
||||
pthread_mutex_t lock;
|
||||
pthread_cond_t ready_cond; // signaled when state → LSP_READY
|
||||
|
||||
|
||||
// ── State ─────────────────────────────────────────────────────────────────
|
||||
LspState state;
|
||||
int next_id;
|
||||
|
||||
// ── Pending requests ──────────────────────────────────────────────────────
|
||||
LspPending pending[LSP_MAX_PENDING];
|
||||
int pending_count;
|
||||
|
||||
// ── Threading ─────────────────────────────────────────────────────────────
|
||||
pthread_t reader_thread;
|
||||
pthread_mutex_t lock;
|
||||
pthread_cond_t ready_cond; // signaled when state → LSP_READY
|
||||
|
||||
// ── Completion context ────────────────────────────────────────────────────
|
||||
int completion_cursor_x; // screen position when
|
||||
int completion_cursor_y; // completion was requested
|
||||
// ── Completion context ────────────────────────────────────────────────────
|
||||
int completion_cursor_x; // screen position when
|
||||
int completion_cursor_y; // completion was requested
|
||||
} LspClient;
|
||||
|
||||
typedef struct {
|
||||
char label[128]; // display text e.g. "printf"
|
||||
char detail[64]; // type/sig hint e.g. "int (const char *, ...)"
|
||||
int kind; // LSP CompletionItemKind (1=Text,2=Method,3=Function…)
|
||||
typedef struct
|
||||
{
|
||||
char label[128]; // display text e.g. "printf"
|
||||
char detail[64]; // type/sig hint e.g. "int (const char *, ...)"
|
||||
int kind; // LSP CompletionItemKind (1=Text,2=Method,3=Function…)
|
||||
} CompletionItem;
|
||||
|
||||
typedef struct {
|
||||
CompletionItem items[COMPLETION_MAX_ITEMS];
|
||||
int count;
|
||||
int selected; // currently highlighted row
|
||||
int visible; // is the popup shown?
|
||||
int origin_x; // screen col where popup appears
|
||||
int origin_y; // screen row where popup appears
|
||||
typedef struct
|
||||
{
|
||||
CompletionItem items[COMPLETION_MAX_ITEMS];
|
||||
int count;
|
||||
int selected; // currently highlighted row
|
||||
int visible; // is the popup shown?
|
||||
int origin_x; // screen col where popup appears
|
||||
int origin_y; // screen row where popup appears
|
||||
} CompletionPopup;
|
||||
|
||||
typedef enum { DIAG_ERROR = 1, DIAG_WARNING, DIAG_HINT } DiagSeverity;
|
||||
|
||||
typedef struct {
|
||||
int buffer_id;
|
||||
int line; // 0-based
|
||||
int col_start; // 0-based
|
||||
int col_end;
|
||||
DiagSeverity severity;
|
||||
char message[256];
|
||||
typedef struct
|
||||
{
|
||||
int buffer_id;
|
||||
int line; // 0-based
|
||||
int col_start; // 0-based
|
||||
int col_end;
|
||||
DiagSeverity severity;
|
||||
char message[256];
|
||||
} Diagnostic;
|
||||
|
||||
typedef struct {
|
||||
Diagnostic entries[DIAG_MAX];
|
||||
int count;
|
||||
typedef struct
|
||||
{
|
||||
Diagnostic entries[DIAG_MAX];
|
||||
int count;
|
||||
} DiagnosticList;
|
||||
|
||||
enum buffer_type { FILE_BUFF, TERMINAL_BUFF };
|
||||
|
||||
struct buffer_t {
|
||||
enum buffer_type type;
|
||||
int buffer_id;
|
||||
int b_lsp_open;
|
||||
int x, y; /**< Position in the file */
|
||||
row_t *row;
|
||||
int numrows;
|
||||
int b_has_changed;
|
||||
char *filename;
|
||||
char *path;
|
||||
enum bufferStatus_e state;
|
||||
int dirty; /**< Has this buffer been modified since last save */
|
||||
struct buffer_t
|
||||
{
|
||||
enum buffer_type type;
|
||||
int buffer_id;
|
||||
int b_lsp_open;
|
||||
int x, y; /**< Position in the file */
|
||||
row_t* row;
|
||||
int numrows;
|
||||
int b_has_changed;
|
||||
char* filename;
|
||||
char* path;
|
||||
char * fullname;
|
||||
enum bufferStatus_e state;
|
||||
int dirty; /**< Has this buffer been modified since last save */
|
||||
};
|
||||
|
||||
/**
|
||||
* \struct editorConfig
|
||||
* \brief Containing our editor state.
|
||||
*/
|
||||
struct editorConfig {
|
||||
int cursor_x, cursor_y; /**< Cursor position */
|
||||
int screenrows; /**< Terminal height*/
|
||||
int screencols; /**< Terminal width*/
|
||||
struct editorConfig
|
||||
{
|
||||
int cursor_x, cursor_y; /**< Cursor position */
|
||||
int screenrows; /**< Terminal height*/
|
||||
int screencols; /**< Terminal width*/
|
||||
|
||||
ScreenLayout layout;
|
||||
ScreenLayout layout;
|
||||
|
||||
row_t *rows; /**< Store all the rows printed */
|
||||
LspClient* lsp_client;
|
||||
CompletionPopup lsp_completion;
|
||||
DiagnosticList lsp_diagnostics;
|
||||
|
||||
ContextBuffer* context_buffers;
|
||||
int dirty;
|
||||
|
||||
LspClient *lsp_client;
|
||||
CompletionPopup lsp_completion;
|
||||
DiagnosticList lsp_diagnostics;
|
||||
char* status_msg;
|
||||
time_t status_msg_time;
|
||||
struct termios orig_termios; /**< Terminal communication interface */
|
||||
|
||||
int dirty;
|
||||
struct const_t constantes;
|
||||
int quit_times_buffer;
|
||||
|
||||
char *status_msg;
|
||||
time_t status_msg_time;
|
||||
struct termios orig_termios; /**< Terminal communication interface */
|
||||
char* init_file_path;
|
||||
FILE* fd_init_file;
|
||||
Lisp env;
|
||||
LispContext ctx; /** Lisp context */
|
||||
Lisp ctx_data; /** Lisp data context */
|
||||
LispError ctx_error; /** Lisp ctx error */
|
||||
|
||||
struct const_t constantes;
|
||||
int quit_times_buffer;
|
||||
struct keyBind_t* key_binds;
|
||||
int number_of_keybinds;
|
||||
|
||||
char *init_file_path;
|
||||
FILE *fd_init_file;
|
||||
Lisp env;
|
||||
LispContext ctx; /** Lisp context */
|
||||
Lisp ctx_data; /** Lisp data context */
|
||||
LispError ctx_error; /** Lisp ctx error */
|
||||
struct prefix_t* prefix;
|
||||
int number_of_prefix;
|
||||
int prefix_state;
|
||||
|
||||
struct keyBind_t *key_binds;
|
||||
int number_of_keybinds;
|
||||
struct buffer_t buffers[64];
|
||||
int number_of_buffer;
|
||||
|
||||
struct prefix_t *prefix;
|
||||
int number_of_prefix;
|
||||
int prefix_state;
|
||||
|
||||
struct buffer_t buffers[64];
|
||||
int number_of_buffer;
|
||||
|
||||
theme_t theme;
|
||||
theme_t theme;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -247,9 +258,10 @@ struct editorConfig {
|
||||
* \brief Contains text to add before writing to screen.
|
||||
* */
|
||||
|
||||
struct abuf {
|
||||
char *b; /**< Text that will be printed */
|
||||
int len; /**< Length of the text */
|
||||
struct abuf
|
||||
{
|
||||
char* b; /**< Text that will be printed */
|
||||
int len; /**< Length of the text */
|
||||
};
|
||||
|
||||
extern struct editorConfig E;
|
||||
|
||||
+4
-1
@@ -12,7 +12,9 @@
|
||||
#define ERASE_END_LINE "\x1b[K"
|
||||
#define TAB "\t"
|
||||
#define SPACE "\x20"
|
||||
#define APP_DEBUG
|
||||
|
||||
/* Uncomment to see debug logs on stderr */
|
||||
// #define APP_DEBUG
|
||||
|
||||
#define COMPLETION_MAX_ITEMS 16
|
||||
#define COMPLETION_MAX_WIDTH 40
|
||||
@@ -32,6 +34,7 @@ enum editorKey_e {
|
||||
END_LINE,
|
||||
PAGE_UP,
|
||||
PAGE_DOWN,
|
||||
LSP_WAKE_KEY = 2000
|
||||
};
|
||||
|
||||
#define ABUF_INIT {NULL, 0}
|
||||
|
||||
@@ -11,4 +11,7 @@ void initBuiltins();
|
||||
|
||||
void initEditor();
|
||||
|
||||
void deInitEditor();
|
||||
|
||||
|
||||
#endif // INIT_H_
|
||||
|
||||
+2
-2
@@ -1163,7 +1163,7 @@ static Lisp sch_string_ref(Lisp args, LispError* e, LispContext ctx)
|
||||
return lisp_null();
|
||||
}
|
||||
|
||||
return lisp_make_char((int)lisp_string_ref(str, lisp_int(index)));
|
||||
return lisp_make_char(lisp_string_ref(str, lisp_int(index)));
|
||||
}
|
||||
|
||||
static Lisp sch_string_set(Lisp args, LispError* e, LispContext ctx)
|
||||
@@ -1737,7 +1737,7 @@ static Lisp sch_pseudo_rand(Lisp args, LispError* e, LispContext ctx)
|
||||
|
||||
static Lisp sch_univeral_time(Lisp args, LispError* e, LispContext ctx)
|
||||
{
|
||||
return lisp_make_int((LispInt)time(NULL));
|
||||
return lisp_make_int(time(NULL));
|
||||
}
|
||||
|
||||
static Lisp sch_is_table(Lisp args, LispError* e, LispContext ctx)
|
||||
|
||||
@@ -59,4 +59,8 @@ ScreenLayout *splitScreenGetLayout(void);
|
||||
*/
|
||||
EditorPane *splitScreenGetActivePane(void);
|
||||
|
||||
void freePane(EditorPane *pane);
|
||||
void freeScreenLayout(ScreenLayout *layout);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -11,6 +11,7 @@ int utf8Encode(uint32_t cp, char *buf);
|
||||
int utf8Seqlen(unsigned char c);
|
||||
int codepointWidth(uint32_t codepoint);
|
||||
uint32_t utf8Decode(const char** s);
|
||||
int is_word_char(const char *s);
|
||||
|
||||
|
||||
#endif //BELUGA_UTF8_H
|
||||
|
||||
Reference in New Issue
Block a user