@@ -26,6 +26,7 @@ func main() {
26
26
js .Global ().Set ("d2GetObjOrder" , js .FuncOf (jsGetObjOrder ))
27
27
js .Global ().Set ("d2GetRefRanges" , js .FuncOf (jsGetRefRanges ))
28
28
js .Global ().Set ("d2Compile" , js .FuncOf (jsCompile ))
29
+ js .Global ().Set ("d2GetBoardAtPosition" , js .FuncOf (jsGetBoardAtPosition ))
29
30
js .Global ().Set ("d2Parse" , js .FuncOf (jsParse ))
30
31
js .Global ().Set ("d2Encode" , js .FuncOf (jsEncode ))
31
32
js .Global ().Set ("d2Decode" , js .FuncOf (jsDecode ))
@@ -302,3 +303,31 @@ func jsDecode(this js.Value, args []js.Value) interface{} {
302
303
func jsVersion (this js.Value , args []js.Value ) interface {} {
303
304
return version .Version
304
305
}
306
+
307
+ type jsBoardAtPosition struct {
308
+ BoardPath []string `json:"boardPath"`
309
+ Error string `json:"error"`
310
+ }
311
+
312
+ func jsGetBoardAtPosition (this js.Value , args []js.Value ) interface {} {
313
+ dsl := args [0 ].String ()
314
+ line := args [1 ].Int ()
315
+ column := args [2 ].Int ()
316
+
317
+ boardPath , err := d2lsp .GetBoardAtPosition (dsl , d2ast.Position {
318
+ Line : line ,
319
+ Column : column ,
320
+ })
321
+
322
+ if err != nil {
323
+ ret := jsBoardAtPosition {Error : err .Error ()}
324
+ str , _ := json .Marshal (ret )
325
+ return string (str )
326
+ }
327
+
328
+ resp := jsBoardAtPosition {
329
+ BoardPath : boardPath ,
330
+ }
331
+ str , _ := json .Marshal (resp )
332
+ return string (str )
333
+ }
0 commit comments