@@ -93,32 +93,13 @@ 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 {
98
+ modPath = detectGoModFallback ()
103
99
return ""
104
100
}
105
101
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 )
122
103
if err != nil {
123
104
return ""
124
105
}
@@ -144,3 +125,32 @@ func parseGoMod(goMod string) (*modfile.File, error) {
144
125
145
126
return modfile .Parse ("go.mod" , raw , nil )
146
127
}
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