j
This commit is contained in:
parent
5b65c4c0e4
commit
985aa16236
13 changed files with 1381 additions and 241 deletions
|
|
@ -78,6 +78,7 @@ Daemon_Client :: struct {
|
|||
response_mutex: sync.Mutex,
|
||||
diagnostic_events: [dynamic]Daemon_Event,
|
||||
gradle_events: [dynamic]Daemon_Event,
|
||||
workspace_response_id: int,
|
||||
pending_response_ids: [dynamic]int,
|
||||
responses: [dynamic]Daemon_Response,
|
||||
}
|
||||
|
|
@ -180,7 +181,7 @@ daemon_stop_process :: proc(child: ^Daemon_Process) {
|
|||
state, wait_err := os.process_wait(child.process, 2 * time.Second)
|
||||
if wait_err != nil || !state.exited {
|
||||
_ = os.process_kill(child.process)
|
||||
_, _ = os.process_wait(child.process)
|
||||
_, _ = os.process_wait(child.process, 500 * time.Millisecond)
|
||||
}
|
||||
child.running = false
|
||||
}
|
||||
|
|
@ -284,7 +285,8 @@ daemon_close :: proc(client: ^Daemon_Client) {
|
|||
net.close(client.socket)
|
||||
client.connected = false
|
||||
}
|
||||
if client.reader != nil && thread.is_done(client.reader) {
|
||||
if client.reader != nil {
|
||||
thread.join(client.reader)
|
||||
thread.destroy(client.reader)
|
||||
client.reader = nil
|
||||
}
|
||||
|
|
@ -328,6 +330,8 @@ daemon_send_workspace_open :: proc(client: ^Daemon_Client, workspace: string) {
|
|||
if !client.connected do return
|
||||
id := client.next_id
|
||||
client.next_id += 1
|
||||
client.workspace_response_id = id
|
||||
daemon_track_response(client, id)
|
||||
request := fmt.tprintf("{{\"id\":%d,\"method\":\"workspace/open\",\"params\":{{\"root\":%s}}}}\n", id, json_quote(workspace))
|
||||
daemon_send(client, request)
|
||||
}
|
||||
|
|
@ -572,6 +576,45 @@ daemon_apply_latest_diagnostics :: proc(client: ^Daemon_Client, editor: ^Editor)
|
|||
}
|
||||
}
|
||||
|
||||
daemon_apply_workspace_response :: proc(client: ^Daemon_Client, editor: ^Editor) {
|
||||
if client.workspace_response_id == 0 do return
|
||||
|
||||
response := daemon_take_response(client, client.workspace_response_id)
|
||||
defer delete(response)
|
||||
if len(response) == 0 do return
|
||||
|
||||
message, value, ok := parse_protocol_message(string(response[:]))
|
||||
if !ok {
|
||||
client.workspace_response_id = 0
|
||||
return
|
||||
}
|
||||
defer json.destroy_value(value)
|
||||
if message.kind != .Response || message.id != client.workspace_response_id do return
|
||||
|
||||
client.workspace_response_id = 0
|
||||
if message.ok {
|
||||
editor_set_status(editor, "Kotlin daemon workspace ready")
|
||||
return
|
||||
}
|
||||
|
||||
error_message := protocol_error_message(value)
|
||||
defer delete(error_message)
|
||||
if len(error_message) > 0 {
|
||||
editor_set_status(editor, fmt.tprintf("Kotlin daemon workspace failed: %s", error_message))
|
||||
} else {
|
||||
editor_set_status(editor, "Kotlin daemon workspace failed")
|
||||
}
|
||||
}
|
||||
|
||||
protocol_error_message :: proc(value: json.Value) -> string {
|
||||
error_value, has_error := json_object_get(value, "error")
|
||||
if !has_error do return strings.clone("")
|
||||
message, _ := json_get_string(error_value, "message")
|
||||
if len(message) > 0 do return strings.clone(message)
|
||||
code, _ := json_get_string(error_value, "code")
|
||||
return strings.clone(code)
|
||||
}
|
||||
|
||||
diagnostics_destroy :: proc(diagnostics: []Diagnostic) {
|
||||
for diagnostic in diagnostics {
|
||||
delete(diagnostic.severity)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue