Refactor completion logic (#2061)
This commit is contained in:
1 parent
5e24fd93d2
commit
d60acef469
1 file changed
+55
-30
+55
-30
@@ -5,6 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -325,46 +326,70 @@ func completeCmd(acc []rune) (matches []string, longestAcc []rune) {
|
|||||||
s := string(acc)
|
s := string(acc)
|
||||||
f := tokenize(s)
|
f := tokenize(s)
|
||||||
|
|
||||||
var longest []rune
|
if len(f) == 1 {
|
||||||
|
|
||||||
switch len(f) {
|
|
||||||
case 1:
|
|
||||||
matches, longestAcc = matchCmd(s)
|
matches, longestAcc = matchCmd(s)
|
||||||
case 2:
|
return
|
||||||
switch f[0] {
|
}
|
||||||
case "set":
|
|
||||||
|
longest := []rune(f[len(f)-1])
|
||||||
|
|
||||||
|
switch f[0] {
|
||||||
|
case "set":
|
||||||
|
if len(f) == 2 {
|
||||||
matches, longest = matchWord(f[1], gOptWords)
|
matches, longest = matchWord(f[1], gOptWords)
|
||||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], longest...)
|
break
|
||||||
case "map", "nmap", "vmap", "cmap", "cmd":
|
|
||||||
longestAcc = acc
|
|
||||||
default:
|
|
||||||
matches, longest = matchFile(f[len(f)-1])
|
|
||||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], longest...)
|
|
||||||
}
|
}
|
||||||
case 3:
|
if len(f) != 3 {
|
||||||
switch f[0] {
|
break
|
||||||
case "setlocal":
|
}
|
||||||
matches, longest = matchWord(f[2], gLocalOptWords)
|
switch f[1] {
|
||||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], longest...)
|
case "selmode":
|
||||||
case "map", "nmap", "vmap", "cmap":
|
matches, longest = matchWord(f[2], []string{"all", "dir"})
|
||||||
matches, longest = matchCmd(f[2])
|
case "sortby":
|
||||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], longest...)
|
matches, longest = matchWord(f[2], []string{"natural", "name", "size", "time", "atime", "btime", "ctime", "ext", "custom"})
|
||||||
case "addcustominfo":
|
|
||||||
longestAcc = acc
|
|
||||||
default:
|
default:
|
||||||
matches, longest = matchFile(f[len(f)-1])
|
if slices.Contains(gOptWords, f[1]+"!") {
|
||||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], longest...)
|
matches, longest = matchWord(f[2], []string{"true", "false"})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "setlocal":
|
||||||
|
if len(f) == 2 {
|
||||||
|
matches, longest = matchFile(f[1])
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if len(f) == 3 {
|
||||||
|
matches, longest = matchWord(f[2], gLocalOptWords)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if len(f) != 4 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
switch f[2] {
|
||||||
|
case "sortby":
|
||||||
|
matches, longest = matchWord(f[3], []string{"natural", "name", "size", "time", "atime", "btime", "ctime", "ext", "custom"})
|
||||||
|
default:
|
||||||
|
if slices.Contains(gLocalOptWords, f[2]+"!") {
|
||||||
|
matches, longest = matchWord(f[3], []string{"true", "false"})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case "map", "nmap", "vmap", "cmap":
|
||||||
|
if len(f) == 3 {
|
||||||
|
matches, longest = matchCmd(f[2])
|
||||||
|
}
|
||||||
|
case "cmd":
|
||||||
|
case "toggle":
|
||||||
|
matches, longest = matchFile(f[len(f)-1])
|
||||||
|
case "cd", "select", "source":
|
||||||
|
if len(f) == 2 {
|
||||||
|
matches, longest = matchFile(f[1])
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
switch f[0] {
|
if !slices.Contains(gCmdWords, f[0]) {
|
||||||
case "set", "setlocal", "map", "nmap", "vmap", "cmap", "cmd":
|
|
||||||
longestAcc = acc
|
|
||||||
default:
|
|
||||||
matches, longest = matchFile(f[len(f)-1])
|
matches, longest = matchFile(f[len(f)-1])
|
||||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], longest...)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], longest...)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user