api/conversions: Do not shorten file paths

The shortening of file paths is purely a terminal UI concern. Move that
code to the presentation layer, and remove from the service layer.
This commit is contained in:
Derek Parker
2015-08-19 17:38:53 -05:00
parent 8d6bb4a1bb
commit 32b499fa47
2 changed files with 20 additions and 22 deletions

View File

@ -2,8 +2,6 @@ package api
import ( import (
"debug/gosym" "debug/gosym"
"os"
"strings"
"github.com/derekparker/delve/proc" "github.com/derekparker/delve/proc"
) )
@ -13,7 +11,7 @@ func ConvertBreakpoint(bp *proc.Breakpoint) *Breakpoint {
return &Breakpoint{ return &Breakpoint{
ID: bp.ID, ID: bp.ID,
FunctionName: bp.FunctionName, FunctionName: bp.FunctionName,
File: shortenFilePath(bp.File), File: bp.File,
Line: bp.Line, Line: bp.Line,
Addr: bp.Addr, Addr: bp.Addr,
Tracepoint: bp.Tracepoint, Tracepoint: bp.Tracepoint,
@ -43,7 +41,7 @@ func ConvertThread(th *proc.Thread) *Thread {
return &Thread{ return &Thread{
ID: th.Id, ID: th.Id,
PC: pc, PC: pc,
File: shortenFilePath(file), File: file,
Line: line, Line: line,
Function: function, Function: function,
} }
@ -76,7 +74,7 @@ func ConvertGoroutine(g *proc.G) *Goroutine {
return &Goroutine{ return &Goroutine{
ID: g.Id, ID: g.Id,
PC: g.PC, PC: g.PC,
File: shortenFilePath(g.File), File: g.File,
Line: g.Line, Line: g.Line,
Function: ConvertFunction(g.Func), Function: ConvertFunction(g.Func),
} }
@ -85,13 +83,8 @@ func ConvertGoroutine(g *proc.G) *Goroutine {
func ConvertLocation(loc proc.Location) Location { func ConvertLocation(loc proc.Location) Location {
return Location{ return Location{
PC: loc.PC, PC: loc.PC,
File: shortenFilePath(loc.File), File: loc.File,
Line: loc.Line, Line: loc.Line,
Function: ConvertFunction(loc.Fn), Function: ConvertFunction(loc.Fn),
} }
} }
func shortenFilePath(fullPath string) string {
workingDir, _ := os.Getwd()
return strings.Replace(fullPath, workingDir, ".", 1)
}

View File

@ -154,10 +154,10 @@ func threads(client service.Client, args ...string) error {
} }
if th.Function != nil { if th.Function != nil {
fmt.Printf("%sThread %d at %#v %s:%d %s\n", fmt.Printf("%sThread %d at %#v %s:%d %s\n",
prefix, th.ID, th.PC, th.File, prefix, th.ID, th.PC, shortenFilePath(th.File),
th.Line, th.Function.Name) th.Line, th.Function.Name)
} else { } else {
fmt.Printf("%sThread %d at %s:%d\n", prefix, th.ID, th.File, th.Line) fmt.Printf("%sThread %d at %s:%d\n", prefix, th.ID, shortenFilePath(th.File), th.Line)
} }
} }
return nil return nil
@ -209,7 +209,7 @@ func formatGoroutine(g *api.Goroutine) string {
if g.Function != nil { if g.Function != nil {
fname = g.Function.Name fname = g.Function.Name
} }
return fmt.Sprintf("%d - %s:%d %s (%#v)", g.ID, g.File, g.Line, fname, g.PC) return fmt.Sprintf("%d - %s:%d %s (%#v)", g.ID, shortenFilePath(g.File), g.Line, fname, g.PC)
} }
func restart(client service.Client, args ...string) error { func restart(client service.Client, args ...string) error {
@ -261,7 +261,7 @@ func clear(client service.Client, args ...string) error {
if err != nil { if err != nil {
return err return err
} }
fmt.Printf("Breakpoint %d cleared at %#v for %s %s:%d\n", bp.ID, bp.Addr, bp.FunctionName, bp.File, bp.Line) fmt.Printf("Breakpoint %d cleared at %#v for %s %s:%d\n", bp.ID, bp.Addr, bp.FunctionName, shortenFilePath(bp.File), bp.Line)
return nil return nil
} }
@ -273,9 +273,9 @@ func clearAll(client service.Client, args ...string) error {
for _, bp := range breakPoints { for _, bp := range breakPoints {
_, err := client.ClearBreakpoint(bp.ID) _, err := client.ClearBreakpoint(bp.ID)
if err != nil { if err != nil {
fmt.Printf("Couldn't delete breakpoint %d at %#v %s:%d: %s\n", bp.ID, bp.Addr, bp.File, bp.Line, err) fmt.Printf("Couldn't delete breakpoint %d at %#v %s:%d: %s\n", bp.ID, bp.Addr, shortenFilePath(bp.File), bp.Line, err)
} }
fmt.Printf("Breakpoint %d cleared at %#v for %s %s:%d\n", bp.ID, bp.Addr, bp.FunctionName, bp.File, bp.Line) fmt.Printf("Breakpoint %d cleared at %#v for %s %s:%d\n", bp.ID, bp.Addr, bp.FunctionName, shortenFilePath(bp.File), bp.Line)
} }
return nil return nil
} }
@ -297,7 +297,7 @@ func breakpoints(client service.Client, args ...string) error {
if bp.Tracepoint { if bp.Tracepoint {
thing = "Tracepoint" thing = "Tracepoint"
} }
fmt.Printf("%s %d at %#v %s:%d\n", thing, bp.ID, bp.Addr, bp.File, bp.Line) fmt.Printf("%s %d at %#v %s:%d\n", thing, bp.ID, bp.Addr, shortenFilePath(bp.File), bp.Line)
var attrs []string var attrs []string
if bp.Stacktrace > 0 { if bp.Stacktrace > 0 {
@ -356,7 +356,7 @@ func setBreakpoint(client service.Client, tracepoint bool, args ...string) error
return err return err
} }
fmt.Printf("%s %d set at %#v for %s %s:%d\n", thing, bp.ID, bp.Addr, bp.FunctionName, bp.File, bp.Line) fmt.Printf("%s %d set at %#v for %s %s:%d\n", thing, bp.ID, bp.Addr, bp.FunctionName, shortenFilePath(bp.File), bp.Line)
} }
return nil return nil
} }
@ -518,7 +518,7 @@ func printStack(stack []api.Location, ind string) {
if stack[i].Function != nil { if stack[i].Function != nil {
name = stack[i].Function.Name name = stack[i].Function.Name
} }
fmt.Printf("%s%d. %s %s:%d (%#v)\n", ind, i, name, stack[i].File, stack[i].Line, stack[i].PC) fmt.Printf("%s%d. %s %s:%d (%#v)\n", ind, i, name, shortenFilePath(stack[i].File), stack[i].Line, stack[i].PC)
} }
} }
@ -541,9 +541,9 @@ func printcontext(state *api.DebuggerState) error {
for _, arg := range state.CurrentThread.Function.Args { for _, arg := range state.CurrentThread.Function.Args {
args = append(args, arg.Value) args = append(args, arg.Value)
} }
fmt.Printf("> %s(%s) %s:%d\n", fn.Name, strings.Join(args, ", "), state.CurrentThread.File, state.CurrentThread.Line) fmt.Printf("> %s(%s) %s:%d\n", fn.Name, strings.Join(args, ", "), shortenFilePath(state.CurrentThread.File), state.CurrentThread.Line)
} else { } else {
fmt.Printf("> %s() %s:%d\n", fn.Name, state.CurrentThread.File, state.CurrentThread.Line) fmt.Printf("> %s() %s:%d\n", fn.Name, shortenFilePath(state.CurrentThread.File), state.CurrentThread.Line)
} }
if state.BreakpointInfo != nil { if state.BreakpointInfo != nil {
@ -635,3 +635,8 @@ func (ere ExitRequestError) Error() string {
func exitCommand(client service.Client, args ...string) error { func exitCommand(client service.Client, args ...string) error {
return ExitRequestError{} return ExitRequestError{}
} }
func shortenFilePath(fullPath string) string {
workingDir, _ := os.Getwd()
return strings.Replace(fullPath, workingDir, ".", 1)
}