************************************************************ * entry function ************************************************************/
(ir *interp.Interp, receipt msgReceipt)
| 19 | * entry function |
| 20 | ************************************************************/ |
| 21 | func handleCompleteRequest(ir *interp.Interp, receipt msgReceipt) error { |
| 22 | // Extract the data from the request. |
| 23 | reqcontent := receipt.Msg.Content.(map[string]interface{}) |
| 24 | code := reqcontent["code"].(string) |
| 25 | cursorPos := int(reqcontent["cursor_pos"].(float64)) |
| 26 | |
| 27 | // autocomplete the code at the cursor position |
| 28 | prefix, matches, _ := ir.CompleteWords(code, cursorPos) |
| 29 | |
| 30 | // prepare the reply |
| 31 | content := make(map[string]interface{}) |
| 32 | |
| 33 | if len(matches) == 0 { |
| 34 | content["ename"] = "ERROR" |
| 35 | content["evalue"] = "no completions found" |
| 36 | content["traceback"] = nil |
| 37 | content["status"] = "error" |
| 38 | } else { |
| 39 | partialWord := interp.TailIdentifier(prefix) |
| 40 | content["cursor_start"] = float64(len(prefix) - len(partialWord)) |
| 41 | content["cursor_end"] = float64(cursorPos) |
| 42 | content["matches"] = matches |
| 43 | content["status"] = "ok" |
| 44 | } |
| 45 | |
| 46 | return receipt.Reply("complete_reply", content) |
| 47 | } |