Skip to content

Commit

Permalink
Rename precompile to transpile
Browse files Browse the repository at this point in the history
The precompiler has been officially renamed to transpiler (see: [1])

Applied changes here too.

[1]: gnolang/gno@1065217
  • Loading branch information
harry-hov committed Mar 23, 2024
1 parent 255d749 commit feef0a4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
14 changes: 8 additions & 6 deletions internal/lsp/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type ErrorInfo struct {
Tool string
}

func (s *server) PrecompileAndBuild(file *GnoFile) ([]ErrorInfo, error) {
func (s *server) TranspileAndBuild(file *GnoFile) ([]ErrorInfo, error) {
pkgDir := filepath.Dir(file.URI.Filename())
pkgName := filepath.Base(pkgDir)
tmpDir := filepath.Join(s.env.GNOHOME, "gnopls", "tmp", pkgName)
Expand All @@ -30,10 +30,10 @@ func (s *server) PrecompileAndBuild(file *GnoFile) ([]ErrorInfo, error) {
return nil, err
}

preOut, _ := tools.Precompile(tmpDir)
preOut, _ := tools.Transpile(tmpDir)
slog.Info(string(preOut))
if len(preOut) > 0 {
return parseErrors(file, string(preOut), "precompile")
return parseErrors(file, string(preOut), "transpile")
}

buildOut, _ := tools.Build(tmpDir)
Expand Down Expand Up @@ -91,9 +91,11 @@ func parseErrors(file *GnoFile, output, cmd string) ([]ErrorInfo, error) {
// numbers to account for the header information in the generated Go file.
func findError(file *GnoFile, fname string, line, col int, msg string, tool string) ErrorInfo {
msg = strings.TrimSpace(msg)
if tool == "precompile" {
// fname parsed from precompile result can be incorrect
// e.g filename = `filename.gno: precompile: parse: tmp.gno`
// TODO: can be removed?
// see: https://github.com/gnolang/gno/pull/1670
if tool == "transpile" {
// fname parsed from transpile result can be incorrect
// e.g filename = `filename.gno: transpile: parse: tmp.gno`
parts := strings.Split(fname, ":")
fname = parts[0]
}
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func (s *server) publishDiagnostics(ctx context.Context, conn jsonrpc2.Conn, file *GnoFile) error {
slog.Info("Lint", "path", file.URI.Filename())

errors, err := s.PrecompileAndBuild(file)
errors, err := s.TranspileAndBuild(file)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions internal/tools/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"path/filepath"
)

// Build a Gno package: gno precompile -gobuild <dir>.
// TODO: Remove this in the favour of directly using tools/precompile.go
// Build a Gno package: gno transpile -gobuild <dir>.
// TODO: Remove this in the favour of directly using tools/transpile.go
func Build(rootDir string) ([]byte, error) {
return exec.Command("gno", "precompile", "-skip-imports", "-gobuild", filepath.Join(rootDir)).CombinedOutput()
return exec.Command("gno", "transpile", "-skip-imports", "-gobuild", filepath.Join(rootDir)).CombinedOutput()
}
11 changes: 0 additions & 11 deletions internal/tools/precompile.go

This file was deleted.

11 changes: 11 additions & 0 deletions internal/tools/transpile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package tools

import (
"os/exec"
"path/filepath"
)

// Transpile a Gno package: gno transpile <dir>.
func Transpile(rootDir string) ([]byte, error) {
return exec.Command("gno", "transpile", "-skip-imports", filepath.Join(rootDir)).CombinedOutput()
}

0 comments on commit feef0a4

Please sign in to comment.