Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
Fix parsing precompile error
Browse files Browse the repository at this point in the history
  • Loading branch information
harry-hov committed Sep 22, 2023
1 parent 8ef90b4 commit a0be304
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions internal/lsp/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (s *server) PrecompileAndBuild(file *GnoFile) ([]ErrorInfo, error) {
}

preOut, _ := tools.Precompile(tmpDir)
slog.Info(string(preOut))
if len(preOut) > 0 {
return parseErrors(file, string(preOut), "precompile")
}
Expand Down Expand Up @@ -90,6 +91,12 @@ 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`
parts := strings.Split(fname, ":")
fname = parts[0]
}

// Error messages are of the form:
//
Expand All @@ -101,10 +108,13 @@ func findError(file *GnoFile, fname string, line, col int, msg string, tool stri
needle := parens.ReplaceAllString(msg, "")
tokens := strings.Fields(needle)

// The generated Go file has 4 lines of header information.
//
// +1 for zero-indexing.
shiftedLine := line - 4
shiftedLine := line
if tool == "build" {
// The generated Go file has 4 lines of header information.
//
// +1 for zero-indexing.
shiftedLine = line - 4
}

errorInfo := ErrorInfo{
FileName: strings.TrimPrefix(GoToGnoFileName(filepath.Base(fname)), "."),
Expand Down

0 comments on commit a0be304

Please sign in to comment.