generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an LSP that produces document highlights when FTL outputs build errors this is a work in progress --------- Co-authored-by: Wes <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
5f11007
commit 812adb7
Showing
8 changed files
with
363 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,37 @@ | ||
package compile | ||
package schema | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"go/ast" | ||
"go/token" | ||
|
||
"github.com/TBD54566975/ftl/backend/schema" | ||
) | ||
|
||
type Error struct { | ||
Msg string | ||
Pos schema.Position | ||
Pos Position | ||
Err error // Wrapped error, if any | ||
} | ||
|
||
func (e Error) Error() string { return fmt.Sprintf("%s: %s", e.Pos, e.Msg) } | ||
func (e Error) Unwrap() error { return e.Err } | ||
|
||
func errorf(pos token.Pos, format string, args ...any) Error { | ||
return Error{Msg: fmt.Sprintf(format, args...), Pos: goPosToSchemaPos(pos)} | ||
func Errorf(pos Position, format string, args ...any) Error { | ||
return Error{Msg: fmt.Sprintf(format, args...), Pos: pos} | ||
} | ||
|
||
func wrapf(node ast.Node, err error, format string, args ...any) Error { | ||
func Wrapf(pos Position, err error, format string, args ...any) Error { | ||
if format == "" { | ||
format = "%s" | ||
} else { | ||
format += ": %s" | ||
} | ||
// Propagate existing error position if available | ||
var pos schema.Position | ||
var newPos Position | ||
if perr := (Error{}); errors.As(err, &perr) { | ||
pos = perr.Pos | ||
newPos = perr.Pos | ||
args = append(args, perr.Msg) | ||
} else { | ||
pos = goPosToSchemaPos(node.Pos()) | ||
newPos = pos | ||
args = append(args, err) | ||
} | ||
return Error{Msg: fmt.Sprintf(format, args...), Pos: pos, Err: err} | ||
return Error{Msg: fmt.Sprintf(format, args...), Pos: newPos, Err: err} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.