Skip to content

Commit

Permalink
update to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
alixander committed Nov 7, 2024
1 parent 387f42f commit 1087778
Showing 1 changed file with 8 additions and 41 deletions.
49 changes: 8 additions & 41 deletions d2js/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ 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 @@ -90,10 +89,11 @@ func jsGetParentID(this js.Value, args []js.Value) interface{} {
}

type jsRefRanges struct {
Ranges []d2ast.Range `json:"ranges"`
ParseError string `json:"parseError"`
UserError string `json:"userError"`
D2Error string `json:"d2Error"`
Ranges []d2ast.Range `json:"ranges"`
ImportRanges []d2ast.Range `json:"importRanges"`
ParseError string `json:"parseError"`
UserError string `json:"userError"`
D2Error string `json:"d2Error"`
}

func jsGetRefRanges(this js.Value, args []js.Value) interface{} {
Expand Down Expand Up @@ -125,49 +125,16 @@ func jsGetRefRanges(this js.Value, args []js.Value) interface{} {
return string(str)
}

refs, err := d2lsp.GetRefs(file, fs, boardPath, key)
if err != nil {
ret := jsRefRanges{D2Error: err.Error()}
str, _ := json.Marshal(ret)
return string(str)
}

var ranges []d2ast.Range

for _, ref := range refs {
ranges = append(ranges, ref.AST().GetRange())
}

resp := jsRefRanges{
Ranges: ranges,
}

str, _ := json.Marshal(resp)
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)
ranges, importRanges, err := d2lsp.GetRefRanges(file, fs, boardPath, key)
if err != nil {
ret := jsRefRanges{D2Error: err.Error()}
str, _ := json.Marshal(ret)
return string(str)
}

resp := jsRefRanges{
Ranges: ranges,
Ranges: ranges,
ImportRanges: importRanges,
}

str, _ := json.Marshal(resp)
Expand Down

0 comments on commit 1087778

Please sign in to comment.