@@ -93,32 +93,13 @@ func detectGoVersion() string {
9393// else it returns `go` version if present,
9494// else it returns empty.
9595func detectGoVersionFromGoMod () string {
96- info , err := gomod .GetModuleInfo ()
97- if err != nil {
98- return ""
99- }
100-
101- wd , err := os .Getwd ()
96+ modPath , err := gomod .GetGoModPath ()
10297 if err != nil {
98+ modPath = detectGoModFallback ()
10399 return ""
104100 }
105101
106- slices .SortFunc (info , func (a , b gomod.ModInfo ) int {
107- return cmp .Compare (len (b .Path ), len (a .Path ))
108- })
109-
110- goMod := info [0 ]
111- for _ , m := range info {
112- if ! strings .HasPrefix (wd , m .Dir ) {
113- continue
114- }
115-
116- goMod = m
117-
118- break
119- }
120-
121- file , err := parseGoMod (goMod .GoMod )
102+ file , err := parseGoMod (modPath )
122103 if err != nil {
123104 return ""
124105 }
@@ -144,3 +125,32 @@ func parseGoMod(goMod string) (*modfile.File, error) {
144125
145126 return modfile .Parse ("go.mod" , raw , nil )
146127}
128+
129+ func detectGoModFallback () string {
130+ info , err := gomod .GetModuleInfo ()
131+ if err != nil {
132+ return ""
133+ }
134+
135+ wd , err := os .Getwd ()
136+ if err != nil {
137+ return ""
138+ }
139+
140+ slices .SortFunc (info , func (a , b gomod.ModInfo ) int {
141+ return cmp .Compare (len (b .Path ), len (a .Path ))
142+ })
143+
144+ goMod := info [0 ]
145+ for _ , m := range info {
146+ if ! strings .HasPrefix (wd , m .Dir ) {
147+ continue
148+ }
149+
150+ goMod = m
151+
152+ break
153+ }
154+
155+ return goMod .GoMod
156+ }
0 commit comments