@@ -15,6 +15,7 @@ package main
15
15
import (
16
16
"bytes"
17
17
"encoding/json"
18
+ "errors"
18
19
"flag"
19
20
"fmt"
20
21
"io"
@@ -23,6 +24,7 @@ import (
23
24
"os"
24
25
"os/exec"
25
26
"path/filepath"
27
+ "regexp"
26
28
"sort"
27
29
"strings"
28
30
@@ -235,6 +237,12 @@ func main() {
235
237
if err != nil {
236
238
log .Fatal (err )
237
239
}
240
+ // Due to https://github.com/golang/vscode-go/issues/1682, we cannot use
241
+ // pseudo-version as the pinned version reliably.
242
+ dlvRevOrStable := dlvVersion .Version
243
+ if rev , err := pseudoVersionRev (dlvVersion .Version ); err == nil { // pseudo-version
244
+ dlvRevOrStable = rev
245
+ }
238
246
239
247
// Check for the latest gopls version.
240
248
versions , err := listAllModuleVersions ("golang.org/x/tools/gopls" )
@@ -269,7 +277,7 @@ func main() {
269
277
}
270
278
271
279
// TODO(suzmue): change input to json and avoid magic string printing.
272
- toolsString := fmt .Sprintf (string (data ), goplsVersion .Version , goplsVersion .Time [:len ("YYYY-MM-DD" )], goplsVersionPre .Version , goplsVersionPre .Time [:len ("YYYY-MM-DD" )], dlvVersion .Version , dlvVersion .Time [:len ("YYYY-MM-DD" )])
280
+ toolsString := fmt .Sprintf (string (data ), goplsVersion .Version , goplsVersion .Time [:len ("YYYY-MM-DD" )], goplsVersionPre .Version , goplsVersionPre .Time [:len ("YYYY-MM-DD" )], dlvRevOrStable , dlvVersion .Version , dlvVersion .Time [:len ("YYYY-MM-DD" )])
273
281
274
282
// Write tools section.
275
283
b .WriteString (toolsString )
@@ -685,3 +693,19 @@ func describeDebugProperty(p *Property) string {
685
693
}
686
694
return b .String ()
687
695
}
696
+
697
+ // pseudoVersionRev extracts the revision info if the given version is pseudo version.
698
+ // We wanted to use golang.org/x/mod/module.PseudoVersionRev, but couldn't due to
699
+ // an error in the CI. This is a workaround.
700
+ //
701
+ // It assumes the version string came from the proxy, so a valid, canonical version
702
+ // string. Thus, the check for pseudoversion is not as robust as golang.org/x/mod/module
703
+ // offers.
704
+ func pseudoVersionRev (ver string ) (rev string , _ error ) {
705
+ var pseudoVersionRE = regexp .MustCompile (`^v[0-9]+\.(0\.0-|\d+\.\d+-([^+]*\.)?0\.)\d{14}-[A-Za-z0-9]+(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$` )
706
+ if strings .Count (ver , "-" ) < 2 || ! pseudoVersionRE .MatchString (ver ) {
707
+ return "" , errors .New ("not a pseudo version" )
708
+ }
709
+ j := strings .LastIndex (ver , "-" )
710
+ return ver [j + 1 :], nil
711
+ }
0 commit comments