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
|
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) {
|
func Compile(p string, r io.Reader, opts *CompileOptions) (*d2graph.Graph, *d2target.Config, error) {
|
||||||
if opts == nil {
|
if opts == nil {
|
||||||
opts = &CompileOptions{}
|
opts = &CompileOptions{}
|
||||||
}
|
}
|
||||||
|
|
||||||
lspMode := os.Getenv("D2_LSP_MODE") == "1"
|
|
||||||
defer LspOutput(lspMode)
|
|
||||||
|
|
||||||
ast, err := d2parser.Parse(p, r, &d2parser.ParseOptions{
|
ast, err := d2parser.Parse(p, r, &d2parser.ParseOptions{
|
||||||
UTF16Pos: opts.UTF16Pos,
|
UTF16Pos: opts.UTF16Pos,
|
||||||
})
|
})
|
||||||
|
|
||||||
lod.Ast = ast
|
if os.Getenv("D2_LSP_MODE") == "1" {
|
||||||
if err != nil {
|
jsonOutput, _ := json.Marshal(LspOutputData{Ast: ast, Err: err})
|
||||||
lod.Err = err
|
fmt.Print(string(jsonOutput))
|
||||||
|
os.Exit(42)
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if lspMode {
|
if err != nil {
|
||||||
return nil, nil, nil
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ir, err := d2ir.Compile(ast, &d2ir.CompileOptions{
|
ir, err := d2ir.Compile(ast, &d2ir.CompileOptions{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue