@@ -13,95 +13,32 @@ import (
1313 "github.com/cheikhshift/gos/core"
1414 "github.com/gorilla/sessions"
1515 "github.com/thestrukture/IDE/api/globals"
16- "gopkg.in/mgo.v2/bson"
1716)
1817
1918//
2019func ApiComplete (w http.ResponseWriter , r * http.Request , session * sessions.Session ) (response string , callmet bool ) {
2120
2221 prefx := r .FormValue ("pref" )
2322
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 )
2726
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"
3229
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+ }
9533
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 )
9835
99- res , _ := core .RunCmdSmart (cmd )
100- response = res
36+ res , err := core .RunCmdSmart (cmd )
37+ response = res
10138
102- os . Remove ( tempFile )
39+
10340
104- }
41+ os . Remove ( tempFile )
10542
10643 callmet = true
10744 return
0 commit comments