code: func WorkspaceFor(source string) (*Workspace, error) {
  	gopaths := envOr("GOPATH", build.Default.GOPATH)
  	// We use absolute paths so that in particular on Windows the case gets normalized
  	sourcePath, err := filepath.Abs(source)
  	if err != nil {
  		sourcePath = source
  	}
  	if os.Getenv("GO111MODULE") != "on" { // GOPATH mode
  		for _, gp := range filepath.SplitList(gopaths) {
  			gopath, err := filepath.Abs(gp)
  			if err != nil {
  				gopath = gp
  			}
  			if filepath.HasPrefix(sourcePath, gopath) {
  				return &Workspace{
  					gopath:       gopaths,
  					isModuleMode: false,
  					Path:         gopath,
  				}, nil
  			}
  		}
  	}
  	if os.Getenv("GO111MODULE") != "off" { // Module mode
  		root, _ := findModuleRoot(sourcePath, "", false)
  		if root != "" {
  			return &Workspace{
  				gopath:       gopaths,
  				isModuleMode: true,
  				Path:         root,
  			}, nil
  		}
  	}
  	return nil, fmt.Errorf(`Go source file "%s" not in Go workspace, adjust GOPATH %s or use modules`, source, gopaths)
  }
docs: // WorkspaceFor returns the Go workspace for the given Go source file.