Skip to content

Commit

Permalink
chore: handle precompile to transpile rename
Browse files Browse the repository at this point in the history
Related change: gnolang/gno#1681
  • Loading branch information
tbruyelle committed Mar 3, 2024
1 parent 1deaccb commit 2328330
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ that supports the Language Server Protocol.
</tr>
<tr>
<td width="50%">
Real-time precompile & build errors in your Gno files.
Real-time transpile & build errors in your Gno files.
</td>
<td width="50%">
Format Gno files with the tool of your choice.
Expand Down
51 changes: 25 additions & 26 deletions internal/gno/gno.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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")
Expand All @@ -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
}

Expand All @@ -100,9 +100,9 @@ func (m *BinManager) Format(gnoFile string) ([]byte, error) {
return format.Source([]byte(gnoFile))
}

// Precompile a Gno package: gno precompile <m.workspaceFolder>.
func (m *BinManager) Precompile() ([]byte, error) {
args := []string{"precompile", m.workspaceFolder}
// Transpile a Gno package: gno transpile <m.workspaceFolder>.
func (m *BinManager) Transpile() ([]byte, error) {
args := []string{"transpile", m.workspaceFolder}
if m.shouldBuild {
args = append(args, "-gobuild")
}
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/gno/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions internal/handler/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 2328330

Please sign in to comment.