1
0
forked from x/icebergs

opt vimer

This commit is contained in:
harveyshao 2022-05-16 00:56:32 +08:00
parent 13a9b81ea4
commit 30b0d12f6f
2 changed files with 32 additions and 19 deletions

View File

@ -3,6 +3,7 @@ package code
import ( import (
"path" "path"
"strings" "strings"
"sync"
ice "shylinux.com/x/icebergs" ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/cli" "shylinux.com/x/icebergs/base/cli"
@ -13,9 +14,27 @@ import (
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
var _cache_msg *ice.Message var _cache_mods = map[string]*ice.Message{}
var _cache_ice *ice.Message var _cache_lock = sync.Mutex{}
var _cache_bin *ice.Message
func _vimer_doc(m *ice.Message, mod string, pkg string) *ice.Message {
_cache_lock.Lock()
defer _cache_lock.Unlock()
key := kit.Keys(mod, pkg)
if msg, ok := _cache_mods[key]; ok && kit.Time(msg.Time("24h")) > kit.Time(m.Time()) {
return msg
}
if mod != "" {
m.Cmd(cli.SYSTEM, "go", "get", mod)
}
if msg := _vimer_go_complete(m.Spawn(), key); msg.Length() > 0 {
_cache_mods[key] = msg
return msg
}
return nil
}
func _vimer_defs(m *ice.Message, ext string) string { func _vimer_defs(m *ice.Message, ext string) string {
defs := kit.Dict( defs := kit.Dict(
@ -138,24 +157,17 @@ func _vimer_complete(m *ice.Message, arg ...string) {
if m.Option(mdb.NAME) == ice.PT { if m.Option(mdb.NAME) == ice.PT {
switch m.Option(mdb.TYPE) { switch m.Option(mdb.TYPE) {
case "msg", "m": case "msg", "m":
if _cache_msg != nil { m.Copy(_vimer_doc(m, "shylinux.com/x/ice", "Message"))
m.Copy(_cache_msg) m.Copy(_vimer_doc(m, "shylinux.com/x/icebergs", "Message"))
break
}
_cache_msg = m
_vimer_go_complete(m, "shylinux.com/x/icebergs.Message")
_vimer_go_complete(m, "shylinux.com/x/ice.Message")
case "ice", "*ice": case "ice", "*ice":
if _cache_ice != nil { m.Copy(_vimer_doc(m, "shylinux.com/x/ice", ""))
m.Copy(_cache_ice)
break case "kit":
} m.Copy(_vimer_doc(m, "shylinux.com/x/toolkits", ""))
_cache_ice = m
_vimer_go_complete(m, "shylinux.com/x/ice")
default: default:
_vimer_go_complete(m, m.Option(mdb.TYPE)) m.Copy(_vimer_doc(m, "", m.Option(mdb.TYPE)))
} }
} else { } else {
@ -207,7 +219,7 @@ func _vimer_complete(m *ice.Message, arg ...string) {
} }
} }
} }
func _vimer_go_complete(m *ice.Message, name string, arg ...string) { func _vimer_go_complete(m *ice.Message, name string, arg ...string) *ice.Message {
kit.Fetch(kit.Split(m.Cmdx(cli.SYSTEM, GO, "doc", name), ice.NL, ice.NL, ice.NL), func(index int, value string) { kit.Fetch(kit.Split(m.Cmdx(cli.SYSTEM, GO, "doc", name), ice.NL, ice.NL, ice.NL), func(index int, value string) {
if ls := kit.Split(value); len(ls) > 1 { if ls := kit.Split(value); len(ls) > 1 {
switch ls[0] { switch ls[0] {
@ -221,6 +233,7 @@ func _vimer_go_complete(m *ice.Message, name string, arg ...string) {
} }
} }
}) })
return m
} }
const VIMER = "vimer" const VIMER = "vimer"

View File

@ -63,7 +63,7 @@ func init() {
if m.Option(mdb.TEXT) == "" { if m.Option(mdb.TEXT) == "" {
return return
} }
name, list := "", kit.Select("", kit.Slice(kit.Split(m.Option(mdb.TEXT), "\t \n."), -1), 0) name := kit.Select("", kit.Slice(kit.Split(m.Option(mdb.TEXT), "\t \n."), -1), 0)
switch name { switch name {
case "can": case "can":
mdb.ZoneSelectCB(m, "", func(value map[string]string) { mdb.ZoneSelectCB(m, "", func(value map[string]string) {