summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c84
1 files changed, 83 insertions, 1 deletions
diff --git a/main.c b/main.c
index 1967db8..2c347ef 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,8 @@
/*
+@TODO:
+- rust-analyzer bug reports:
+ - bad json can give "Unexpected error: client exited without proper shutdown sequence"
+ - rust-analyzer should wait until cargo metadata/check is done before sending initialize response
FUTURE FEATURES:
- configurable max buffer size + max view-only buffer size
- better undo chaining (dechain on backspace?)
@@ -48,7 +52,9 @@ no_warn_end
#endif
#include "unicode.h"
+#include "arr.c"
#include "util.c"
+
#if _WIN32
#include "filesystem-win.c"
#elif __unix__
@@ -56,7 +62,6 @@ no_warn_end
#else
#error "Unrecognized operating system."
#endif
-#include "arr.c"
#include "math.c"
#if _WIN32
@@ -92,6 +97,7 @@ static void die(char const *fmt, ...) {
#include "ted.h"
#include "gl.c"
#include "text.c"
+#include "lsp.h"
#include "string32.c"
#include "syntax.c"
@@ -108,6 +114,8 @@ bool tag_goto(Ted *ted, char const *tag);
#include "command.c"
#include "config.c"
#include "session.c"
+#include "json.c"
+#include "lsp.c"
#if PROFILE
#define PROFILE_TIME(var) double var = time_get_seconds();
@@ -286,6 +294,72 @@ int main(int argc, char **argv) {
PROFILE_TIME(init_start)
PROFILE_TIME(basic_init_start)
+
+ if (0) {
+ // @TODO TEMPORARY
+ LSP lsp={0};
+// chdir("/p/test-lsp");
+ if (!lsp_create(&lsp, "rust-analyzer")) {
+ printf("lsp_create: %s\n",lsp.error);
+ exit(1);
+ }
+ usleep(1000000);//if we don't do this we get "waiting for cargo metadata or cargo check"
+ LSPRequest test_req = {.type = LSP_COMPLETION};
+ test_req.data.completion = (LSPRequestCompletion){
+ .position = {
+ .path = str_dup("/p/test-lsp/src/main.rs"),
+ .line = 2,
+ .character = 2,
+ }
+ };
+ lsp_send_request(&lsp, &test_req);
+ while (1) {
+ LSPMessage message = {0};
+ while (lsp_next_message(&lsp, &message)) {
+ if (message.type == LSP_RESPONSE) {
+ const LSPResponse *response = &message.u.response;
+ switch (response->type) {
+ case LSP_COMPLETION: {
+ const LSPResponseCompletion *completion = &response->data.completion;
+ arr_foreach_ptr(completion->items, LSPCompletionItem, item) {
+ printf("(%d)%s => ",
+ item->text_edit.type,
+ lsp_response_string(response, item->label));
+ printf("%s\n",
+ lsp_response_string(response, item->text_edit.new_text));
+ }
+ } break;
+ default:
+ break;
+ }
+ } else if (message.type == LSP_REQUEST) {
+ const LSPRequest *request = &message.u.request;
+ switch (request->type) {
+ case LSP_SHOW_MESSAGE: {
+ const LSPRequestMessage *m = &request->data.message;
+ // @TODO actually show
+ printf("Show (%d): %s\n", m->type, m->message);
+ } break;
+ case LSP_LOG_MESSAGE: {
+ const LSPRequestMessage *m = &request->data.message;
+ // @TODO actually log
+ printf("Log (%d): %s\n", m->type, m->message);
+ } break;
+ default: break;
+ }
+ }
+ lsp_message_free(&message);
+ }
+ char error[256];
+ if (lsp_get_error(&lsp, error, sizeof error, true)) {
+ printf("lsp error: %s\n", error);
+ }
+ usleep(10000);
+ }
+ lsp_free(&lsp);
+ exit(0);
+ }
+
#if __unix__
{
struct sigaction act = {0};
@@ -341,6 +415,14 @@ int main(int argc, char **argv) {
}
ted->last_save_time = -1e50;
+
+ // @TODO TEMPORARY
+ ted->test_lsp = calloc(1, sizeof(LSP));
+ if (!lsp_create(ted->test_lsp, "rust-analyzer")) {
+ printf("lsp_create: %s\n",ted->test_lsp->error);
+ exit(1);
+ }
+
// make sure signal handler has access to ted.
error_signal_handler_ted = ted;