Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/config/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 24 additions & 9 deletions internal/config/plugin_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type PluginPackage struct {
Author string
Tags []string
Versions PluginVersions
Builtin bool
}

// PluginPackages is a list of PluginPackage instances.
Expand Down Expand Up @@ -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: ")
Expand Down Expand Up @@ -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 {
Expand All @@ -343,7 +347,8 @@ func newStaticPluginVersion(name, version string) *PluginVersion {
}
}
pl := &PluginPackage{
Name: name,
Name: name,
Builtin: builtin,
}
pv := &PluginVersion{
pack: pl,
Expand All @@ -358,15 +363,15 @@ 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 {
if !p.IsLoaded() {
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)
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if this is initlua?

Although, this part is already buggy without this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I have just updated initlua to be builtin then, should error out now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, is it built-in or not built-in?

We are introducing mess where we could easily avoid it? For example, we could just add an explicit check for "initlua"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Copy link
Collaborator

@JoeKar JoeKar Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It neither is built-in nor has a version, so we shouldn't show either?

Actually I was thinking the same, but it has an advantage to print its presence:
You see that there might be one more callback routine affecting micro's behavior.

This we can then request directly within the issue template (when we use the new GitHub template mechanism after micro's move).

Copy link
Contributor Author

@Neko-Box-Coder Neko-Box-Coder Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It neither is built-in nor has a version, so we shouldn't show either?

Actually I was thinking the same, but it has an advantage to print its presence: You see that there might be one more callback routine affecting micro's behavior.

I thought @dmaluka meant only the version (bracketed) text. If @dmaluka meant the whole entry like you said then I agree with you @JoeKar , I would prefer it being shown and not hidden away from the user.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I meant only the bracketed text.

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 {
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion internal/config/rtfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)))
Expand Down
Loading