Skip to content

Commit 3c67852

Browse files
committed
get board at position
1 parent c3814ed commit 3c67852

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

d2js/js.go

+29
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func main() {
2626
js.Global().Set("d2GetObjOrder", js.FuncOf(jsGetObjOrder))
2727
js.Global().Set("d2GetRefRanges", js.FuncOf(jsGetRefRanges))
2828
js.Global().Set("d2Compile", js.FuncOf(jsCompile))
29+
js.Global().Set("d2GetBoardAtPosition", js.FuncOf(jsGetBoardAtPosition))
2930
js.Global().Set("d2Parse", js.FuncOf(jsParse))
3031
js.Global().Set("d2Encode", js.FuncOf(jsEncode))
3132
js.Global().Set("d2Decode", js.FuncOf(jsDecode))
@@ -302,3 +303,31 @@ func jsDecode(this js.Value, args []js.Value) interface{} {
302303
func jsVersion(this js.Value, args []js.Value) interface{} {
303304
return version.Version
304305
}
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

Comments
 (0)