// File: /workspace/github_c_makefile_star2_O2/justy989[P]ce/ce_app.c
// Function: ce_app_handle_clangd_response
void ce_app_handle_clangd_response(CeApp_t* app){
     if(app->clangd.buffer == NULL){
          return;
     }
     while(ce_clangd_outstanding_responses(&app->clangd)){
          CeClangDResponse_t response = ce_clangd_pop_response(&app->clangd);
          if(response.method != NULL){
               if(strcmp(response.method, "textDocument/typeDefinition") == 0 ||
                  strcmp(response.method, "textDocument/definition") == 0 ||
                  strcmp(response.method, "textDocument/declaration") == 0 ||
                  strcmp(response.method, "textDocument/implementation") == 0){
                    CeLayout_t* tab_layout = app->tab_list_layout->tab_list.current;
                    CeView_t* view = &tab_layout->tab.current->view;
                    CeDestination_t dest = _extract_destination_from_range_response(response.obj);
                    if(load_destination_into_view(&app->buffer_node_head,
                                                  view,
                                                  &app->config_options,
                                                  &app->vim,
                                                  true,
                                                  NULL,
                                                  &dest)){
                         ce_clangd_file_open(&app->clangd, app->buffer_node_head->buffer);
                    }
               }else if(strcmp(response.method, "textDocument/completion") == 0){
                    if(app->clangd_completion.complete){
                         ce_complete_free(app->clangd_completion.complete);
                         free(app->clangd_completion.complete);
                    }
                    app->clangd_completion.complete = _extract_completion_from_response(response.obj,
                                                                                        &app->clangd_completion.start);
                    CeLayout_t* tab_layout = app->tab_list_layout->tab_list.current;
                    if(app->clangd_completion.complete &&
                       tab_layout->tab.current->type == CE_LAYOUT_TYPE_VIEW){
                         CeView_t* completed_view = &tab_layout->tab.current->view;
                         int64_t match_len = completed_view->cursor.x - app->clangd_completion.start.x;
                         if(match_len > 0){
                              char* match = ce_buffer_dupe_string(completed_view->buffer, app->clangd_completion.start, match_len);
                              ce_complete_match(app->clangd_completion.complete, match);
                              free(match);
                         }
                         build_complete_list(app->clangd_completion.buffer,
                                             app->clangd_completion.complete);
                         build_clangd_completion_view(&app->clangd_completion.view,
                                                      app->clangd_completion.start,
                                                      completed_view,
                                                      app->clangd_completion.buffer,
                                                      &app->config_options,
                                                      &app->terminal_rect);
                    }
               }else if(strcmp(response.method, "textDocument/references") == 0){
                   _extract_reference_locations_to_buffer(response.obj, app->clangd_references_buffer,
                                                          app->buffer_node_head);
                   if(app->clangd_references_buffer->line_count > 0){
                       ce_app_open_popup_view(app, app->clangd_references_buffer);
                   }
               }
          }else{
               CeJsonFindResult_t method_find = ce_json_obj_find(response.obj, "method");
               if(method_find.type == CE_JSON_TYPE_STRING){
                    const char* method = ce_json_obj_get_string(response.obj, &method_find);
                    if(method != NULL){
                        if(strcmp(method, "textDocument/publishDiagnostics") == 0){
                            CeClangDDiagnostics_t diagnostics = _extract_diagnostics_from_response(response.obj);
                            if(diagnostics.filepath != NULL){
                                // DEBUG
                                // printf("diags: %s %lld\n", diagnostics.filepath, diagnostics.count);
                                // for(int64_t i = 0; i < diagnostics.count; i++){
                                //     CeClangDDiagnostic_t* diag = diagnostics.elements + i;
                                //     printf("  %lld, %lld -> %lld, %lld %s\n",
                                //            diag->start.x, diag->start.y, diag->end.x, diag->end.y,
                                //            diag->message);
                                // }
                                CeBuffer_t* buffer = find_already_loaded_file(app->buffer_node_head, diagnostics.filepath);
                                if(buffer){
                                    CeAppBufferData_t* app_data = (CeAppBufferData_t*)(buffer->app_data);
                                    if(app_data->clangd_diagnostics.count > 0){
                                        ce_clangd_diag_free(&app_data->clangd_diagnostics);
                                    }
                                    memcpy(&app_data->clangd_diagnostics, &diagnostics, sizeof(diagnostics));
                                }else{
                                    ce_clangd_diag_free(&diagnostics);
                                }
                            }
                        }
                    }
               }
          }
          ce_clangd_response_free(&response);
     }
}

// Assembly:
cmpq $0x0, 0x2cf8(%rdi)
je 0x1316e
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4b8, %rsp            # imm = 0x4B8
movq %rdi, %rbx
leaq 0x2cd0(%rdi), %r14
leaq 0x2828(%rdi), %r15
leaq 0x2d50(%rdi), %rax
movq %rax, 0x8(%rsp)
leaq 0x2d80(%rdi), %rax
movq %rax, 0x40(%rsp)
leaq 0x1a50(%rdi), %rax
movq %rax, 0x10(%rsp)
leaq 0x20(%rdi), %rax
movq %rax, 0x50(%rsp)
leaq 0x28(%rsp), %r12
movq %r15, 0x48(%rsp)
movq %r14, %rdi
callq 0x15466
testb %al, %al
je 0x1315d
movq %r12, %rdi
movq %r14, %rsi
callq 0x1546f
movq 0x38(%rsp), %r13
testq %r13, %r13
je 0x12faa
movq %r13, %rdi
leaq 0x18f56(%rip), %rsi     # 0x2bc27
callq 0xd390
testl %eax, %eax
je 0x12d80
movq %r13, %rdi
leaq 0x18f5b(%rip), %rsi     # 0x2bc43
callq 0xd390
testl %eax, %eax
je 0x12d80
movq %r13, %rdi
leaq 0x18f5c(%rip), %rsi     # 0x2bc5b
callq 0xd390
testl %eax, %eax
je 0x12d80
movq %r13, %rdi
leaq 0x18f62(%rip), %rsi     # 0x2bc74
callq 0xd390
testl %eax, %eax
je 0x12d80
movq %r13, %rdi
leaq 0x18f6b(%rip), %rsi     # 0x2bc90
callq 0xd390
testl %eax, %eax
je 0x1306a
movq %r13, %rdi
leaq 0x18f6c(%rip), %rsi     # 0x2bca8
callq 0xd390
testl %eax, %eax
jne 0x12ff0
movq 0x30(%rsp), %rdi
movq 0x2828(%rbx), %rdx
movq 0x2898(%rbx), %rsi
callq 0x12967
movq 0x2898(%rbx), %rsi
cmpq $0x0, 0x8(%rsi)
jle 0x12ff0
movq %rbx, %rdi
callq 0x13236
jmp 0x12ff0
movq 0x2818(%rbx), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rbp
movq 0x30(%rsp), %r13
movl $0x410, %edx            # imm = 0x410
leaq 0xa8(%rsp), %rdi
xorl %esi, %esi
callq 0xd2a0
movq %r13, %rdi
leaq 0x18e07(%rip), %rsi     # 0x2bbb9
callq 0x1af29
movl %eax, 0x18(%rsp)
movq %rdx, 0x20(%rsp)
cmpl $0x2, %eax
jne 0x12f69
movq %r13, %rdi
leaq 0x18(%rsp), %rsi
callq 0x1afa7
testq %rax, %rax
je 0x12f69
movq %rax, %r13
cmpq $0x0, 0x8(%rax)
je 0x12f69
movq (%r13), %rdi
cmpl $0x1, (%rdi)
jne 0x12f69
addq $0x8, %rdi
leaq 0x18de7(%rip), %rsi     # 0x2bbec
callq 0x1af29
movl %eax, 0x58(%rsp)
movq %rdx, 0x60(%rsp)
cmpl $0x1, %eax
jne 0x12f64
movq (%r13), %rdi
addq $0x8, %rdi
leaq 0x58(%rsp), %rsi
callq 0x1af8c
testq %rax, %rax
je 0x12f64
movq %rax, %r15
movq %rax, %rdi
leaq 0x17885(%rip), %rsi     # 0x2a6c9
callq 0x1af29
movl %eax, 0x98(%rsp)
movq %rdx, 0xa0(%rsp)
cmpl $0x1, 0x58(%rsp)
jne 0x12f64
movq %r15, %rdi
leaq 0x98(%rsp), %rsi
callq 0x1af8c
testq %rax, %rax
je 0x12f64
movq %rax, %r15
movq %rax, %rdi
leaq 0x18d69(%rip), %rsi     # 0x2bbf2
callq 0x1af29
movl %eax, 0x88(%rsp)
movq %rdx, 0x90(%rsp)
cmpl $0x4, %eax
jne 0x12f64
movq %r15, %rdi
leaq 0x88(%rsp), %rsi
callq 0x1afdb
testq %rax, %rax
je 0x12f64
cvttsd2si (%rax), %rax
movq %rax, 0xa8(%rsp)
movq %r15, %rdi
leaq 0x17de7(%rip), %rsi     # 0x2acbd
callq 0x1af29
movl %eax, 0x78(%rsp)
movq %rdx, 0x80(%rsp)
cmpl $0x4, %eax
jne 0x12f64
movq %r15, %rdi
leaq 0x78(%rsp), %rsi
callq 0x1afdb
testq %rax, %rax
je 0x12f64
cvttsd2si (%rax), %rax
movq %rax, 0xb0(%rsp)
movq (%r13), %rdi
addq $0x8, %rdi
leaq 0x18ce9(%rip), %rsi     # 0x2bc03
callq 0x1af29
movl %eax, 0x68(%rsp)
movq %rdx, 0x70(%rsp)
cmpl $0x3, %eax
jne 0x12f64
movq (%r13), %rdi
addq $0x8, %rdi
leaq 0x68(%rsp), %rsi
callq 0x1afc2
testq %rax, %rax
je 0x12f64
movl $0x3ff, %edx            # imm = 0x3FF
leaq 0xb8(%rsp), %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0xd0b0
movq %r15, %rdi
callq 0x128d5
movq 0x48(%rsp), %r15
addq $0x8, %rbp
leaq 0xa8(%rsp), %rax
movq %rax, (%rsp)
movq %r15, %rdi
movq %rbp, %rsi
movq 0x10(%rsp), %rdx
movq 0x50(%rsp), %rcx
pushq $0x1
popq %r8
xorl %r9d, %r9d
callq 0x1316f
testq %rax, %rax
je 0x12ff0
movq (%r15), %rax
movq (%rax), %rsi
movq %r14, %rdi
callq 0x14cd5
jmp 0x12ff0
movq 0x30(%rsp), %rdi
leaq 0x18d0a(%rip), %rsi     # 0x2bcc0
callq 0x1af29
movl %eax, 0x18(%rsp)
movq %rdx, 0x20(%rsp)
cmpl $0x3, %eax
jne 0x12ff0
movq 0x30(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x1afc2
testq %rax, %rax
je 0x12ff0
movq %rax, %rdi
leaq 0x18ce0(%rip), %rsi     # 0x2bcc7
callq 0xd390
testl %eax, %eax
je 0x12ffd
movq %r12, %rdi
callq 0x15603
jmp 0x12c9e
movq 0x30(%rsp), %rsi
leaq 0xa8(%rsp), %rdi
callq 0x125b9
movq 0xb8(%rsp), %rsi
testq %rsi, %rsi
je 0x12ff0
movq (%r15), %rdi
callq 0x10f43
testq %rax, %rax
je 0x1314b
movq %r15, %r13
movq 0x58(%rax), %rax
leaq 0x610(%rax), %r15
cmpq $0x0, 0x618(%rax)
jle 0x1304d
movq %r15, %rdi
callq 0x1568e
movq 0xb8(%rsp), %rax
movq %rax, 0x10(%r15)
movups 0xa8(%rsp), %xmm0
movups %xmm0, (%r15)
movq %r13, %r15
jmp 0x12ff0
movq 0x2d70(%rbx), %rdi
testq %rdi, %rdi
je 0x13087
callq 0x18e0f
movq 0x2d70(%rbx), %rdi
callq 0xd090
movq 0x30(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x12084
movq %rax, 0x2d70(%rbx)
testq %rax, %rax
je 0x12ff0
movq 0x2818(%rbx), %rcx
movq 0x10(%rcx), %rcx
movq 0x10(%rcx), %r13
cmpl $0x0, (%r13)
jne 0x12ff0
movq 0x38(%r13), %rcx
movq 0x8(%rsp), %rdx
movq (%rdx), %rsi
subq %rsi, %rcx
jle 0x13108
movq 0x48(%r13), %rdi
movq 0x2d58(%rbx), %rdx
callq 0xf361
movq %r15, %rbp
movq %rax, %r15
movq 0x2d70(%rbx), %rdi
movq %rax, %rsi
callq 0x18e97
movq %r15, %rdi
movq %rbp, %r15
callq 0xd090
movq 0x2d70(%rbx), %rax
addq $0x8, %r13
movq 0x2d78(%rbx), %rdi
movq %rax, %rsi
callq 0x11518
movq 0x2d78(%rbx), %r8
movq 0x2d50(%rbx), %rsi
movq 0x2d58(%rbx), %rdx
movq %rbx, (%rsp)
movq 0x40(%rsp), %rdi
movq %r13, %rcx
movq 0x10(%rsp), %r9
callq 0x1248e
jmp 0x12ff0
leaq 0xa8(%rsp), %rdi
callq 0x1568e
jmp 0x12ff0
addq $0x4b8, %rsp            # imm = 0x4B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq