First completion level is working (LSP connected)

This commit is contained in:
2026-05-28 18:28:59 +02:00
parent 8eeef59a98
commit a8b2960eb4
27 changed files with 5167 additions and 335 deletions
+91
View File
@@ -5,8 +5,12 @@
#include <termios.h>
#include <time.h>
#include "define.h"
#include "lisp.h"
typedef struct lsp_client_t LspClient;
/**
* \struct row_t
* \brief Store one editor row
@@ -94,15 +98,98 @@ struct keyBind_t {
Lisp command;
};
// In data.h — add these
#include <pthread.h>
#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;
enum bufferStatus_e state;
int dirty; /**< Has this buffer been modified since last save */
};
@@ -122,6 +209,10 @@ struct editorConfig {
ContextBuffer* context_buffers;
LspClient *lsp_client;
CompletionPopup lsp_completion;
DiagnosticList lsp_diagnostics;
int dirty;
char *status_msg;