mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vcomplete: improve flag completion, add missdoc (#14415)
This commit is contained in:
parent
ed17779434
commit
8eea861c93
@ -114,7 +114,6 @@ const (
|
||||
'help',
|
||||
'new',
|
||||
'init',
|
||||
'complete',
|
||||
'translate',
|
||||
'self',
|
||||
'search',
|
||||
@ -130,7 +129,12 @@ const (
|
||||
'run',
|
||||
'build',
|
||||
'build-module',
|
||||
'missdoc',
|
||||
]
|
||||
// Entries in the flag arrays below should be entered as is:
|
||||
// * Short flags, e.g.: "-v", should be entered: '-v'
|
||||
// * Long flags, e.g.: "--version", should be entered: '--version'
|
||||
// * Single-dash flags, e.g.: "-version", should be entered: '-version'
|
||||
auto_complete_flags = [
|
||||
'-apk',
|
||||
'-show-timings',
|
||||
@ -228,16 +232,33 @@ const (
|
||||
'--write',
|
||||
]
|
||||
auto_complete_flags_shader = [
|
||||
'help',
|
||||
'h',
|
||||
'force-update',
|
||||
'u',
|
||||
'verbose',
|
||||
'v',
|
||||
'slang',
|
||||
'l',
|
||||
'output',
|
||||
'o',
|
||||
'--help',
|
||||
'-h',
|
||||
'--force-update',
|
||||
'-u',
|
||||
'--verbose',
|
||||
'-v',
|
||||
'--slang',
|
||||
'-l',
|
||||
'--output',
|
||||
'-o',
|
||||
]
|
||||
auto_complete_flags_missdoc = [
|
||||
'--help',
|
||||
'-h',
|
||||
'--tags',
|
||||
'-t',
|
||||
'--deprecated',
|
||||
'-d',
|
||||
'--private',
|
||||
'-p',
|
||||
'--no-line-numbers',
|
||||
'-n',
|
||||
'--exclude',
|
||||
'-e',
|
||||
'--relative-paths',
|
||||
'-r',
|
||||
'--js',
|
||||
]
|
||||
auto_complete_flags_self = [
|
||||
'-prod',
|
||||
@ -372,12 +393,17 @@ fn auto_complete_request(args []string) []string {
|
||||
parent_command = parts[i]
|
||||
break
|
||||
}
|
||||
if part.starts_with('-') { // 'v [subcmd] -<tab>' or 'v [subcmd] --<tab>'-> flags.
|
||||
get_flags := fn (base []string, flag string) []string {
|
||||
if flag.len == 1 { return base
|
||||
} else { return base.filter(it.starts_with(flag))
|
||||
mut results := []string{}
|
||||
for entry in base {
|
||||
if entry.starts_with(flag) {
|
||||
results << entry
|
||||
}
|
||||
}
|
||||
if part.starts_with('-') { // 'v -<tab>' -> flags.
|
||||
return results
|
||||
}
|
||||
|
||||
match parent_command {
|
||||
'bin2v' { // 'v bin2v -<tab>'
|
||||
list = get_flags(auto_complete_flags_bin2v, part)
|
||||
@ -397,6 +423,9 @@ fn auto_complete_request(args []string) []string {
|
||||
'shader' { // 'v shader -<tab>' -> flags.
|
||||
list = get_flags(auto_complete_flags_shader, part)
|
||||
}
|
||||
'missdoc' { // 'v missdoc -<tab>' -> flags.
|
||||
list = get_flags(auto_complete_flags_missdoc, part)
|
||||
}
|
||||
else {
|
||||
for flag in auto_complete_flags {
|
||||
if flag == part {
|
||||
@ -414,6 +443,11 @@ fn auto_complete_request(args []string) []string {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Clear the list if the result is identical to the part examined
|
||||
// (the flag must have already been completed)
|
||||
if list.len == 1 && part == list[0] {
|
||||
list.clear()
|
||||
}
|
||||
} else {
|
||||
match part {
|
||||
'help' { // 'v help <tab>' -> top level commands except "help".
|
||||
|
Loading…
Reference in New Issue
Block a user