First completion level is working (LSP connected)
This commit is contained in:
+69
-33
@@ -15,11 +15,15 @@
|
||||
#include "../include/split_screen.h"
|
||||
#include "../include/syntax_highlighter.h"
|
||||
#include "../include/terminal.h"
|
||||
#include "../include/lsp_ui.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "include/completion.h"
|
||||
#include "include/utils.h"
|
||||
|
||||
extern struct editorConfig E;
|
||||
|
||||
/**
|
||||
@@ -52,7 +56,7 @@ static void editorDrawPane(struct abuf* ab, EditorPane* pane)
|
||||
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, E.theme.BACKGROUND_COLOR, (int)strlen(E.theme.BACKGROUND_COLOR));
|
||||
|
||||
|
||||
// pane line is out of buffer
|
||||
@@ -70,7 +74,7 @@ static void editorDrawPane(struct abuf* ab, EditorPane* pane)
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
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')
|
||||
{
|
||||
@@ -80,7 +84,7 @@ static void editorDrawPane(struct abuf* ab, EditorPane* pane)
|
||||
|
||||
// Print only up to pane width
|
||||
abAppend(ab, highlighted, byte_len_to_print);
|
||||
free(highlighted);
|
||||
bFree(highlighted);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -130,7 +134,7 @@ static void editorDrawAllPanes(struct abuf* ab)
|
||||
{
|
||||
char pos_buf[32];
|
||||
snprintf(pos_buf, sizeof(pos_buf), "\x1b[%d;%dH", y + 1, divider_col);
|
||||
abAppend(ab, pos_buf, (int) strlen(pos_buf));
|
||||
abAppend(ab, pos_buf, (int)strlen(pos_buf));
|
||||
abAppend(ab, "\x1b[1m|\x1b[0m", 9); // Bold pipe divider
|
||||
}
|
||||
}
|
||||
@@ -140,7 +144,7 @@ static void editorDrawAllPanes(struct abuf* ab)
|
||||
int divider_row = layout->panes[0].height;
|
||||
char pos_buf[32];
|
||||
snprintf(pos_buf, sizeof(pos_buf), "\x1b[%d;%dH", divider_row + 1, 1);
|
||||
abAppend(ab, pos_buf, (int) strlen(pos_buf));
|
||||
abAppend(ab, pos_buf, (int)strlen(pos_buf));
|
||||
for (int x = 0; x < E.screencols; x++)
|
||||
{
|
||||
abAppend(ab, "\x1b[1m-\x1b[0m", 9); // Bold dash divider
|
||||
@@ -180,11 +184,13 @@ void editorScroll()
|
||||
if (active->cursor_x == 0 && active->x_offset)
|
||||
{
|
||||
active->x_offset--;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
active->cursor_x--;
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
// RIGHT
|
||||
if (rel_x > active->cursor_x + active->x_offset)
|
||||
@@ -192,7 +198,8 @@ void editorScroll()
|
||||
if (active->cursor_x == active->width - 1)
|
||||
{
|
||||
active->x_offset++;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
active->cursor_x++;
|
||||
}
|
||||
@@ -204,7 +211,8 @@ void editorScroll()
|
||||
if (active->cursor_y == 0 && active->y_offset)
|
||||
{
|
||||
active->y_offset--;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
active->cursor_y--;
|
||||
}
|
||||
@@ -215,25 +223,25 @@ void editorScroll()
|
||||
if (active->cursor_y == active->height - 1)
|
||||
{
|
||||
active->y_offset++;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
active->cursor_y++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
char * basename(char *path)
|
||||
char* basename(char* path)
|
||||
{
|
||||
int len = (int) strlen(path);
|
||||
int len = (int)strlen(path);
|
||||
|
||||
|
||||
for(int i=len-1; i>0; i--)
|
||||
for (int i = len - 1; i > 0; i--)
|
||||
{
|
||||
if(path[i]=='/' )
|
||||
if (path[i] == '/')
|
||||
{
|
||||
path = path+i+1;
|
||||
path = path + i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -316,7 +324,7 @@ void editorDrawStatusBar(struct abuf* ab)
|
||||
*/
|
||||
void editorDrawMessageBar(struct abuf* ab)
|
||||
{
|
||||
int msg_len = (int) strlen(E.status_msg);
|
||||
int msg_len = (int)strlen(E.status_msg);
|
||||
abAppend(ab, ERASE_END_LINE, 3);
|
||||
if (msg_len > E.screencols)
|
||||
{
|
||||
@@ -344,17 +352,17 @@ void editorDrawContextBuffer(struct abuf* ab)
|
||||
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);
|
||||
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, 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);
|
||||
}
|
||||
}
|
||||
free(E.context_buffers);
|
||||
bFree(E.context_buffers);
|
||||
E.context_buffers = NULL;
|
||||
}
|
||||
|
||||
@@ -377,27 +385,55 @@ void editorRefreshScreen()
|
||||
abAppend(&ab, HIDE_CURSOR, 6);
|
||||
abAppend(&ab, CURSOR_TOP_LEFT, 3);
|
||||
abAppend(&ab, E.theme.BACKGROUND_COLOR,
|
||||
(int) strlen(E.theme.BACKGROUND_COLOR)); // RGB background is 12 bytes
|
||||
(int)strlen(E.theme.BACKGROUND_COLOR));
|
||||
|
||||
// Draw all panes
|
||||
editorScroll();
|
||||
editorDrawAllPanes(&ab);
|
||||
|
||||
// Draw status bar and message bar
|
||||
editorDrawStatusBar(&ab);
|
||||
editorDrawMessageBar(&ab);
|
||||
// editorDrawContextBuffer(&ab);
|
||||
|
||||
// Position cursor in active pane
|
||||
EditorPane* active = splitScreenGetActivePane();
|
||||
if (active != NULL)
|
||||
{
|
||||
snprintf(buf, sizeof(buf), "\x1b[%d;%dH",
|
||||
active->cursor_y + active->origin_y + 1,
|
||||
active->cursor_x + active->origin_x + 1);
|
||||
abAppend(&ab, buf, (int) strlen(buf));
|
||||
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)
|
||||
{
|
||||
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);
|
||||
abAppend(&ab, buf, (int)strlen(buf));
|
||||
|
||||
abAppend(&ab, SHOW_CURSOR, 6);
|
||||
write(STDOUT_FILENO, ab.b, ab.len);
|
||||
abFree(&ab);
|
||||
|
||||
Reference in New Issue
Block a user