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

Method fixImports

session.go:635–664  ·  view source on GitHub ↗

fixImports formats and adjusts imports for the current AST.

()

Source from the content-addressed store, hash-verified

633
634// fixImports formats and adjusts imports for the current AST.
635func (s *Session) fixImports() error {
636 // Fix against error: no required module provides package ...; try 'go get -d ...'
637 for _, path := range s.requiredModules {
638 cmd := exec.Command("go", "get", "-d", path)
639 cmd.Dir = s.tempDir
640 if err := cmd.Run(); err != nil {
641 debugf("failed to go get -d %q: %s", path, err)
642 }
643 }
644 s.requiredModules = nil
645
646 var buf bytes.Buffer
647 err := printer.Fprint(&buf, s.fset, s.file)
648 if err != nil {
649 return err
650 }
651
652 formatted, err := imports.Process("", buf.Bytes(), nil)
653 if err != nil {
654 return err
655 }
656
657 s.file, err = parser.ParseFile(s.fset, "", formatted, parser.Mode(0))
658 if err != nil {
659 return err
660 }
661 s.mainBody = s.mainFunc().Body
662
663 return nil
664}
665
666func (s *Session) includePackage(path string) error {
667 pkg, err := build.Import(path, ".", 0)

Callers 1

EvalMethod · 0.95

Calls 3

mainFuncMethod · 0.95
debugfFunction · 0.70
RunMethod · 0.45

Tested by

no test coverage detected