Skip to content

Commit f086809

Browse files
committed
jsre: fix <tab><tab> completion magic
1 parent 5542b51 commit f086809

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

‎jsre/completion.go‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,18 @@ func getCompletions(vm *otto.Otto, line string) (results []string) {
5555
}
5656
}
5757
})
58-
// e.g. web3<tab><tab> append dot since its an object
59-
if obj, _ = vm.Object(line); obj != nil {
60-
results = append(results, line+".")
58+
59+
// Append opening parenthesis (for functions) or dot (for objects)
60+
// if the line itself is the only completion.
61+
if len(results) == 1 && results[0] == line {
62+
obj, _ := vm.Object(line)
63+
if obj != nil {
64+
if obj.Class() == "Function" {
65+
results[0] += "("
66+
} else {
67+
results[0] += "."
68+
}
69+
}
6170
}
6271

6372
sort.Strings(results)

‎jsre/completion_test.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ func TestCompleteKeywords(t *testing.T) {
4040
}{
4141
{
4242
input: "x",
43-
want: []string{"x", "x."},
43+
want: []string{"x."},
44+
},
45+
{
46+
input: "x.someMethod",
47+
want: []string{"x.someMethod("},
4448
},
4549
{
4650
input: "x.",

0 commit comments

Comments
 (0)