Skip to content

Commit c3814ed

Browse files
committed
update to latest
1 parent 23f48df commit c3814ed

File tree

1 file changed

+8
-41
lines changed

1 file changed

+8
-41
lines changed

d2js/js.go

+8-41
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ func main() {
2525
js.Global().Set("d2GetParentID", js.FuncOf(jsGetParentID))
2626
js.Global().Set("d2GetObjOrder", js.FuncOf(jsGetObjOrder))
2727
js.Global().Set("d2GetRefRanges", js.FuncOf(jsGetRefRanges))
28-
js.Global().Set("d2GetImportRanges", js.FuncOf(jsGetImportRanges))
2928
js.Global().Set("d2Compile", js.FuncOf(jsCompile))
3029
js.Global().Set("d2Parse", js.FuncOf(jsParse))
3130
js.Global().Set("d2Encode", js.FuncOf(jsEncode))
@@ -90,10 +89,11 @@ func jsGetParentID(this js.Value, args []js.Value) interface{} {
9089
}
9190

9291
type jsRefRanges struct {
93-
Ranges []d2ast.Range `json:"ranges"`
94-
ParseError string `json:"parseError"`
95-
UserError string `json:"userError"`
96-
D2Error string `json:"d2Error"`
92+
Ranges []d2ast.Range `json:"ranges"`
93+
ImportRanges []d2ast.Range `json:"importRanges"`
94+
ParseError string `json:"parseError"`
95+
UserError string `json:"userError"`
96+
D2Error string `json:"d2Error"`
9797
}
9898

9999
func jsGetRefRanges(this js.Value, args []js.Value) interface{} {
@@ -125,49 +125,16 @@ func jsGetRefRanges(this js.Value, args []js.Value) interface{} {
125125
return string(str)
126126
}
127127

128-
refs, err := d2lsp.GetRefs(file, fs, boardPath, key)
129-
if err != nil {
130-
ret := jsRefRanges{D2Error: err.Error()}
131-
str, _ := json.Marshal(ret)
132-
return string(str)
133-
}
134-
135-
var ranges []d2ast.Range
136-
137-
for _, ref := range refs {
138-
ranges = append(ranges, ref.AST().GetRange())
139-
}
140-
141-
resp := jsRefRanges{
142-
Ranges: ranges,
143-
}
144-
145-
str, _ := json.Marshal(resp)
146-
return string(str)
147-
}
148-
149-
func jsGetImportRanges(this js.Value, args []js.Value) interface{} {
150-
fsRaw := args[0].String()
151-
path := args[1].String()
152-
importPath := args[2].String()
153-
154-
var fs map[string]string
155-
err := json.Unmarshal([]byte(fsRaw), &fs)
156-
if err != nil {
157-
ret := jsRefRanges{D2Error: err.Error()}
158-
str, _ := json.Marshal(ret)
159-
return string(str)
160-
}
161-
162-
ranges, err := d2lsp.GetImportRanges(path, fs, importPath)
128+
ranges, importRanges, err := d2lsp.GetRefRanges(file, fs, boardPath, key)
163129
if err != nil {
164130
ret := jsRefRanges{D2Error: err.Error()}
165131
str, _ := json.Marshal(ret)
166132
return string(str)
167133
}
168134

169135
resp := jsRefRanges{
170-
Ranges: ranges,
136+
Ranges: ranges,
137+
ImportRanges: importRanges,
171138
}
172139

173140
str, _ := json.Marshal(resp)

0 commit comments

Comments
 (0)