popup and diagnose ui
This commit is contained in:
+51
-71
@@ -24,8 +24,6 @@
|
||||
#include "include/completion.h"
|
||||
#include "include/utils.h"
|
||||
|
||||
extern struct editorConfig E;
|
||||
|
||||
/**
|
||||
* @brief Renders a single pane with its buffer content
|
||||
*/
|
||||
@@ -74,7 +72,10 @@ static void editorDrawPane(struct abuf* ab, EditorPane* pane)
|
||||
}
|
||||
else
|
||||
{
|
||||
lspUiDrawGutter(ab, &E.lsp_diagnostics, pane->buffer_id, file_row);
|
||||
if (E.constantes.LSP) {
|
||||
lspUiDrawGutter(ab, &E.lsp_diagnostics, pane->buffer_id, file_row);
|
||||
}
|
||||
|
||||
|
||||
if (buf->filename[strlen(buf->filename) - 1] == 'c' || buf->filename[strlen(buf->filename) - 1] == 'h')
|
||||
{
|
||||
@@ -304,11 +305,8 @@ void editorDrawStatusBar(struct abuf* ab)
|
||||
abAppend(ab, render_status, render_len);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
abAppend(ab, " ", 1);
|
||||
++len;
|
||||
}
|
||||
abAppend(ab, " ", 1);
|
||||
++len;
|
||||
}
|
||||
|
||||
abAppend(ab, "\x1b[m", 3); // normal text mode
|
||||
@@ -336,36 +334,6 @@ void editorDrawMessageBar(struct abuf* ab)
|
||||
}
|
||||
}
|
||||
|
||||
void editorDrawContextBuffer(struct abuf* ab)
|
||||
{
|
||||
int pos_len;
|
||||
char pos_buf[1024];
|
||||
int i, j;
|
||||
|
||||
if (!E.context_buffers)
|
||||
return;
|
||||
|
||||
appDebug("Printing context");
|
||||
|
||||
for (i = 0; i < E.context_buffers->height; ++i)
|
||||
{
|
||||
if (E.context_buffers->editor_y + i + 1 > 0)
|
||||
{
|
||||
pos_len = snprintf(pos_buf, sizeof(pos_buf), "\x1b[%d;%dH",
|
||||
E.context_buffers->editor_y + i + 1, E.context_buffers->editor_x - 2);
|
||||
abAppend(ab, pos_buf, pos_len);
|
||||
|
||||
// Apply background color (6 bytes for RGB format)
|
||||
abAppend(ab, E.theme.BACKGROUND_COLOR, (int)strlen(E.theme.BACKGROUND_COLOR));
|
||||
abAppend(ab, "|", 1);
|
||||
abAppend(ab, E.context_buffers->rows->chars, E.context_buffers->rows->size);
|
||||
abAppend(ab, "|", 1);
|
||||
}
|
||||
}
|
||||
bFree(E.context_buffers);
|
||||
E.context_buffers = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Performs complete screen refresh and buffer synchronization
|
||||
* @details Clears screen, redraws all visible content (rows, status bar,
|
||||
@@ -388,50 +356,62 @@ void editorRefreshScreen()
|
||||
(int)strlen(E.theme.BACKGROUND_COLOR));
|
||||
|
||||
editorScroll();
|
||||
|
||||
|
||||
EditorPane* active = splitScreenGetActivePane();
|
||||
struct buffer_t* buffer = bufferFindById(active->buffer_id);
|
||||
|
||||
editorDrawAllPanes(&ab);
|
||||
if (E.constantes.LSP) {
|
||||
|
||||
// ── LSP: draw completion popup every frame while visible ──────────────────
|
||||
appDebug("[REFRESH] lsp_completion.visible=%d\n",
|
||||
E.lsp_completion.visible);
|
||||
while (E.lsp_client->completion_requested && !E.lsp_client->completion_just_arrived);
|
||||
// reset flags
|
||||
E.lsp_client->completion_just_arrived = 0;
|
||||
E.lsp_client->completion_requested = 0;
|
||||
|
||||
// ── LSP: diagnostic for current line in status bar ────────────────────────
|
||||
const char* diag = lspUiDiagnosticAtCursor(
|
||||
&E.lsp_diagnostics,
|
||||
active->buffer_id,
|
||||
buffer->y);
|
||||
if (diag) {
|
||||
char single_line[512];
|
||||
int i = 0;
|
||||
|
||||
// Copy until newline, \0, or screen width
|
||||
while (diag[i] && diag[i] != '\n' && i < E.screencols - 4)
|
||||
{
|
||||
single_line[i] = diag[i];
|
||||
i++;
|
||||
}
|
||||
|
||||
// If message was truncated, add ellipsis
|
||||
if (diag[i] != '\0' && diag[i] != '\n')
|
||||
{
|
||||
single_line[i++] = '.';
|
||||
single_line[i++] = '.';
|
||||
single_line[i++] = '.';
|
||||
}
|
||||
single_line[i] = '\0';
|
||||
editorSetStatusMessage("● %s", single_line);
|
||||
}
|
||||
|
||||
}
|
||||
editorDrawStatusBar(&ab);
|
||||
editorDrawMessageBar(&ab);
|
||||
|
||||
EditorPane *active = splitScreenGetActivePane();
|
||||
struct buffer_t *buffer = bufferFindById(active->buffer_id);
|
||||
|
||||
// ── LSP: sync buffer changes to clangd ────────────────────────────────────
|
||||
if (buffer->b_has_changed) {
|
||||
if (E.lsp_client && E.lsp_client->state == LSP_READY) {
|
||||
lspDidChange(E.lsp_client, buffer);
|
||||
|
||||
E.lsp_client->completion_just_arrived = 0; // consume the flag
|
||||
}
|
||||
buffer->b_has_changed = 0;
|
||||
}
|
||||
|
||||
// ── LSP: draw completion popup every frame while visible ──────────────────
|
||||
fprintf(stderr, "[REFRESH] lsp_completion.visible=%d\n",
|
||||
E.lsp_completion.visible);
|
||||
while (E.lsp_client->completion_requested && !E.lsp_client->completion_just_arrived)
|
||||
;
|
||||
// reset flags
|
||||
E.lsp_client->completion_just_arrived = 0;
|
||||
E.lsp_client->completion_requested = 0;
|
||||
|
||||
if (E.lsp_client && E.lsp_client->state == LSP_READY)
|
||||
if (E.constantes.LSP && (E.lsp_client && E.lsp_client->state == LSP_READY))
|
||||
{
|
||||
lspUiDrawCompletion(&ab, &E.lsp_completion);
|
||||
appDebug("ready\n");
|
||||
}
|
||||
|
||||
// ── LSP: diagnostic for current line in status bar ────────────────────────
|
||||
const char *diag = lspUiDiagnosticAtCursor(
|
||||
&E.lsp_diagnostics,
|
||||
active->buffer_id,
|
||||
active->cursor_y + active->y_offset);
|
||||
if (diag)
|
||||
editorSetStatusMessage("● %s", diag);
|
||||
|
||||
// ── Position cursor (account for gutter width) ────────────────────────────
|
||||
snprintf(buf, sizeof(buf), "\x1b[%d;%dH",
|
||||
active->cursor_y + active->origin_y + 1,
|
||||
active->cursor_x + active->origin_x + 1 + GUTTER_WIDTH);
|
||||
active->cursor_x + active->origin_x + 1 + (E.constantes.LSP ? GUTTER_WIDTH : 0));
|
||||
abAppend(&ab, buf, (int)strlen(buf));
|
||||
|
||||
abAppend(&ab, SHOW_CURSOR, 6);
|
||||
|
||||
Reference in New Issue
Block a user