Skip to content

Commit

Permalink
Fix autocomplete
Browse files Browse the repository at this point in the history
Fix autocomplete
  • Loading branch information
cheikhshift committed Jul 18, 2022
1 parent 203ccb9 commit 7131ee7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 154 deletions.
89 changes: 13 additions & 76 deletions api/handlers/rest_ApiComplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,95 +13,32 @@ import (
"github.com/cheikhshift/gos/core"
"github.com/gorilla/sessions"
"github.com/thestrukture/IDE/api/globals"
"gopkg.in/mgo.v2/bson"
)

//
func ApiComplete(w http.ResponseWriter, r *http.Request, session *sessions.Session) (response string, callmet bool) {

prefx := r.FormValue("pref")

ret := []bson.M{}
//return {name: ea.word, value: ea.insert, score: 0, meta: ea.meta}
gxml := os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml"
content := r.FormValue("content")
id := r.FormValue("id")
tempFile := filepath.Join(globals.AutocompletePath, id)

if _, err := os.Stat(gxml); !os.IsNotExist(err) && r.FormValue("gocode") == "" {
gos, _ := core.PLoadGos(gxml)
score := 0
for _, v := range gos.Variables {
ioutil.WriteFile(tempFile, []byte(content), 0700)
cms := "gocode"

if strings.Contains(v.Name, prefx) {
score = score + 1
ret = append(ret, bson.M{"name": v.Name, "value": v.Name, "score": score, "meta": "Global variable | " + v.Type})
}

}

for _, v := range gos.RootImports {

if strings.Contains(v.Src, prefx) {
score = score + 1
paths := strings.Split(v.Src, "/")
ret = append(ret, bson.M{"name": v.Src, "value": paths[len(paths)-1], "score": score, "meta": "package"})
}

}

for _, v := range gos.Header.Structs {

if strings.Contains(v.Name, prefx) {
score = score + 1
ret = append(ret, bson.M{"name": v.Name, "value": v.Name, "score": score, "meta": "Interface"})
}

}

for _, v := range gos.Header.Objects {

if strings.Contains(v.Name, prefx) {
score = score + 1
ret = append(ret, bson.M{"name": v.Name, "value": v.Name, "score": score, "meta": "{{Interface func group}}"})
}

}

for _, v := range gos.Methods.Methods {

if strings.Contains(v.Name, prefx) {
score = score + 1
ret = append(ret, bson.M{"name": v.Name, "value": v.Name + " ", "score": score, "meta": "{{Template pipeline}}"})
score = score + 1
ret = append(ret, bson.M{"name": v.Name, "value": "net" + v.Name + "(" + v.Variables + ")", "score": score, "meta": "Pipeline go function."})
}

}

for _, v := range gos.Templates.Templates {

if strings.Contains(v.Name, prefx) {
score = score + 1
ret = append(ret, bson.M{"name": v.Name, "value": v.Name + " ", "score": score, "meta": "{{Template $struct}}"})
score = score + 1
ret = append(ret, bson.M{"name": v.Name, "value": "netb" + v.Name + "(" + v.Struct + "{})", "score": score, "meta": "Template build go function."})
}

}

response = mResponse(ret)
} else {
content := r.FormValue("content")
id := r.FormValue("id")
tempFile := filepath.Join(globals.AutocompletePath, id)
if globals.Windows {
cms = strings.Replace(os.ExpandEnv("$GOPATH")+"\\bin\\gocode.exe", "/", "\\", -1)
}

ioutil.WriteFile(tempFile, []byte(content), 0700)
cmd := fmt.Sprintf("gocode -f=json --in=%s autocomplete %s", tempFile, prefx)
cmd := fmt.Sprintf(cms+" -f=json --in=%s autocomplete %s", tempFile, prefx)

res, _ := core.RunCmdSmart(cmd)
response = res
res, err := core.RunCmdSmart(cmd)
response = res

os.Remove(tempFile)


}
os.Remove(tempFile)

callmet = true
return
Expand Down
94 changes: 16 additions & 78 deletions gos.gxml
Original file line number Diff line number Diff line change
Expand Up @@ -2341,89 +2341,27 @@ for _, v := range apps {

prefx := r.FormValue("pref")


content := r.FormValue("content")
id := r.FormValue("id")
tempFile := filepath.Join(autocompletePath, id)

ret := []bson.M{}
//return {name: ea.word, value: ea.insert, score: 0, meta: ea.meta}
gxml := os.ExpandEnv("$GOPATH") + "/src/" + r.FormValue("pkg") + "/gos.gxml"

if _, err := os.Stat(gxml); !os.IsNotExist(err) && r.FormValue("gocode") == "" {
gos,_ := core.PLoadGos(gxml)
score := 0
for _,v := range gos.Variables {

if strings.Contains(v.Name, prefx){
score = score + 1
ret = append(ret, bson.M{"name":v.Name,"value":v.Name,"score":score,"meta":"Global variable | " + v.Type})
}

}

for _,v := range gos.RootImports {

if strings.Contains(v.Src, prefx){
score = score + 1
paths := strings.Split(v.Src,"/")
ret = append(ret, bson.M{"name":v.Src,"value":paths[len(paths) - 1],"score":score,"meta":"package"})
}

}

for _,v := range gos.Header.Structs {

if strings.Contains(v.Name, prefx){
score = score + 1
ret = append(ret, bson.M{"name":v.Name,"value":v.Name ,"score":score,"meta":"Interface"})
}

}

for _,v := range gos.Header.Objects {

if strings.Contains(v.Name, prefx){
score = score + 1
ret = append(ret, bson.M{"name":v.Name,"value":v.Name ,"score":score,"meta":"{{Interface func group}}"})
}

}

for _,v := range gos.Methods.Methods {

if strings.Contains(v.Name, prefx){
score = score + 1
ret = append(ret, bson.M{"name":v.Name,"value":v.Name + " ","score":score,"meta":"{{Template pipeline}}"})
score = score + 1
ret = append(ret, bson.M{"name":v.Name,"value":"net_" + v.Name + "(" + v.Variables +")","score":score,"meta":"Pipeline go function."})
}

}

for _,v := range gos.Templates.Templates {

if strings.Contains(v.Name, prefx){
score = score + 1
ret = append(ret, bson.M{"name":v.Name,"value":v.Name + " ","score":score,"meta":"{{Template $struct}}"})
score = score + 1
ret = append(ret, bson.M{"name":v.Name,"value":"net_b" + v.Name + "(" + v.Struct +"{})","score":score,"meta":"Template build go function."})
}
ioutil.WriteFile(tempFile, []byte(content), 0700)
cms := "gocode"

}

response = mResponse(ret)
} else {
content := r.FormValue("content")
id := r.FormValue("id")
tempFile := filepath.Join(autocompletePath, id)
if Windows {
cms = strings.Replace(os.ExpandEnv("$GOPATH")+"\\bin\\gocode.exe", "/", "\\", -1)

}

ioutil.WriteFile(tempFile, []byte(content), 0700)
cmd := fmt.Sprintf("gocode -f=json --in=%s autocomplete %s", tempFile ,prefx)
cmd := fmt.Sprintf( cms + " -f=json --in=%s autocomplete %s", tempFile ,prefx)

res, _ := core.RunCmdSmart(cmd)
response = res

os.Remove(tempFile)

}
res, err := core.RunCmdSmart(cmd)
response = res



os.Remove(tempFile)

</end>

Expand Down

0 comments on commit 7131ee7

Please sign in to comment.