@@ -13,95 +13,32 @@ import (
13
13
"github.com/cheikhshift/gos/core"
14
14
"github.com/gorilla/sessions"
15
15
"github.com/thestrukture/IDE/api/globals"
16
- "gopkg.in/mgo.v2/bson"
17
16
)
18
17
19
18
//
20
19
func ApiComplete (w http.ResponseWriter , r * http.Request , session * sessions.Session ) (response string , callmet bool ) {
21
20
22
21
prefx := r .FormValue ("pref" )
23
22
24
- ret := []bson. M {}
25
- //return {name: ea.word, value: ea.insert, score: 0, meta: ea.meta}
26
- gxml := os . ExpandEnv ( "$GOPATH" ) + "/src/" + r . FormValue ( "pkg" ) + "/gos.gxml"
23
+ content := r . FormValue ( "content" )
24
+ id := r . FormValue ( "id" )
25
+ tempFile := filepath . Join ( globals . AutocompletePath , id )
27
26
28
- if _ , err := os .Stat (gxml ); ! os .IsNotExist (err ) && r .FormValue ("gocode" ) == "" {
29
- gos , _ := core .PLoadGos (gxml )
30
- score := 0
31
- for _ , v := range gos .Variables {
27
+ ioutil .WriteFile (tempFile , []byte (content ), 0700 )
28
+ cms := "gocode"
32
29
33
- if strings .Contains (v .Name , prefx ) {
34
- score = score + 1
35
- ret = append (ret , bson.M {"name" : v .Name , "value" : v .Name , "score" : score , "meta" : "Global variable | " + v .Type })
36
- }
37
-
38
- }
39
-
40
- for _ , v := range gos .RootImports {
41
-
42
- if strings .Contains (v .Src , prefx ) {
43
- score = score + 1
44
- paths := strings .Split (v .Src , "/" )
45
- ret = append (ret , bson.M {"name" : v .Src , "value" : paths [len (paths )- 1 ], "score" : score , "meta" : "package" })
46
- }
47
-
48
- }
49
-
50
- for _ , v := range gos .Header .Structs {
51
-
52
- if strings .Contains (v .Name , prefx ) {
53
- score = score + 1
54
- ret = append (ret , bson.M {"name" : v .Name , "value" : v .Name , "score" : score , "meta" : "Interface" })
55
- }
56
-
57
- }
58
-
59
- for _ , v := range gos .Header .Objects {
60
-
61
- if strings .Contains (v .Name , prefx ) {
62
- score = score + 1
63
- ret = append (ret , bson.M {"name" : v .Name , "value" : v .Name , "score" : score , "meta" : "{{Interface func group}}" })
64
- }
65
-
66
- }
67
-
68
- for _ , v := range gos .Methods .Methods {
69
-
70
- if strings .Contains (v .Name , prefx ) {
71
- score = score + 1
72
- ret = append (ret , bson.M {"name" : v .Name , "value" : v .Name + " " , "score" : score , "meta" : "{{Template pipeline}}" })
73
- score = score + 1
74
- ret = append (ret , bson.M {"name" : v .Name , "value" : "net" + v .Name + "(" + v .Variables + ")" , "score" : score , "meta" : "Pipeline go function." })
75
- }
76
-
77
- }
78
-
79
- for _ , v := range gos .Templates .Templates {
80
-
81
- if strings .Contains (v .Name , prefx ) {
82
- score = score + 1
83
- ret = append (ret , bson.M {"name" : v .Name , "value" : v .Name + " " , "score" : score , "meta" : "{{Template $struct}}" })
84
- score = score + 1
85
- ret = append (ret , bson.M {"name" : v .Name , "value" : "netb" + v .Name + "(" + v .Struct + "{})" , "score" : score , "meta" : "Template build go function." })
86
- }
87
-
88
- }
89
-
90
- response = mResponse (ret )
91
- } else {
92
- content := r .FormValue ("content" )
93
- id := r .FormValue ("id" )
94
- tempFile := filepath .Join (globals .AutocompletePath , id )
30
+ if globals .Windows {
31
+ cms = strings .Replace (os .ExpandEnv ("$GOPATH" )+ "\\ bin\\ gocode.exe" , "/" , "\\ " , - 1 )
32
+ }
95
33
96
- ioutil .WriteFile (tempFile , []byte (content ), 0700 )
97
- cmd := fmt .Sprintf ("gocode -f=json --in=%s autocomplete %s" , tempFile , prefx )
34
+ cmd := fmt .Sprintf (cms + " -f=json --in=%s autocomplete %s" , tempFile , prefx )
98
35
99
- res , _ := core .RunCmdSmart (cmd )
100
- response = res
36
+ res , err := core .RunCmdSmart (cmd )
37
+ response = res
101
38
102
- os . Remove ( tempFile )
39
+
103
40
104
- }
41
+ os . Remove ( tempFile )
105
42
106
43
callmet = true
107
44
return
0 commit comments