diff --git a/languageserver/cmd/languageserver/main_wasm.go b/languageserver/cmd/languageserver/main_wasm.go index 4d468586..7d22a7fb 100644 --- a/languageserver/cmd/languageserver/main_wasm.go +++ b/languageserver/cmd/languageserver/main_wasm.go @@ -160,13 +160,31 @@ 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) @@ -174,6 +192,7 @@ func start(id int) { err = languageServer.SetOptions( server.WithAddressImportResolver(addressImportResolver), + server.WithStringImportResolver(stringImportResolver), ) if err != nil { panic(err)