MCPcopy Index your code
hub / github.com/gopherdata/gophernotes / handleCompleteRequest

Function handleCompleteRequest

complete.go:21–47  ·  view source on GitHub ↗

************************************************************ * entry function ************************************************************/

(ir *interp.Interp, receipt msgReceipt)

Source from the content-addressed store, hash-verified

19* entry function
20************************************************************/
21func 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}

Callers 1

handleShellMsgMethod · 0.85

Calls 1

ReplyMethod · 0.80

Tested by

no test coverage detected