summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buffer.c17
-rw-r--r--lsp-parse.c18
-rw-r--r--lsp-write.c14
-rw-r--r--lsp.c4
-rw-r--r--lsp.h4
-rw-r--r--main.c26
-rw-r--r--test/lsp/JavaA/Main.java2
7 files changed, 52 insertions, 33 deletions
diff --git a/buffer.c b/buffer.c
index 8d20a6f..6e32770 100644
--- a/buffer.c
+++ b/buffer.c
@@ -1183,6 +1183,9 @@ i64 buffer_pos_move_down(TextBuffer *buffer, BufferPos *pos, i64 by) {
void buffer_cursor_move_to_pos(TextBuffer *buffer, BufferPos pos) {
buffer_pos_validate(buffer, &pos);
+ if (buffer_pos_eq(buffer->cursor_pos, pos)) {
+ return;
+ }
buffer->cursor_pos = pos;
buffer->selection = false;
buffer_scroll_to_cursor(buffer);
@@ -1606,6 +1609,9 @@ BufferPos buffer_insert_text_at_pos(TextBuffer *buffer, BufferPos pos, String32
BufferPos b = {.line = line_idx, .index = index};
free(str_alloc);
+
+ signature_help_retrigger(buffer->ted);
+
return b;
}
@@ -1907,6 +1913,7 @@ void buffer_delete_chars_at_pos(TextBuffer *buffer, BufferPos pos, i64 nchars_)
buffer_validate_cursor(buffer);
buffer_lines_modified(buffer, line_idx, line_idx);
+ signature_help_retrigger(buffer->ted);
}
// Delete characters between the given buffer positions. Returns number of characters deleted.
@@ -2012,11 +2019,12 @@ i64 buffer_backspace_at_pos(TextBuffer *buffer, BufferPos *pos, i64 ntimes) {
// returns number of characters backspaced
i64 buffer_backspace_at_cursor(TextBuffer *buffer, i64 ntimes) {
i64 ret = 0;
+ BufferPos cursor_pos = buffer->cursor_pos;
if (buffer->selection)
ret = buffer_delete_selection(buffer);
else
- ret = buffer_backspace_at_pos(buffer, &buffer->cursor_pos, ntimes);
- buffer_scroll_to_cursor(buffer);
+ ret = buffer_backspace_at_pos(buffer, &cursor_pos, ntimes);
+ buffer_cursor_move_to_pos(buffer, cursor_pos);
return ret;
}
@@ -2041,11 +2049,12 @@ void buffer_backspace_words_at_pos(TextBuffer *buffer, BufferPos *pos, i64 nword
}
void buffer_backspace_words_at_cursor(TextBuffer *buffer, i64 nwords) {
+ BufferPos cursor_pos = buffer->cursor_pos;
if (buffer->selection)
buffer_delete_selection(buffer);
else
- buffer_backspace_words_at_pos(buffer, &buffer->cursor_pos, nwords);
- buffer_scroll_to_cursor(buffer);
+ buffer_backspace_words_at_pos(buffer, &cursor_pos, nwords);
+ buffer_cursor_move_to_pos(buffer, cursor_pos);
}
// puts the inverse edit into `inverse`
diff --git a/lsp-parse.c b/lsp-parse.c
index 703bc51..633fd2e 100644
--- a/lsp-parse.c
+++ b/lsp-parse.c
@@ -301,14 +301,14 @@ static bool parse_completion(LSP *lsp, const JSON *json, LSPResponse *response)
static bool parse_signature_help(LSP *lsp, const JSON *json, LSPResponse *response) {
JSONObject result = json_force_object(json_get(json, "result"));
- json_debug_print_object(json, result);printf("\n");
+ //json_debug_print_object(json, result);printf("\n");
LSPResponseSignatureHelp *help = &response->data.signature_help;
u32 active_signature = 0;
double active_signature_dbl = json_object_get_number(json, result, "activeSignature");
if (isfinite(active_signature_dbl))
active_signature = (u32)active_signature_dbl;
- double active_signature_active_parameter = json_object_get_number(json, result, "activeParameter");
+ double global_active_parameter = json_object_get_number(json, result, "activeParameter");
JSONArray signatures = json_object_get_array(json, result, "signatures");
if (active_signature >= signatures.len)
@@ -336,9 +336,9 @@ static bool parse_signature_help(LSP *lsp, const JSON *json, LSPResponse *respon
if (isfinite(active_parameter_dbl)) {
active_parameter = (u32)active_parameter_dbl;
}
- if (s == active_signature && active_parameter == U32_MAX &&
- isfinite(active_signature_active_parameter)) {
- active_parameter = (u32)active_parameter_dbl;
+ if (active_parameter == U32_MAX &&
+ isfinite(global_active_parameter)) {
+ active_parameter = (u32)global_active_parameter;
}
if (active_parameter < parameters.len) {
JSONObject parameter_info = json_array_get_object(json, parameters, active_parameter);
@@ -543,6 +543,14 @@ static void process_message(LSP *lsp, JSON *json) {
write_request(lsp, &initialized);
// we can now send requests which have nothing to do with initialization
lsp->initialized = true;
+ {
+ // configure jdtls so it actually supports signature help
+ // NOTE: this won't send if the LSP isn't jdtls (because of lsp_supports_request)
+ LSPRequest jdtls_configuration = {
+ .type = LSP_REQUEST_JDTLS_CONFIGURATION
+ };
+ lsp_send_request(lsp, &jdtls_configuration);
+ }
} break;
default:
// it's some response we don't care about
diff --git a/lsp-write.c b/lsp-write.c
index 406faa5..5898109 100644
--- a/lsp-write.c
+++ b/lsp-write.c
@@ -262,6 +262,8 @@ static const char *lsp_request_method(LSPRequest *request) {
return "workspace/workspaceFolders";
case LSP_REQUEST_DID_CHANGE_WORKSPACE_FOLDERS:
return "workspace/didChangeWorkspaceFolders";
+ case LSP_REQUEST_JDTLS_CONFIGURATION:
+ return "workspace/didChangeConfiguration";
}
assert(0);
return "$/ignore";
@@ -276,6 +278,7 @@ static bool request_type_is_notification(LSPRequestType type) {
case LSP_REQUEST_DID_CLOSE:
case LSP_REQUEST_DID_CHANGE:
case LSP_REQUEST_DID_CHANGE_WORKSPACE_FOLDERS:
+ case LSP_REQUEST_JDTLS_CONFIGURATION:
return true;
case LSP_REQUEST_INITIALIZE:
case LSP_REQUEST_SHUTDOWN:
@@ -499,6 +502,17 @@ static void write_request(LSP *lsp, LSPRequest *request) {
write_obj_end(o);
write_obj_end(o);
} break;
+ case LSP_REQUEST_JDTLS_CONFIGURATION:
+ write_key_obj_start(o, "params");
+ write_key_obj_start(o, "settings");
+ write_key_obj_start(o, "java");
+ write_key_obj_start(o, "signatureHelp");
+ write_key_bool(o, "enabled", true);
+ write_obj_end(o);
+ write_obj_end(o);
+ write_obj_end(o);
+ write_obj_end(o);
+ break;
}
write_obj_end(o);
diff --git a/lsp.c b/lsp.c
index f2729f5..47b2b72 100644
--- a/lsp.c
+++ b/lsp.c
@@ -45,6 +45,7 @@ static void lsp_request_free(LSPRequest *r) {
case LSP_REQUEST_SIGNATURE_HELP:
case LSP_REQUEST_DID_CLOSE:
case LSP_REQUEST_WORKSPACE_FOLDERS:
+ case LSP_REQUEST_JDTLS_CONFIGURATION:
break;
case LSP_REQUEST_DID_OPEN: {
LSPRequestDidOpen *open = &r->data.open;
@@ -132,6 +133,9 @@ static bool lsp_supports_request(LSP *lsp, const LSPRequest *request) {
case LSP_REQUEST_SHUTDOWN:
case LSP_REQUEST_EXIT:
return true;
+ case LSP_REQUEST_JDTLS_CONFIGURATION:
+ // @TODO: check if this is actually jdtls
+ return lsp->language == LANG_JAVA;
case LSP_REQUEST_COMPLETION:
return cap->completion_support;
case LSP_REQUEST_SIGNATURE_HELP:
diff --git a/lsp.h b/lsp.h
index 711db2a..c078820 100644
--- a/lsp.h
+++ b/lsp.h
@@ -27,6 +27,10 @@ typedef enum {
// client-to-server
LSP_REQUEST_INITIALIZE, // initialize
LSP_REQUEST_INITIALIZED, // initialized
+ // workspace/didChangeConfiguration with parameters specifically for jdtls.
+ // we need this because annoyingly jdtls refuses to give signature help
+ // unless you specifically configure it to do that
+ LSP_REQUEST_JDTLS_CONFIGURATION,
LSP_REQUEST_SHUTDOWN, // shutdown
LSP_REQUEST_EXIT, // exit
LSP_REQUEST_DID_OPEN, // textDocument/didOpen
diff --git a/main.c b/main.c
index 4cad511..9cd5d27 100644
--- a/main.c
+++ b/main.c
@@ -1,9 +1,6 @@
/*
@TODO:
-- why is jdtls not giving us signatures?
-- why is clangd not giving us active parameter?
- more LSP stuff:
- - signature help
- hover
- go to definition using LSP
- find usages
@@ -780,26 +777,9 @@ int main(int argc, char **argv) {
break;
}
}
-
- bool signature_help = false;
- arr_foreach_ptr(lsp->signature_help_trigger_chars, char32_t, c) {
- if (*c == last_char) {
- signature_help = true;
- break;
- }
- }
-
- if (signature_help_is_open(ted)) {
- arr_foreach_ptr(lsp->signature_help_retrigger_chars, char32_t, c) {
- if (*c == last_char) {
- signature_help = true;
- break;
- }
- }
- }
-
- if (signature_help)
- signature_help_open(ted, last_char);
+ // NOTE: we are not checking for signature help trigger
+ // characters because currently we ask for signature
+ // help any time a character is inserted.
if (settings->identifier_trigger_characters && is_word(last_char)
&& !is_digit(last_char))
diff --git a/test/lsp/JavaA/Main.java b/test/lsp/JavaA/Main.java
index 5682de5..274ba52 100644
--- a/test/lsp/JavaA/Main.java
+++ b/test/lsp/JavaA/Main.java
@@ -3,7 +3,7 @@ public class Main {
int x = 0;
x++;
for (int i = 0; i < args.length; ++i) {
- Integer.parseInt("33");
+ String.valueOf(3.5);
}
}
}