aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ring.c
diff options
context:
space:
mode:
authorRobin Haberkorn <rhaberkorn@fmsbw.de>2026-08-02 15:24:45 +0200
committerRobin Haberkorn <rhaberkorn@fmsbw.de>2026-08-11 00:38:31 +0200
commit44f5bf677282308b959411c416da2b5b08db2062 (patch)
treef350d7a16c3c3c431e2744ae321d781b27641413 /src/ring.c
parent9b78fc83dbd29b5594431b1c49b7d13865141aaa (diff)
support lookups via language servers (LSP)HEADmaster-fmsbw-cimaster
* The main interface is the `FT` command. `FT` was an undocumented Video TECO command for etags/ctags lookups. I don't want to exactly copy its interface, though. * `FT` allows looking up symbol names, definitions and references. * ctags will be supported via ctags-lsp. LSP support is more powerful though and works without regenerating TAGS files all the time. The LSP will also allow you to customize auto-completions using SciTECO itself (i.e. by writing a language server in SciTECO). * For multiple results, `FT$` can be used to cycle through results - this should mimic repeated `S$` or `N$`. * `:FT...$` does a fuzzy search. IMHO it's not important to return a status integer instead. `FT` will only really be used in interactive mode. * Document synchronization is supported via hooks from ring.c and via Scintilla notifications. * Currently, the LSP communication is based on blocking GIOChannels. This means that a misbehaving hanging server could "lock up" the entire editor (FIXME). Only on ncurses you can always kill the subprocess by pressing CTRL+C. We need helper functions in spawn.c to read and write with interruptions. * The textDocument/didChange notification transmits not only all edits, but all files' contents as well during initial synchronization. Therefore it is optimized to write and JSON-escape data without copying them around in memory and without destroying the buffer gap. * Use $SCITECO_LSP to configure the language server. You can also use `tee` to capture stdin and stdout. Perhaps $SCITECO_LSP should be saved in .teco_session, so you can change it between projects? * $SCITECO_LSP_ROOT is used to point to the project's root directory. session.tes will set it up automatically.
Diffstat (limited to 'src/ring.c')
-rw-r--r--src/ring.c41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/ring.c b/src/ring.c
index cda15c4..dc43ac5 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -37,6 +37,7 @@
#include "glob.h"
#include "error.h"
#include "list.h"
+#include "lsp.h"
#include "ring.h"
/** @private @static @memberof teco_buffer_t */
@@ -79,13 +80,20 @@ teco_buffer_undo_edit(teco_buffer_t *ctx)
static gboolean
teco_buffer_load(teco_buffer_t *ctx, const gchar *filename, GError **error)
{
+ teco_buffer_set_filename(ctx, filename);
+
+ if (!teco_lsp_didopen(ctx, error))
+ return FALSE;
+
+ /*
+ * Will also call teco_lsp_didchange_insert() following
+ * Scintilla notifications.
+ */
if (!teco_view_load(ctx->view, filename, TRUE, error))
return FALSE;
/* currently buffer cannot be dirty */
g_assert(ctx->state == TECO_BUFFER_CLEAN);
-
- teco_buffer_set_filename(ctx, filename);
return TRUE;
}
@@ -93,7 +101,9 @@ teco_buffer_load(teco_buffer_t *ctx, const gchar *filename, GError **error)
static gboolean
teco_buffer_save(teco_buffer_t *ctx, const gchar *filename, GError **error)
{
- if (!filename && !ctx->filename) {
+ gboolean is_unnamed = !ctx->filename;
+
+ if (!filename && is_unnamed) {
g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED,
"Cannot save the unnamed file "
"without providing a file name");
@@ -127,6 +137,13 @@ teco_buffer_save(teco_buffer_t *ctx, const gchar *filename, GError **error)
teco_undo_cstring(ctx->filename);
teco_buffer_set_filename(ctx, filename ? : ctx->filename);
+ /*
+ * Unnamed buffers were not synced with the LSP server,
+ * so we do this now.
+ */
+ if (is_unnamed && !teco_lsp_sync(ctx, error))
+ return FALSE;
+
return TRUE;
}
@@ -400,6 +417,9 @@ teco_ring_edit_by_name(const gchar *filename, GError **error)
else
teco_interface_msg(TECO_MSG_INFO,
"Added new unnamed file to ring.");
+
+ if (!teco_lsp_didopen(buffer, error))
+ return FALSE;
}
return teco_ed_hook(TECO_ED_HOOK_ADD, error);
@@ -467,6 +487,9 @@ teco_ring_close(teco_buffer_t *buffer, GError **error)
teco_ring_remove_buffer(buffer);
}
+ if (!teco_lsp_didclose(buffer, error))
+ return FALSE;
+
/* transfer responsibility to the undo token object */
teco_undo_ring_reinsert(buffer);
@@ -489,6 +512,18 @@ teco_ring_set_scintilla_undo(gboolean state)
}
}
+gboolean
+teco_ring_sync_lsp(GError **error)
+{
+ for (teco_tailq_entry_t *cur = teco_ring_head.first; cur != NULL; cur = cur->next) {
+ teco_buffer_t *buffer = (teco_buffer_t *)cur;
+ if (buffer->filename && !teco_lsp_sync(buffer, error))
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
void
teco_ring_cleanup(void)
{