diff --git a/src/Stratis.VS.StratisEVM/SolidityLanguageClient.cs b/src/Stratis.VS.StratisEVM/SolidityLanguageClient.cs index d46c245..973475d 100644 --- a/src/Stratis.VS.StratisEVM/SolidityLanguageClient.cs +++ b/src/Stratis.VS.StratisEVM/SolidityLanguageClient.cs @@ -260,49 +260,57 @@ public async Task HandleNotificationAsync(string methodName, JToken methodParam, public async Task HandleRequestAsync(string methodName, JToken methodParam, Func> sendRequest) { - var resp = await sendRequest(methodParam); - Info("Request {req} {param}: {resp}", methodName, methodParam?.ToString() ?? "", resp?.ToString() ?? "(null)"); - if (resp != null) + try { - if (methodName == "textDocument/hover") + var resp = await sendRequest(methodParam); + Info("Request {req} {param}: {resp}", methodName, methodParam?.ToString() ?? "", resp?.ToString() ?? "(null)"); + if (resp != null) { - if (resp.Root != null && resp.Root["contents"] != null && resp.Root["contents"]["kind"] != null && resp.Root["contents"]["kind"].Value() == "markdown") + if (methodName == "textDocument/hover") { - Info("Replace hover markup contents with plaintext."); - resp.Root["contents"]["kind"] = JValue.CreateString("plaintext"); - if (resp.Root["contents"]["value"] != null) + if (resp.Root != null && resp.Root["contents"] != null && resp.Root["contents"]["kind"] != null && resp.Root["contents"]["kind"].Value() == "markdown") { - resp.Root["contents"]["value"] = JValue.CreateString(resp.Root["contents"]["value"].Value().Replace("### ", "").Replace("#", "")); - } - else - { - resp.Root["contents"]["value"] = JValue.CreateString(""); + Info("Replace hover markup contents with plaintext."); + resp.Root["contents"]["kind"] = JValue.CreateString("plaintext"); + if (resp.Root["contents"]["value"] != null) + { + resp.Root["contents"]["value"] = JValue.CreateString(resp.Root["contents"]["value"].Value().Replace("### ", "").Replace("#", "")); + } + else + { + resp.Root["contents"]["value"] = JValue.CreateString(""); + } } } - } - else if (methodName == "textDocument/completion") - { - if (resp.Root.Type == JTokenType.Array && resp.Root.HasValues) + else if (methodName == "textDocument/completion") { - foreach (var f in resp.Root) + if (resp.Root.Type == JTokenType.Array && resp.Root.HasValues) { - if (f != null && f["documentation"] != null && f["documentation"]["kind"] != null && f["documentation"]["value"] != null && f["documentation"]["kind"].Value() == "markdown") + foreach (var f in resp.Root) { - Info("Replace completion markup contents with plaintext."); - f["documentation"]["kind"] = JValue.CreateString("plaintext"); - f["documentation"]["value"] = JValue.CreateString(f["documentation"]["value"].Value().Replace("### ", "").Replace("#", "")); + if (f != null && f["documentation"] != null && f["documentation"]["kind"] != null && f["documentation"]["value"] != null && f["documentation"]["kind"].Value() == "markdown") + { + Info("Replace completion markup contents with plaintext."); + f["documentation"]["kind"] = JValue.CreateString("plaintext"); + f["documentation"]["value"] = JValue.CreateString(f["documentation"]["value"].Value().Replace("### ", "").Replace("#", "")); + } } } + } - + return resp; + } + else + { + Info("resp is null"); + return JObject.FromObject(new { contents = new { kind = "plaintext", value = "" } }); } - return resp; } - else + catch (Exception ex) { - Info("resp is null"); + Error(ex, "Exception thrown handling request {m}.", methodName); return JObject.FromObject(new { contents = new { kind = "plaintext", value = "" } }); - } + } } } #endregion diff --git a/tests/solidity/test2/ReceivesEth.sol b/tests/solidity/test2/ReceivesEth.sol index 787ae9c..1e531d3 100644 --- a/tests/solidity/test2/ReceivesEth.sol +++ b/tests/solidity/test2/ReceivesEth.sol @@ -3,8 +3,9 @@ pragma solidity ^0.8.23; contract ReceivesEth { uint public amount = 1 ether; - + uint public amount2 = 2 ether; + receive() external payable { - require(msg.value == amount, "Wrong amount"); + require(msg.value == amount2, "Wrong amount"); } }