Skip to content

Commit

Permalink
update lsp
Browse files Browse the repository at this point in the history
  • Loading branch information
alixander committed Nov 7, 2024
1 parent 78bafb6 commit 387f42f
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion d2js/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand All @@ -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"`
Expand Down

0 comments on commit 387f42f

Please sign in to comment.