github.com/jmigpin/editor@v1.6.0/core/internalcmds/lsprotocallhierarchy.go (about)

     1  package internalcmds
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"io"
     7  	"path/filepath"
     8  
     9  	"github.com/jmigpin/editor/core"
    10  	"github.com/jmigpin/editor/core/lsproto"
    11  	"github.com/jmigpin/editor/util/iout/iorw"
    12  )
    13  
    14  func LSProtoCallHierarchyIncomingCalls(args0 *core.InternalCmdArgs) error {
    15  	return lsprotoCallHierarchyCalls(args0, lsproto.IncomingChct)
    16  }
    17  func LSProtoCallHierarchyOutgoingCalls(args0 *core.InternalCmdArgs) error {
    18  	return lsprotoCallHierarchyCalls(args0, lsproto.OutgoingChct)
    19  }
    20  
    21  func lsprotoCallHierarchyCalls(args0 *core.InternalCmdArgs, typ lsproto.CallHierarchyCallType) error {
    22  	ed := args0.Ed
    23  	erow := args0.ERow
    24  
    25  	if !erow.Info.IsFileButNotDir() {
    26  		return fmt.Errorf("not a file")
    27  	}
    28  
    29  	// create new erow to run on
    30  	dir := filepath.Dir(erow.Info.Name())
    31  	info := erow.Ed.ReadERowInfo(dir)
    32  	erow2 := core.NewBasicERow(info, erow.Row.PosBelow())
    33  	iorw.Append(erow2.Row.Toolbar.RW(), []byte(" | Stop"))
    34  	erow2.Flash()
    35  
    36  	// NOTE: args0.Ctx will end at func exit
    37  
    38  	erow2.Exec.RunAsync(func(ctx context.Context, rw io.ReadWriter) error {
    39  		// NOTE: not running in UI goroutine here
    40  
    41  		ta := erow.Row.TextArea
    42  		mcalls, err := ed.LSProtoMan.CallHierarchyCalls(ctx, erow.Info.Name(), ta.RW(), ta.CursorIndex(), typ)
    43  		if err != nil {
    44  			return err
    45  		}
    46  		str, err := lsproto.ManagerCallHierarchyCallsToString(mcalls, typ, erow2.Info.Dir())
    47  		if err != nil {
    48  			return err
    49  		}
    50  		fmt.Fprintf(rw, str)
    51  		return nil
    52  	})
    53  
    54  	return nil
    55  }