Skip to content

Commit 6d1a7fa

Browse files
committed
internal/imports: handle out of range panic in modInfo
Fixes golang/vscode-go#882 Change-Id: If238f61be5653c159293a811bf9728029701de48 Reviewed-on: https://go-review.googlesource.com/c/tools/+/267125 Trust: Rebecca Stambler <rstambler@golang.org> Run-TryBot: Rebecca Stambler <rstambler@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
1 parent 7ad286a commit 6d1a7fa

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

internal/imports/mod.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,11 @@ func (r *ModuleResolver) modInfo(dir string) (modDir string, modName string) {
347347
}
348348

349349
if r.dirInModuleCache(dir) {
350-
matches := modCacheRegexp.FindStringSubmatch(dir)
351-
index := strings.Index(dir, matches[1]+"@"+matches[2])
352-
modDir := filepath.Join(dir[:index], matches[1]+"@"+matches[2])
353-
return modDir, readModName(filepath.Join(modDir, "go.mod"))
350+
if matches := modCacheRegexp.FindStringSubmatch(dir); len(matches) == 3 {
351+
index := strings.Index(dir, matches[1]+"@"+matches[2])
352+
modDir := filepath.Join(dir[:index], matches[1]+"@"+matches[2])
353+
return modDir, readModName(filepath.Join(modDir, "go.mod"))
354+
}
354355
}
355356
for {
356357
if info, ok := r.cacheLoad(dir); ok {

0 commit comments

Comments
 (0)