jsre: fix <tab><tab> completion magic
This commit is contained in:
parent
5542b51b50
commit
f08680985a
@ -55,9 +55,18 @@ func getCompletions(vm *otto.Otto, line string) (results []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// e.g. web3<tab><tab> append dot since its an object
|
|
||||||
if obj, _ = vm.Object(line); obj != nil {
|
// Append opening parenthesis (for functions) or dot (for objects)
|
||||||
results = append(results, line+".")
|
// if the line itself is the only completion.
|
||||||
|
if len(results) == 1 && results[0] == line {
|
||||||
|
obj, _ := vm.Object(line)
|
||||||
|
if obj != nil {
|
||||||
|
if obj.Class() == "Function" {
|
||||||
|
results[0] += "("
|
||||||
|
} else {
|
||||||
|
results[0] += "."
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Strings(results)
|
sort.Strings(results)
|
||||||
|
@ -40,7 +40,11 @@ func TestCompleteKeywords(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
input: "x",
|
input: "x",
|
||||||
want: []string{"x", "x."},
|
want: []string{"x."},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "x.someMethod",
|
||||||
|
want: []string{"x.someMethod("},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
input: "x.",
|
input: "x.",
|
||||||
|
Loading…
Reference in New Issue
Block a user