From 2328330a58e8ce2a217b5d39cd20c1bbfe8c9055 Mon Sep 17 00:00:00 2001 From: Thomas Bruyelle Date: Sun, 3 Mar 2024 12:47:25 +0100 Subject: [PATCH] chore: handle precompile to transpile rename Related change: https://github.com/gnolang/gno/pull/1681 --- README.md | 2 +- internal/gno/gno.go | 51 +++++++++++++++++++------------------- internal/gno/util.go | 2 +- internal/handler/config.go | 4 +-- 4 files changed, 29 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 7ae7bba..53c20b5 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ that supports the Language Server Protocol. - Real-time precompile & build errors in your Gno files. + Real-time transpile & build errors in your Gno files. Format Gno files with the tool of your choice. diff --git a/internal/gno/gno.go b/internal/gno/gno.go index 08c0309..ce7c76b 100644 --- a/internal/gno/gno.go +++ b/internal/gno/gno.go @@ -27,13 +27,13 @@ var ErrNoGno = errors.New("no gno binary found") // // TODO: Should we install / update our own copy of gno? type BinManager struct { - workspaceFolder string // path to project - gno string // path to gno binary - gnokey string // path to gnokey binary - gopls string // path to gopls binary - root string // path to gno repository - shouldPrecompile bool // whether to precompile on save - shouldBuild bool // whether to build on save + workspaceFolder string // path to project + gno string // path to gno binary + gnokey string // path to gnokey binary + gopls string // path to gopls binary + root string // path to gno repository + shouldTranspile bool // whether to transpile on save + shouldBuild bool // whether to build on save } // BuildError is an error returned by the `gno build` command. @@ -52,11 +52,11 @@ type BuildError struct { // `gnokeyBin`: The path to the `gnokey` binary. // `goplsBin`: The path to the `gopls` binary. // `root`: The path to the `gno` repository -// `precompile`: Whether to precompile Gno files on save. +// `transpile`: Whether to transpile Gno files on save. // `build`: Whether to build Gno files on save. // // NOTE: Unlike `gnoBin`, `gnokeyBin` is optional. -func NewBinManager(workspaceFolder, gnoBin, gnokeyBin, goplsBin, root string, precompile, build bool) (*BinManager, error) { +func NewBinManager(workspaceFolder, gnoBin, gnokeyBin, goplsBin, root string, transpile, build bool) (*BinManager, error) { if gnoBin == "" { var err error gnoBin, err = exec.LookPath("gno") @@ -71,13 +71,13 @@ func NewBinManager(workspaceFolder, gnoBin, gnokeyBin, goplsBin, root string, pr goplsBin, _ = exec.LookPath("gopls") } return &BinManager{ - workspaceFolder: workspaceFolder, - gno: gnoBin, - gnokey: gnokeyBin, - gopls: goplsBin, - root: root, - shouldPrecompile: precompile, - shouldBuild: build, + workspaceFolder: workspaceFolder, + gno: gnoBin, + gnokey: gnokeyBin, + gopls: goplsBin, + root: root, + shouldTranspile: transpile, + shouldBuild: build, }, nil } @@ -100,9 +100,9 @@ func (m *BinManager) Format(gnoFile string) ([]byte, error) { return format.Source([]byte(gnoFile)) } -// Precompile a Gno package: gno precompile . -func (m *BinManager) Precompile() ([]byte, error) { - args := []string{"precompile", m.workspaceFolder} +// Transpile a Gno package: gno transpile . +func (m *BinManager) Transpile() ([]byte, error) { + args := []string{"transpile", m.workspaceFolder} if m.shouldBuild { args = append(args, "-gobuild") } @@ -129,19 +129,18 @@ func (m *BinManager) RunTest(pkg, name string) ([]byte, error) { return cmd.CombinedOutput() } -// Lint precompiles and builds a Gno package and returns any errors. +// Lint transpiles and builds a Gno package and returns any errors. // // In practice, this means: // -// 1. Precompile -// 2. parse the errors -// 3. recompute the offsets (.gen.go -> .gno). +// 1. Transpile +// 2. Parse the errors func (m *BinManager) Lint() ([]BuildError, error) { - if !m.shouldPrecompile && !m.shouldBuild { + if !m.shouldTranspile && !m.shouldBuild { return []BuildError{}, nil } - preOut, _ := m.Precompile() // TODO handle error? - return m.parseErrors(string(preOut), "precompile") + preOut, _ := m.Transpile() // TODO handle error? + return m.parseErrors(string(preOut), "transpile") } type GoplsDefinition struct { diff --git a/internal/gno/util.go b/internal/gno/util.go index 540a7d2..708097c 100644 --- a/internal/gno/util.go +++ b/internal/gno/util.go @@ -16,7 +16,7 @@ import ( // related issue: https://github.com/golang/go/issues/62067 var errorRe = regexp.MustCompile(`(?m)^([^#]+?):(\d+):(\d+):(.+)$`) -// parseErrors parses the output of the `gno precompile -gobuild` command for +// parseErrors parses the output of the `gno transpile -gobuild` command for // errors. // // The format is: diff --git a/internal/handler/config.go b/internal/handler/config.go index 0be47e0..e46e730 100644 --- a/internal/handler/config.go +++ b/internal/handler/config.go @@ -29,11 +29,11 @@ func (h *handler) handleDidChangeConfiguration(ctx context.Context, reply jsonrp gnokeyBin, _ := settings["gnokey"].(string) goplsBin, _ := settings["gopls"].(string) - precompile, _ := settings["precompileOnSave"].(bool) + transpile, _ := settings["transpileOnSave"].(bool) build, _ := settings["buildOnSave"].(bool) root, _ := settings["root"].(string) - h.binManager, err = gno.NewBinManager(h.workspaceFolder, gnoBin, gnokeyBin, goplsBin, root, precompile, build) + h.binManager, err = gno.NewBinManager(h.workspaceFolder, gnoBin, gnokeyBin, goplsBin, root, transpile, build) if err != nil { return replyErr(ctx, reply, err) }