]> git.lizzy.rs Git - micro.git/blobdiff - internal/action/infocomplete.go
better top
[micro.git] / internal / action / infocomplete.go
index 9179b63b5e8fc433cb7c98b09b80597e7085a477..d6c16cb2fa17df5573ef0e099ff23f57e1a13d02 100644 (file)
@@ -92,17 +92,16 @@ func OptionComplete(b *buffer.Buffer) ([]string, []string) {
        input, argstart := buffer.GetArg(b)
 
        var suggestions []string
-       localSettings := config.DefaultLocalSettings()
        for option := range config.GlobalSettings {
                if strings.HasPrefix(option, input) {
                        suggestions = append(suggestions, option)
                }
        }
-       for option := range localSettings {
-               if strings.HasPrefix(option, input) && !contains(suggestions, option) {
-                       suggestions = append(suggestions, option)
-               }
-       }
+       // for option := range localSettings {
+       //      if strings.HasPrefix(option, input) && !contains(suggestions, option) {
+       //              suggestions = append(suggestions, option)
+       //      }
+       // }
 
        sort.Strings(suggestions)
        completions := make([]string, len(suggestions))
@@ -122,19 +121,19 @@ func OptionValueComplete(b *buffer.Buffer) ([]string, []string) {
        completeValue := false
        args := bytes.Split(l, []byte{' '})
        if len(args) >= 2 {
-               localSettings := config.DefaultLocalSettings()
+               // localSettings := config.DefaultLocalSettings()
                for option := range config.GlobalSettings {
                        if option == string(args[len(args)-2]) {
                                completeValue = true
                                break
                        }
                }
-               for option := range localSettings {
-                       if option == string(args[len(args)-2]) {
-                               completeValue = true
-                               break
-                       }
-               }
+               // for option := range localSettings {
+               //      if option == string(args[len(args)-2]) {
+               //              completeValue = true
+               //              break
+               //      }
+               // }
        }
        if !completeValue {
                return OptionComplete(b)
@@ -144,18 +143,18 @@ func OptionValueComplete(b *buffer.Buffer) ([]string, []string) {
 
        inputOpt = strings.TrimSpace(inputOpt)
        var suggestions []string
-       localSettings := config.DefaultLocalSettings()
+       // localSettings := config.DefaultLocalSettings()
        var optionVal interface{}
        for k, option := range config.GlobalSettings {
                if k == inputOpt {
                        optionVal = option
                }
        }
-       for k, option := range localSettings {
-               if k == inputOpt {
-                       optionVal = option
-               }
-       }
+       // for k, option := range localSettings {
+       //      if k == inputOpt {
+       //              optionVal = option
+       //      }
+       // }
 
        switch optionVal.(type) {
        case bool:
@@ -198,51 +197,84 @@ func OptionValueComplete(b *buffer.Buffer) ([]string, []string) {
        return completions, suggestions
 }
 
-// // MakeCompletion registers a function from a plugin for autocomplete commands
-// func MakeCompletion(function string) Completion {
-//     pluginCompletions = append(pluginCompletions, LuaFunctionComplete(function))
-//     return Completion(-len(pluginCompletions))
-// }
-//
-// // PluginComplete autocompletes from plugin function
-// func PluginComplete(complete Completion, input string) (chosen string, suggestions []string) {
-//     idx := int(-complete) - 1
-//
-//     if len(pluginCompletions) <= idx {
-//             return "", nil
-//     }
-//     suggestions = pluginCompletions[idx](input)
-//
-//     if len(suggestions) == 1 {
-//             chosen = suggestions[0]
-//     }
-//     return
-// }
-//
-// // PluginCmdComplete completes with possible choices for the `> plugin` command
-// func PluginCmdComplete(input string) (chosen string, suggestions []string) {
-//     for _, cmd := range []string{"install", "remove", "search", "update", "list"} {
-//             if strings.HasPrefix(cmd, input) {
-//                     suggestions = append(suggestions, cmd)
-//             }
-//     }
-//
-//     if len(suggestions) == 1 {
-//             chosen = suggestions[0]
-//     }
-//     return chosen, suggestions
-// }
+// PluginCmdComplete autocompletes the plugin command
+func PluginCmdComplete(b *buffer.Buffer) ([]string, []string) {
+       c := b.GetActiveCursor()
+       input, argstart := buffer.GetArg(b)
+
+       var suggestions []string
+       for _, cmd := range PluginCmds {
+               if strings.HasPrefix(cmd, input) {
+                       suggestions = append(suggestions, cmd)
+               }
+       }
+
+       sort.Strings(suggestions)
+       completions := make([]string, len(suggestions))
+       for i := range suggestions {
+               completions[i] = util.SliceEndStr(suggestions[i], c.X-argstart)
+       }
+       return completions, suggestions
+}
+
+// PluginComplete completes values for the plugin command
+func PluginComplete(b *buffer.Buffer) ([]string, []string) {
+       c := b.GetActiveCursor()
+       l := b.LineBytes(c.Y)
+       l = util.SliceStart(l, c.X)
+       input, argstart := buffer.GetArg(b)
+
+       completeValue := false
+       args := bytes.Split(l, []byte{' '})
+       if len(args) >= 2 {
+               for _, cmd := range PluginCmds {
+                       if cmd == string(args[len(args)-2]) {
+                               completeValue = true
+                               break
+                       }
+               }
+       }
+       if !completeValue {
+               return PluginCmdComplete(b)
+       }
+
+       var suggestions []string
+       for _, pl := range config.Plugins {
+               if strings.HasPrefix(pl.Name, input) {
+                       suggestions = append(suggestions, pl.Name)
+               }
+       }
+       sort.Strings(suggestions)
+
+       completions := make([]string, len(suggestions))
+       for i := range suggestions {
+               completions[i] = util.SliceEndStr(suggestions[i], c.X-argstart)
+       }
+       return completions, suggestions
+}
+
+// PluginNameComplete completes with the names of loaded plugins
+// func PluginNameComplete(b *buffer.Buffer) ([]string, []string) {
+//     c := b.GetActiveCursor()
+//     input, argstart := buffer.GetArg(b)
 //
-// // PluginnameComplete completes with the names of loaded plugins
-// func PluginNameComplete(input string) (chosen string, suggestions []string) {
-//     for _, pp := range GetAllPluginPackages() {
+//     var suggestions []string
+//     for _, pp := range config.GetAllPluginPackages(nil) {
 //             if strings.HasPrefix(pp.Name, input) {
 //                     suggestions = append(suggestions, pp.Name)
 //             }
 //     }
 //
-//     if len(suggestions) == 1 {
-//             chosen = suggestions[0]
+//     sort.Strings(suggestions)
+//     completions := make([]string, len(suggestions))
+//     for i := range suggestions {
+//             completions[i] = util.SliceEndStr(suggestions[i], c.X-argstart)
 //     }
-//     return chosen, suggestions
+//     return completions, suggestions
+// }
+
+// // MakeCompletion registers a function from a plugin for autocomplete commands
+// func MakeCompletion(function string) Completion {
+//     pluginCompletions = append(pluginCompletions, LuaFunctionComplete(function))
+//     return Completion(-len(pluginCompletions))
 // }