@@ -240,6 +240,13 @@ func addNeededOverlayPackages(cfg *Config, driver driver, response *responseDedu
240
240
}
241
241
242
242
func runContainsQueries (cfg * Config , driver driver , response * responseDeduper , queries []string , rootDirs func () map [string ]string ) error {
243
+ go111ModuleOff := false
244
+ for i := range cfg .Env {
245
+ if cfg .Env [len (cfg .Env )- i - 1 ] == "GO111MODULE=off" {
246
+ go111ModuleOff = true
247
+ break
248
+ }
249
+ }
243
250
for _ , query := range queries {
244
251
// TODO(matloob): Do only one query per directory.
245
252
fdir := filepath .Dir (query )
@@ -249,6 +256,14 @@ func runContainsQueries(cfg *Config, driver driver, response *responseDeduper, q
249
256
if err != nil {
250
257
return fmt .Errorf ("could not determine absolute path of file= query path %q: %v" , query , err )
251
258
}
259
+ if go111ModuleOff {
260
+ // Given that langserver converts the repos to modules explicitly, 'go list' has no idea where to find the
261
+ // packages with 'GO111MODULE=off'. Setting the list pattern to relative local import will guide 'go list'
262
+ // to find the part of the packages inside current repo.
263
+ if dir , err := filepath .Rel (cfg .Dir , fdir ); err == nil {
264
+ pattern = "." + string (filepath .Separator ) + dir
265
+ }
266
+ }
252
267
dirResponse , err := driver (cfg , pattern )
253
268
if err != nil || (len (dirResponse .Packages ) == 1 && len (dirResponse .Packages [0 ].Errors ) == 1 ) {
254
269
// There was an error loading the package. Try to load the file as an ad-hoc package.
0 commit comments