Skip to content

Commit

Permalink
Merge pull request #228 from onflow/jribbink/string-import-wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent authored Oct 26, 2023
2 parents 9f82dd6 + 20fdb4d commit 846cd46
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion languageserver/cmd/languageserver/main_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,39 @@ func start(id int) {
)

addressImportResolver := func(location common.AddressLocation) (code string, err error) {
res := global.Call(globalFunctionName(id, "getAddressCode"), location.String())
getAddressCodeFunc := global.Get(globalFunctionName(id, "getAddressCode"))
if getAddressCodeFunc.IsNull() || getAddressCodeFunc.IsUndefined() {
return "", fmt.Errorf("CLS %d: getAddressCode not defined", id)
}

res := getAddressCodeFunc.Invoke(location.Address().String())
if res.IsNull() || res.IsUndefined() {
return "", fmt.Errorf("CLS %d: getAddressCode failed: %s", id, res)
}
return res.String(), nil
}

stringImportResolver := func(location common.StringLocation) (code string, err error) {
getStringCodeFunc = global.Get(globalFunctionName(id, "getStringCode"))
if getStringCodeFunc.IsNull() || getStringCodeFunc.IsUndefined() {
return "", fmt.Errorf("CLS %d: getStringCode not defined", id)
}

res := getStringCodeFunc.Invoke(location.String())
if res.IsNull() || res.IsUndefined() {
return "", fmt.Errorf("CLS %d: getStringCode failed: %s", id, res)
}
return res.String(), nil
}

languageServer, err := server.NewServer()
if err != nil {
panic(err)
}

err = languageServer.SetOptions(
server.WithAddressImportResolver(addressImportResolver),
server.WithStringImportResolver(stringImportResolver),
)
if err != nil {
panic(err)
Expand Down

0 comments on commit 846cd46

Please sign in to comment.