------------------------------------------------------------------------- server_* functions Corresponding client_* functions are autogenerated by goremote. -------------------------------------------------------------------------
(file []byte, filename string, cursor int, context_packed go_build_context)
| 132 | //------------------------------------------------------------------------- |
| 133 | |
| 134 | func server_auto_complete(file []byte, filename string, cursor int, context_packed go_build_context) (c []candidate, d int) { |
| 135 | context := unpack_build_context(&context_packed) |
| 136 | defer func() { |
| 137 | if err := recover(); err != nil { |
| 138 | print_backtrace(err) |
| 139 | c = []candidate{ |
| 140 | {"PANIC", "PANIC", decl_invalid, "panic"}, |
| 141 | } |
| 142 | |
| 143 | // drop cache |
| 144 | g_daemon.drop_cache() |
| 145 | } |
| 146 | }() |
| 147 | // TODO: Probably we don't care about comparing all the fields, checking GOROOT and GOPATH |
| 148 | // should be enough. |
| 149 | if !reflect.DeepEqual(g_daemon.context.Context, context.Context) { |
| 150 | g_daemon.context = context |
| 151 | g_daemon.drop_cache() |
| 152 | } |
| 153 | switch g_config.PackageLookupMode { |
| 154 | case "bzl": |
| 155 | // when package lookup mode is bzl, we set GOPATH to "" explicitly and |
| 156 | // BzlProjectRoot becomes valid (or empty) |
| 157 | var err error |
| 158 | g_daemon.context.GOPATH = "" |
| 159 | g_daemon.context.BzlProjectRoot, err = find_bzl_project_root(g_config.LibPath, filename) |
| 160 | if *g_debug && err != nil { |
| 161 | log.Printf("Bzl project root not found: %s", err) |
| 162 | } |
| 163 | case "gb": |
| 164 | // when package lookup mode is gb, we set GOPATH to "" explicitly and |
| 165 | // GBProjectRoot becomes valid (or empty) |
| 166 | var err error |
| 167 | g_daemon.context.GOPATH = "" |
| 168 | g_daemon.context.GBProjectRoot, err = find_gb_project_root(filename) |
| 169 | if *g_debug && err != nil { |
| 170 | log.Printf("Gb project root not found: %s", err) |
| 171 | } |
| 172 | case "go": |
| 173 | // get current package path for GO15VENDOREXPERIMENT hack |
| 174 | g_daemon.context.CurrentPackagePath = "" |
| 175 | pkg, err := g_daemon.context.ImportDir(filepath.Dir(filename), build.FindOnly) |
| 176 | if err == nil { |
| 177 | if *g_debug { |
| 178 | log.Printf("Go project path: %s", pkg.ImportPath) |
| 179 | } |
| 180 | g_daemon.context.CurrentPackagePath = pkg.ImportPath |
| 181 | } else if *g_debug { |
| 182 | log.Printf("Go project path not found: %s", err) |
| 183 | } |
| 184 | } |
| 185 | if *g_debug { |
| 186 | var buf bytes.Buffer |
| 187 | log.Printf("Got autocompletion request for '%s'\n", filename) |
| 188 | log.Printf("Cursor at: %d\n", cursor) |
| 189 | if cursor > len(file) || cursor < 0 { |
| 190 | log.Println("ERROR! Cursor is outside of the boundaries of the buffer, " + |
| 191 | "this is most likely a text editor plugin bug. Text editor is responsible " + |
no test coverage detected