@@ -93,32 +93,15 @@ func detectGoVersion() string {
93
93
// else it returns `go` version if present,
94
94
// else it returns empty.
95
95
func 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 ()
102
97
if err != nil {
103
- return ""
104
- }
105
-
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
98
+ modPath = detectGoModFallback ()
99
+ if modPath == "" {
100
+ return ""
114
101
}
115
-
116
- goMod = m
117
-
118
- break
119
102
}
120
103
121
- file , err := parseGoMod (goMod . GoMod )
104
+ file , err := parseGoMod (modPath )
122
105
if err != nil {
123
106
return ""
124
107
}
@@ -144,3 +127,32 @@ func parseGoMod(goMod string) (*modfile.File, error) {
144
127
145
128
return modfile .Parse ("go.mod" , raw , nil )
146
129
}
130
+
131
+ func detectGoModFallback () string {
132
+ info , err := gomod .GetModuleInfo ()
133
+ if err != nil {
134
+ return ""
135
+ }
136
+
137
+ wd , err := os .Getwd ()
138
+ if err != nil {
139
+ return ""
140
+ }
141
+
142
+ slices .SortFunc (info , func (a , b gomod.ModInfo ) int {
143
+ return cmp .Compare (len (b .Path ), len (a .Path ))
144
+ })
145
+
146
+ goMod := info [0 ]
147
+ for _ , m := range info {
148
+ if ! strings .HasPrefix (wd , m .Dir ) {
149
+ continue
150
+ }
151
+
152
+ goMod = m
153
+
154
+ break
155
+ }
156
+
157
+ return goMod .GoMod
158
+ }
0 commit comments