vcomplete: improve flag completion, add missdoc (#14415)

Larpon 2022-05-18 07:50:32 +02:00 committed by Jef Roosens
parent 3bae3a23df
commit c5d93afdc1
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
1 changed files with 59 additions and 25 deletions

View File

@ -76,7 +76,7 @@ SUBCMD:
// Snooped from cmd/v/v.v, vlib/v/pref/pref.v // Snooped from cmd/v/v.v, vlib/v/pref/pref.v
const ( const (
auto_complete_commands = [ auto_complete_commands = [
// simple_cmd // simple_cmd
'ast', 'ast',
'doc', 'doc',
@ -114,7 +114,6 @@ const (
'help', 'help',
'new', 'new',
'init', 'init',
'complete',
'translate', 'translate',
'self', 'self',
'search', 'search',
@ -130,8 +129,13 @@ const (
'run', 'run',
'build', 'build',
'build-module', 'build-module',
'missdoc',
] ]
auto_complete_flags = [ // 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', '-apk',
'-show-timings', '-show-timings',
'-check-syntax', '-check-syntax',
@ -190,7 +194,7 @@ const (
'-version', '-version',
'--version', '--version',
] ]
auto_complete_flags_doc = [ auto_complete_flags_doc = [
'-all', '-all',
'-f', '-f',
'-h', '-h',
@ -209,7 +213,7 @@ const (
'-s', '-s',
'-l', '-l',
] ]
auto_complete_flags_fmt = [ auto_complete_flags_fmt = [
'-c', '-c',
'-diff', '-diff',
'-l', '-l',
@ -217,7 +221,7 @@ const (
'-debug', '-debug',
'-verify', '-verify',
] ]
auto_complete_flags_bin2v = [ auto_complete_flags_bin2v = [
'-h', '-h',
'--help', '--help',
'-m', '-m',
@ -227,22 +231,39 @@ const (
'-w', '-w',
'--write', '--write',
] ]
auto_complete_flags_shader = [ auto_complete_flags_shader = [
'help', '--help',
'h', '-h',
'force-update', '--force-update',
'u', '-u',
'verbose', '--verbose',
'v', '-v',
'slang', '--slang',
'l', '-l',
'output', '--output',
'o', '-o',
] ]
auto_complete_flags_self = [ 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', '-prod',
] ]
auto_complete_compilers = [ auto_complete_compilers = [
'cc', 'cc',
'gcc', 'gcc',
'tcc', 'tcc',
@ -372,12 +393,17 @@ fn auto_complete_request(args []string) []string {
parent_command = parts[i] parent_command = parts[i]
break break
} }
get_flags := fn (base []string, flag string) []string { if part.starts_with('-') { // 'v [subcmd] -<tab>' or 'v [subcmd] --<tab>'-> flags.
if flag.len == 1 { return base get_flags := fn (base []string, flag string) []string {
} else { return base.filter(it.starts_with(flag)) mut results := []string{}
} for entry in base {
} if entry.starts_with(flag) {
if part.starts_with('-') { // 'v -<tab>' -> flags. results << entry
}
}
return results
}
match parent_command { match parent_command {
'bin2v' { // 'v bin2v -<tab>' 'bin2v' { // 'v bin2v -<tab>'
list = get_flags(auto_complete_flags_bin2v, part) list = get_flags(auto_complete_flags_bin2v, part)
@ -397,6 +423,9 @@ fn auto_complete_request(args []string) []string {
'shader' { // 'v shader -<tab>' -> flags. 'shader' { // 'v shader -<tab>' -> flags.
list = get_flags(auto_complete_flags_shader, part) list = get_flags(auto_complete_flags_shader, part)
} }
'missdoc' { // 'v missdoc -<tab>' -> flags.
list = get_flags(auto_complete_flags_missdoc, part)
}
else { else {
for flag in auto_complete_flags { for flag in auto_complete_flags {
if flag == part { 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 { } else {
match part { match part {
'help' { // 'v help <tab>' -> top level commands except "help". 'help' { // 'v help <tab>' -> top level commands except "help".