MCPcopy
hub / github.com/x-motemen/gore / Eval

Method Eval

session.go:419–473  ·  view source on GitHub ↗

Eval the input.

(in string)

Source from the content-addressed store, hash-verified

417
418// Eval the input.
419func (s *Session) Eval(in string) error {
420 debugf("eval >>> %q", in)
421
422 s.clearQuickFix()
423 s.storeCode()
424
425 if strings.HasPrefix(strings.TrimSpace(in), ":") {
426 err := s.invokeCommand(in)
427 if err != nil && err != ErrQuit {
428 fmt.Fprintf(s.stderr, "%s\n", err)
429 }
430 return err
431 }
432
433 if _, err := s.evalExpr(in); err != nil {
434 debugf("expr :: err = %s", err)
435
436 err := s.evalStmt(in)
437 if err != nil {
438 debugf("stmt :: err = %s", err)
439
440 err := s.evalFunc(in)
441 if err != nil {
442 debugf("func :: err = %s", err)
443
444 if err := s.parseTokens(in); err != nil {
445 fmt.Fprintf(s.stderr, "%s\n", err)
446 return err
447 }
448
449 return ErrContinue
450 }
451 }
452 }
453
454 if s.autoImport {
455 if err := s.fixImports(); err != nil {
456 debugf("fixImports :: err = %s", err)
457 }
458 }
459 s.doQuickFix()
460
461 err := s.Run()
462 if err != nil {
463 if _, ok := err.(*exec.ExitError); ok {
464 debugf("got exit error, popping out last input")
465 s.restoreCode()
466 }
467 debugf("%s", err)
468 err = ErrCmdRun
469 }
470
471 s.updateCompleter()
472 return err
473}
474
475func (s *Session) updateCompleter() {
476 if s.completer != nil {

Callers 15

TestAction_TypeFunction · 0.95
TestAction_DocFunction · 0.95
TestAction_ImportFunction · 0.95
TestAction_ClearFunction · 0.95
TestAction_HelpFunction · 0.95
TestAction_QuitFunction · 0.95
TestSessionEval_importFunction · 0.95

Calls 13

clearQuickFixMethod · 0.95
storeCodeMethod · 0.95
invokeCommandMethod · 0.95
evalExprMethod · 0.95
evalStmtMethod · 0.95
evalFuncMethod · 0.95
parseTokensMethod · 0.95
fixImportsMethod · 0.95
doQuickFixMethod · 0.95
RunMethod · 0.95
restoreCodeMethod · 0.95
updateCompleterMethod · 0.95

Tested by 15

TestAction_TypeFunction · 0.76
TestAction_DocFunction · 0.76
TestAction_ImportFunction · 0.76
TestAction_ClearFunction · 0.76
TestAction_HelpFunction · 0.76
TestAction_QuitFunction · 0.76
TestSessionEval_importFunction · 0.76