#ifndef DATA_H_ #define DATA_H_ #include #include #include #include "define.h" #include "lisp.h" typedef struct lsp_client_t LspClient; /** * \struct row_t * \brief Store one editor row * \param * */ 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; } 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 } 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 int origin_x, origin_y; 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 } EditorPane; /** * @brief Screen layout manager */ typedef struct { SplitMode mode; EditorPane* panes; int num_panes; 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; } theme_t; enum bufferStatus_e { IDLE, READ_ONLY, READ_AND_WRITE, }; struct const_t { int TAB_LENGTH; int QUIT_TIMES; char* THEME; int LSP; }; struct prefix_t { char prefix_name[64]; int prefix_id; }; struct keyBind_t { char* key_sequence; int prefix_id; Lisp command; }; // In data.h — add these #include #define LSP_MAX_PENDING 64 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); } LspPending; 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; // ── 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 } 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…) } 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 } 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]; } Diagnostic; 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; 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*/ ScreenLayout layout; LspClient* lsp_client; CompletionPopup lsp_completion; DiagnosticList lsp_diagnostics; int dirty; char* status_msg; time_t status_msg_time; struct termios orig_termios; /**< Terminal communication interface */ struct const_t constantes; int quit_times_buffer; 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 keyBind_t* key_binds; int number_of_keybinds; struct prefix_t* prefix; int number_of_prefix; int prefix_state; struct buffer_t buffers[64]; int number_of_buffer; theme_t theme; }; /** * \struct abuf * \brief Contains text to add before writing to screen. * */ struct abuf { char* b; /**< Text that will be printed */ int len; /**< Length of the text */ }; extern struct editorConfig E; #endif