From fc30bb2b323f3e572c8f25dbd3c6c86d2356da6c Mon Sep 17 00:00:00 2001 From: shaoying Date: Thu, 30 Jul 2020 10:30:50 +0800 Subject: [PATCH] opt git.spide --- core/code/go.go | 5 ++-- core/code/inner.go | 1 + exec.go | 2 +- misc/git/git.go | 63 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 65 insertions(+), 6 deletions(-) diff --git a/core/code/go.go b/core/code/go.go index b27637d7..851b9c74 100644 --- a/core/code/go.go +++ b/core/code/go.go @@ -91,8 +91,9 @@ func init() { m.Cmd(mdb.RENDER, mdb.CREATE, GODOC, GODOC, c.Cap(ice.CTX_FOLLOW)) m.Cmd(mdb.PLUGIN, mdb.CREATE, MOD, MOD, c.Cap(ice.CTX_FOLLOW)) - m.Cmd(mdb.PLUGIN, mdb.CREATE, MOD, MOD, c.Cap(ice.CTX_FOLLOW)) - m.Cmd(mdb.RENDER, mdb.CREATE, SUM, SUM, c.Cap(ice.CTX_FOLLOW)) + m.Cmd(mdb.RENDER, mdb.CREATE, MOD, MOD, c.Cap(ice.CTX_FOLLOW)) + + m.Cmd(mdb.PLUGIN, mdb.CREATE, SUM, SUM, c.Cap(ice.CTX_FOLLOW)) m.Cmd(mdb.RENDER, mdb.CREATE, SUM, SUM, c.Cap(ice.CTX_FOLLOW)) }}, diff --git a/core/code/inner.go b/core/code/inner.go index c33fd0ba..91f1b3e1 100644 --- a/core/code/inner.go +++ b/core/code/inner.go @@ -87,6 +87,7 @@ func init() { Configs: map[string]*ice.Config{ INNER: {Name: "inner", Help: "编辑器", Value: kit.Data( "source", kit.Dict( + "license", "true", "makefile", "true", "shy", "true", "py", "true", diff --git a/exec.go b/exec.go index 0e7922a7..aeb4e4db 100644 --- a/exec.go +++ b/exec.go @@ -17,7 +17,7 @@ func (m *Message) TryCatch(msg *Message, safe bool, hand ...func(msg *Message)) case io.EOF: case nil: default: - fileline := kit.FileLine(5, 2) + fileline := kit.FileLine(4, 2) m.Log(LOG_WARN, "catch: %s %s", e, fileline) m.Log(LOG_INFO, "chain: %s", msg.Format("chain")) m.Log(LOG_WARN, "catch: %s %s", e, fileline) diff --git a/misc/git/git.go b/misc/git/git.go index 19c68ebf..c4d30c62 100644 --- a/misc/git/git.go +++ b/misc/git/git.go @@ -291,16 +291,73 @@ var Index = &ice.Context{Name: "git", Help: "代码库", m.Cmdy("total", arg) }}, - "spide": {Name: "spide name=auto auto", Help: "趋势图", Meta: kit.Dict( + "spide": {Name: "spide path=auto file=auto auto", Help: "结构图", Meta: kit.Dict( "display", "/plugin/story/spide.js", ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if len(arg) > 0 && arg[0] == "inner" { + arg[1] = path.Join("usr", arg[1]) + m.Cmdy("web.code.inner", arg[1:]) + return + } + if len(arg) == 0 { m.Option("_display", "table") m.Cmdy("total", arg) return } - m.Option(nfs.DIR_DEEP, "true") - m.Cmdy(nfs.DIR, mdb.RENDER, nfs.DIR, "", path.Join("usr", arg[0])) + if len(arg) == 1 { + m.Option(nfs.DIR_DEEP, "true") + m.Cmdy(nfs.DIR, mdb.RENDER, nfs.DIR, "", path.Join("usr", arg[0])) + return + } + + tags := "" + m.Option(cli.CMD_DIR, path.Join("usr", arg[0])) + if strings.HasSuffix(arg[1], ".go") { + tags = m.Cmdx(cli.SYSTEM, "gotags", arg[1]) + for _, line := range strings.Split(tags, "\n") { + m.Debug("line: %v", line) + if len(line) == 0 || strings.HasPrefix(line, "!_") { + continue + } + + ls := kit.Split(line, "\t ", "\t ", "\t ") + name := ls[3] + ":" + ls[0] + switch ls[3] { + case "m": + if strings.HasPrefix(ls[5], "ctype") { + name = strings.TrimPrefix(ls[5], "ctype:") + ":" + ls[0] + } else if strings.HasPrefix(ls[6], "ntype") { + name = "-" + ls[0] + } else { + + } + case "w": + t := ls[len(ls)-1] + name = "-" + ls[0] + ":" + strings.TrimPrefix(t, "type:") + } + + m.Push("name", name) + m.Push("file", ls[1]) + m.Push("line", strings.TrimSuffix(ls[2], ";\"")) + m.Push("type", ls[3]) + m.Push("extra", strings.Join(ls[4:], " ")) + } + } else { + tags = m.Cmdx(cli.SYSTEM, "ctags", "-f", "-", arg[1]) + for _, line := range strings.Split(tags, "\n") { + if len(line) == 0 || strings.HasPrefix(line, "!_") { + continue + } + + ls := kit.Split(line, "\t ", "\t ", "\t ") + m.Push("name", ls[0]) + m.Push("file", ls[1]) + m.Push("line", "1") + } + } + + m.Sort("line", "int") }}, }, }