summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-31 11:54:06 -0500
committerpommicket <pommicket@gmail.com>2022-12-31 11:54:06 -0500
commit02faedf9bf7e826bc78161f8cf07ffca5d2dbe57 (patch)
tree39a0f0f221fbdec2197f1c8c6d0cf4986df6b8d4
parentf40e9f02ef3ca0a86282a927c9bb7887900100b2 (diff)
highlight-enabled and highlight-auto settings
-rw-r--r--config.c2
-rw-r--r--ide-highlights.c27
-rw-r--r--main.c3
-rw-r--r--ted.c3
-rw-r--r--ted.cfg4
-rw-r--r--ted.h2
6 files changed, 32 insertions, 9 deletions
diff --git a/config.c b/config.c
index 070f440..ddfc8ad 100644
--- a/config.c
+++ b/config.c
@@ -263,6 +263,8 @@ static OptionBool const options_bool[] = {
{"lsp-enabled", &options_zero.lsp_enabled, true},
{"hover-enabled", &options_zero.hover_enabled, true},
{"vsync", &options_zero.vsync, false},
+ {"highlight-enabled", &options_zero.highlight_enabled, true},
+ {"highlight-auto", &options_zero.highlight_auto, true},
};
static OptionU8 const options_u8[] = {
{"tab-width", &options_zero.tab_width, 1, 100, true},
diff --git a/ide-highlights.c b/ide-highlights.c
index 8ecf3ea..f53fb19 100644
--- a/ide-highlights.c
+++ b/ide-highlights.c
@@ -1,30 +1,33 @@
-static void highlights_clear(Highlights *hls) {
+void highlights_close(Ted *ted) {
+ Highlights *hls = &ted->highlights;
arr_clear(hls->highlights);
+ ted_cancel_lsp_request(ted, hls->last_request_lsp, hls->last_request_id);
+ hls->last_request_id = 0;
+ hls->requested_position = (LSPDocumentPosition){0};
}
void highlights_send_request(Ted *ted) {
TextBuffer *buffer = ted->active_buffer;
Highlights *hls = &ted->highlights;
if (!buffer) {
- highlights_clear(hls);
+ highlights_close(ted);
return;
}
LSP *lsp = buffer_lsp(buffer);
if (!lsp) {
- highlights_clear(hls);
+ highlights_close(ted);
return;
}
LSPDocumentPosition pos = buffer_cursor_pos_as_lsp_document_position(buffer);
LSPRequest request = {.type = LSP_REQUEST_HIGHLIGHT};
request.data.highlight.position = pos;
+
+ ted_cancel_lsp_request(ted, hls->last_request_lsp, hls->last_request_id);
hls->last_request_id = lsp_send_request(lsp, &request);
hls->last_request_lsp = lsp->id;
hls->requested_position = pos;
}
-void highlights_close(Ted *ted) {
- highlights_clear(&ted->highlights);
-}
void highlights_process_lsp_response(Ted *ted, LSPResponse *response) {
Highlights *hls = &ted->highlights;
@@ -43,13 +46,21 @@ void highlights_frame(Ted *ted) {
Highlights *hls = &ted->highlights;
TextBuffer *buffer = ted->active_buffer;
if (!buffer) {
- highlights_clear(hls);
+ highlights_close(ted);
+ return;
+ }
+ const Settings *settings = buffer_settings(buffer);
+ bool ctrl_down = SDL_GetKeyboardState(NULL)[SDL_SCANCODE_LCTRL]
+ || SDL_GetKeyboardState(NULL)[SDL_SCANCODE_RCTRL];
+ if (!settings->highlight_enabled
+ || (!settings->highlight_auto && !ctrl_down)) {
+ highlights_close(ted);
return;
}
+
LSPDocumentPosition pos = buffer_cursor_pos_as_lsp_document_position(buffer);
if (!lsp_document_position_eq(pos, hls->requested_position)) {
// cursor moved or something. let's resend the request.
- highlights_clear(hls);
highlights_send_request(ted);
}
diff --git a/main.c b/main.c
index 5a86677..335f48b 100644
--- a/main.c
+++ b/main.c
@@ -1,7 +1,8 @@
/*
@TODO:
+- use ted_cancel_request more
- show line containing usage
-- highlight-enabled, and highlight-auto
+- hover-auto
- handle multiple symbols with same name in go-to-definition menu
- :go-to-cursor-definition
- test full unicode position handling
diff --git a/ted.c b/ted.c
index 3868a29..987a753 100644
--- a/ted.c
+++ b/ted.c
@@ -568,3 +568,6 @@ void ted_go_to_lsp_document_position(Ted *ted, LSP *lsp, LSPDocumentPosition pos
ted_go_to_position(ted, path, line, character, true);
}
+void ted_cancel_lsp_request(Ted *ted, LSPID lsp, LSPRequestID request) {
+ lsp_cancel_request(ted_get_lsp_by_id(ted, lsp), request);
+}
diff --git a/ted.cfg b/ted.cfg
index 52978cf..dcf926b 100644
--- a/ted.cfg
+++ b/ted.cfg
@@ -41,6 +41,10 @@ lsp-enabled = yes
signature-help-enabled = yes
# display hover info when shift key is pressed? (only with LSP running)
hover-enabled = yes
+# highlight instances of the variable under the cursor when the ctrl key is pressed? (only with LSP running)
+highlight-enabled = yes
+# don't require ctrl key for highlighting
+highlight-auto = no
# maximum editable file size.
# ted will set the buffer to view-only if a file larger than this is loaded.
# NOTE: ted is not really meant for absolutely massive files.
diff --git a/ted.h b/ted.h
index 9201a89..56185fc 100644
--- a/ted.h
+++ b/ted.h
@@ -158,6 +158,8 @@ typedef struct {
bool signature_help_enabled;
bool lsp_enabled;
bool hover_enabled;
+ bool highlight_enabled;
+ bool highlight_auto;
bool vsync;
u8 tab_width;
u8 cursor_width;