From 387f42f1ff856607e70d202b3efdfbf5ba458919 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 17 Oct 2024 09:04:11 -0600 Subject: [PATCH] update lsp --- d2js/js.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/d2js/js.go b/d2js/js.go index 3b0e8a6390..1f3dfeb261 100644 --- a/d2js/js.go +++ b/d2js/js.go @@ -25,6 +25,7 @@ func main() { js.Global().Set("d2GetParentID", js.FuncOf(jsGetParentID)) js.Global().Set("d2GetObjOrder", js.FuncOf(jsGetObjOrder)) js.Global().Set("d2GetRefRanges", js.FuncOf(jsGetRefRanges)) + js.Global().Set("d2GetImportRanges", js.FuncOf(jsGetImportRanges)) js.Global().Set("d2Compile", js.FuncOf(jsCompile)) js.Global().Set("d2Parse", js.FuncOf(jsParse)) js.Global().Set("d2Encode", js.FuncOf(jsEncode)) @@ -124,7 +125,7 @@ func jsGetRefRanges(this js.Value, args []js.Value) interface{} { return string(str) } - refs, err := d2lsp.GetRefs(file, fs, key, boardPath) + refs, err := d2lsp.GetRefs(file, fs, boardPath, key) if err != nil { ret := jsRefRanges{D2Error: err.Error()} str, _ := json.Marshal(ret) @@ -145,6 +146,34 @@ func jsGetRefRanges(this js.Value, args []js.Value) interface{} { return string(str) } +func jsGetImportRanges(this js.Value, args []js.Value) interface{} { + fsRaw := args[0].String() + path := args[1].String() + importPath := args[2].String() + + var fs map[string]string + err := json.Unmarshal([]byte(fsRaw), &fs) + if err != nil { + ret := jsRefRanges{D2Error: err.Error()} + str, _ := json.Marshal(ret) + return string(str) + } + + ranges, err := d2lsp.GetImportRanges(path, fs, importPath) + if err != nil { + ret := jsRefRanges{D2Error: err.Error()} + str, _ := json.Marshal(ret) + return string(str) + } + + resp := jsRefRanges{ + Ranges: ranges, + } + + str, _ := json.Marshal(resp) + return string(str) +} + type jsObject struct { Result string `json:"result"` UserError string `json:"userError"`