pkg/edit: Fix crash in edit:complete-filename when given no arguments.

This fixes #1799.
This commit is contained in:
Qi Xiao 2024-05-03 14:56:40 +01:00
parent 1aeb2f6e98
commit 57078f79be
3 changed files with 14 additions and 1 deletions

View File

@ -22,6 +22,9 @@ var eachExternal = fsutil.EachExternal
// GenerateFileNames returns filename candidates that are suitable for completing
// the last argument. It can be used in Config.ArgGenerator.
func GenerateFileNames(args []string) ([]RawItem, error) {
if len(args) == 0 {
return nil, nil
}
return generateFileNames(args[len(args)-1], false)
}

View File

@ -1,9 +1,16 @@
//each:complex-candidate-in-global
/////////////////////
# complete-filename #
/////////////////////
//complete-filename-in-global
// Don't crash with no argument. Regression test for b.elv.sh/1799.
~> complete-filename
/////////////////////
# complex-candidate #
/////////////////////
//each:complex-candidate-in-global
## construction ##
~> complex-candidate a/b
▶ (edit:complex-candidate a/b &code-suffix='' &display=[^styled])

View File

@ -4,6 +4,7 @@ import (
"embed"
"testing"
"src.elv.sh/pkg/edit/complete"
"src.elv.sh/pkg/eval"
"src.elv.sh/pkg/eval/evaltest"
)
@ -21,6 +22,8 @@ func TestTranscripts(t *testing.T) {
"binding-map-in-global", fnInGlobal("binding-map", makeBindingMap),
"wordify-in-global", fnInGlobal("wordify", wordify),
"complete-getopt-in-global", fnInGlobal("complete-getopt", completeGetopt),
"complete-filename-in-global", fnInGlobal("complete-filename",
wrapArgGenerator(complete.GenerateFileNames)),
"complex-candidate-in-global", fnInGlobal("complex-candidate", complexCandidate),
"add-var-in-global", fnInGlobal("add-var", addVar),
"add-vars-in-global", fnInGlobal("add-vars", addVars),