mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-04 14:10:23 +09:00
Merge pull request #3810 from Neko-Box-Coder/ShowBuiltinPlugins
Adding the ability to differentiate builtin plugins when listing
This commit is contained in:
@@ -71,7 +71,7 @@ type Plugin struct {
|
||||
Info *PluginInfo // json file containing info
|
||||
Srcs []RuntimeFile // lua files
|
||||
Loaded bool
|
||||
Default bool // pre-installed plugin
|
||||
Builtin bool
|
||||
}
|
||||
|
||||
// IsLoaded returns if a plugin is enabled
|
||||
|
||||
@@ -42,6 +42,7 @@ type PluginPackage struct {
|
||||
Author string
|
||||
Tags []string
|
||||
Versions PluginVersions
|
||||
Builtin bool
|
||||
}
|
||||
|
||||
// PluginPackages is a list of PluginPackage instances.
|
||||
@@ -75,6 +76,9 @@ func (pp *PluginPackage) String() string {
|
||||
buf := new(bytes.Buffer)
|
||||
buf.WriteString("Plugin: ")
|
||||
buf.WriteString(pp.Name)
|
||||
if pp.Builtin {
|
||||
buf.WriteString(" (built-in)")
|
||||
}
|
||||
buf.WriteRune('\n')
|
||||
if pp.Author != "" {
|
||||
buf.WriteString("Author: ")
|
||||
@@ -334,7 +338,7 @@ func isUnknownCoreVersion() bool {
|
||||
return err != nil
|
||||
}
|
||||
|
||||
func newStaticPluginVersion(name, version string) *PluginVersion {
|
||||
func newStaticPluginVersion(name, version string, builtin bool) *PluginVersion {
|
||||
vers, err := semver.ParseTolerant(version)
|
||||
|
||||
if err != nil {
|
||||
@@ -343,7 +347,8 @@ func newStaticPluginVersion(name, version string) *PluginVersion {
|
||||
}
|
||||
}
|
||||
pl := &PluginPackage{
|
||||
Name: name,
|
||||
Name: name,
|
||||
Builtin: builtin,
|
||||
}
|
||||
pv := &PluginVersion{
|
||||
pack: pl,
|
||||
@@ -358,7 +363,7 @@ func newStaticPluginVersion(name, version string) *PluginVersion {
|
||||
func GetInstalledVersions(withCore bool) PluginVersions {
|
||||
result := PluginVersions{}
|
||||
if withCore {
|
||||
result = append(result, newStaticPluginVersion(CorePluginName, util.Version))
|
||||
result = append(result, newStaticPluginVersion(CorePluginName, util.Version, true))
|
||||
}
|
||||
|
||||
for _, p := range Plugins {
|
||||
@@ -366,7 +371,7 @@ func GetInstalledVersions(withCore bool) PluginVersions {
|
||||
continue
|
||||
}
|
||||
version := GetInstalledPluginVersion(p.Name)
|
||||
if pv := newStaticPluginVersion(p.Name, version); pv != nil {
|
||||
if pv := newStaticPluginVersion(p.Name, version, p.Builtin); pv != nil {
|
||||
result = append(result, pv)
|
||||
}
|
||||
}
|
||||
@@ -604,7 +609,7 @@ func UpdatePlugins(out io.Writer, plugins []string) {
|
||||
// if no plugins are specified, update all installed plugins.
|
||||
if len(plugins) == 0 {
|
||||
for _, p := range Plugins {
|
||||
if !p.IsLoaded() || p.Default {
|
||||
if !p.IsLoaded() || p.Builtin || p.Name == "initlua" {
|
||||
continue
|
||||
}
|
||||
plugins = append(plugins, p.Name)
|
||||
@@ -613,7 +618,7 @@ func UpdatePlugins(out io.Writer, plugins []string) {
|
||||
|
||||
fmt.Fprintln(out, "Checking for plugin updates")
|
||||
microVersion := PluginVersions{
|
||||
newStaticPluginVersion(CorePluginName, util.Version),
|
||||
newStaticPluginVersion(CorePluginName, util.Version, true),
|
||||
}
|
||||
|
||||
var updates = make(PluginDependencies, 0)
|
||||
@@ -663,10 +668,14 @@ func PluginCommand(out io.Writer, cmd string, args []string) {
|
||||
case "remove":
|
||||
removed := ""
|
||||
for _, plugin := range args {
|
||||
if plugin == "initlua" {
|
||||
fmt.Fprintln(out, "initlua cannot be removed, but can be disabled via settings.")
|
||||
continue
|
||||
}
|
||||
// check if the plugin exists.
|
||||
for _, p := range Plugins {
|
||||
if p.Name == plugin && p.Default {
|
||||
fmt.Fprintln(out, "Default plugins cannot be removed, but can be disabled via settings.")
|
||||
if p.Name == plugin && p.Builtin {
|
||||
fmt.Fprintln(out, p.Name, "is a built-in plugin which cannot be removed, but can be disabled via settings.")
|
||||
continue
|
||||
}
|
||||
if p.Name == plugin {
|
||||
@@ -687,7 +696,13 @@ func PluginCommand(out io.Writer, cmd string, args []string) {
|
||||
plugins := GetInstalledVersions(false)
|
||||
fmt.Fprintln(out, "The following plugins are currently installed:")
|
||||
for _, p := range plugins {
|
||||
fmt.Fprintf(out, "%s (%s)\n", p.Pack().Name, p.Version)
|
||||
if p.Pack().Name == "initlua" {
|
||||
fmt.Fprintf(out, "%s\n", "initlua")
|
||||
} else if p.Pack().Builtin {
|
||||
fmt.Fprintf(out, "%s (built-in)\n", p.Pack().Name)
|
||||
} else {
|
||||
fmt.Fprintf(out, "%s (%s)\n", p.Pack().Name, p.Version)
|
||||
}
|
||||
}
|
||||
case "search":
|
||||
plugins := SearchPlugin(out, args)
|
||||
|
||||
@@ -187,6 +187,7 @@ func InitPlugins() {
|
||||
p.Name = "initlua"
|
||||
p.DirName = "initlua"
|
||||
p.Srcs = append(p.Srcs, realFile(initlua))
|
||||
p.Builtin = false
|
||||
Plugins = append(Plugins, p)
|
||||
}
|
||||
|
||||
@@ -242,7 +243,7 @@ func InitPlugins() {
|
||||
p := new(Plugin)
|
||||
p.Name = d
|
||||
p.DirName = d
|
||||
p.Default = true
|
||||
p.Builtin = true
|
||||
for _, f := range srcs {
|
||||
if strings.HasSuffix(f, ".lua") {
|
||||
p.Srcs = append(p.Srcs, assetFile(filepath.Join(plugdir, d, f)))
|
||||
|
||||
Reference in New Issue
Block a user