9
9
"os"
10
10
"path/filepath"
11
11
"strconv"
12
+ "strings"
12
13
"time"
13
14
"unicode/utf8"
14
15
)
@@ -37,11 +38,8 @@ func filterOutShebang(data []byte) ([]byte, int) {
37
38
// Formatter interfaces
38
39
//-------------------------------------------------------------------------
39
40
40
- type FormatterEmpty interface {
41
+ type Formatter interface {
41
42
WriteEmpty ()
42
- }
43
-
44
- type FormatterCandidates interface {
45
43
WriteCandidates (names , types , classes []string , num int )
46
44
}
47
45
@@ -82,7 +80,7 @@ func (*VimFormatter) WriteCandidates(names, types, classes []string, num int) {
82
80
word := names [i ]
83
81
if classes [i ] == "func" {
84
82
word += "("
85
- if len (types [i ]) == 6 {
83
+ if strings . HasPrefix (types [i ], "func()" ) {
86
84
word += ")"
87
85
}
88
86
}
@@ -106,6 +104,9 @@ func (*VimFormatter) WriteCandidates(names, types, classes []string, num int) {
106
104
107
105
type EmacsFormatter struct {}
108
106
107
+ func (* EmacsFormatter ) WriteEmpty () {
108
+ }
109
+
109
110
func (* EmacsFormatter ) WriteCandidates (names , types , classes []string , num int ) {
110
111
for i := 0 ; i < len (names ); i ++ {
111
112
name := names [i ]
@@ -123,6 +124,9 @@ func (*EmacsFormatter) WriteCandidates(names, types, classes []string, num int)
123
124
124
125
type CSVFormatter struct {}
125
126
127
+ func (* CSVFormatter ) WriteEmpty () {
128
+ }
129
+
126
130
func (* CSVFormatter ) WriteCandidates (names , types , classes []string , num int ) {
127
131
for i := 0 ; i < len (names ); i ++ {
128
132
fmt .Printf ("%s,,%s,,%s\n " , classes [i ], names [i ], types [i ])
@@ -153,7 +157,7 @@ func (*JSONFormatter) WriteCandidates(names, types, classes []string, num int) {
153
157
154
158
//-------------------------------------------------------------------------
155
159
156
- func getFormatter () interface {} {
160
+ func getFormatter () Formatter {
157
161
switch * format {
158
162
case "vim" :
159
163
return new (VimFormatter )
@@ -260,15 +264,10 @@ func cmdAutoComplete(c *rpc.Client) {
260
264
formatter := getFormatter ()
261
265
names , types , classes , partial := Client_AutoComplete (c , file , filename , cursor )
262
266
if names == nil {
263
- if f , ok := formatter .(FormatterEmpty ); ok {
264
- f .WriteEmpty ()
265
- }
267
+ formatter .WriteEmpty ()
266
268
return
267
269
}
268
-
269
- if f , ok := formatter .(FormatterCandidates ); ok {
270
- f .WriteCandidates (names , types , classes , partial )
271
- }
270
+ formatter .WriteCandidates (names , types , classes , partial )
272
271
}
273
272
274
273
func cmdClose (c * rpc.Client ) {
0 commit comments