Update d2compiler/compile.go
Co-authored-by: gavin-ts <85081687+gavin-ts@users.noreply.github.com>
This commit is contained in:
parent
9b463d5c9f
commit
1c4d076812
1 changed files with 6 additions and 20 deletions
|
|
@ -35,38 +35,24 @@ type LspOutputData struct {
|
|||
Err error
|
||||
}
|
||||
|
||||
var lod LspOutputData
|
||||
|
||||
func LspOutput(m bool) {
|
||||
if !m {
|
||||
return
|
||||
}
|
||||
|
||||
jsonOutput, _ := json.Marshal(lod)
|
||||
fmt.Print(string(jsonOutput))
|
||||
os.Exit(42)
|
||||
}
|
||||
|
||||
func Compile(p string, r io.Reader, opts *CompileOptions) (*d2graph.Graph, *d2target.Config, error) {
|
||||
if opts == nil {
|
||||
opts = &CompileOptions{}
|
||||
}
|
||||
|
||||
lspMode := os.Getenv("D2_LSP_MODE") == "1"
|
||||
defer LspOutput(lspMode)
|
||||
|
||||
ast, err := d2parser.Parse(p, r, &d2parser.ParseOptions{
|
||||
UTF16Pos: opts.UTF16Pos,
|
||||
})
|
||||
|
||||
lod.Ast = ast
|
||||
if err != nil {
|
||||
lod.Err = err
|
||||
if os.Getenv("D2_LSP_MODE") == "1" {
|
||||
jsonOutput, _ := json.Marshal(LspOutputData{Ast: ast, Err: err})
|
||||
fmt.Print(string(jsonOutput))
|
||||
os.Exit(42)
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if lspMode {
|
||||
return nil, nil, nil
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
ir, err := d2ir.Compile(ast, &d2ir.CompileOptions{
|
||||
|
|
|
|||
Loading…
Reference in a new issue