Skip to content

Commit d003400

Browse files
Merge pull request #13263 from ethereum/fix/lsp-checker-to-not-bail-on-missing-response
lsp: Fixes lsp.py to not bail out when no response is expected.
2 parents e7c5f04 + 5918955 commit d003400

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

test/lsp.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,10 @@ def send_message(self, method_name: str, params: Optional[dict]) -> None:
237237
self.process.stdin.write(rpc_message.encode("utf-8"))
238238
self.process.stdin.flush()
239239

240-
def call_method(self, method_name: str, params: Optional[dict]) -> Any:
240+
def call_method(self, method_name: str, params: Optional[dict], expects_response: bool = True) -> Any:
241241
self.send_message(method_name, params)
242+
if not expects_response:
243+
return None
242244
return self.receive_message()
243245

244246
def send_notification(self, name: str, params: Optional[dict] = None) -> None:
@@ -484,6 +486,8 @@ def parseRequestAndResponse(self) -> RequestAndResponse:
484486
if self.at_end():
485487
raise TestParserException(ret, "Request body not found")
486488

489+
if self.at_end():
490+
return self.RequestAndResponse(**ret)
487491

488492
# Parse response header
489493
if self.current_line().startswith(RESPONSE_START):
@@ -492,8 +496,6 @@ def parseRequestAndResponse(self) -> RequestAndResponse:
492496
raise TestParserException(ret, "Response header malformed")
493497
ret["response"] = self.current_line()[len(RESPONSE_START):] + "\n"
494498
ret["responseBegin"] = self.position()
495-
else:
496-
raise TestParserException(ret, "Response header not found")
497499

498500
self.next_line()
499501

@@ -568,7 +570,9 @@ def test_diagnostics(self):
568570

569571
# Process diagnostics first
570572
self.expected_diagnostics = next(self.parsed_testcases)
571-
assert isinstance(self.expected_diagnostics, TestParser.Diagnostics) is True
573+
assert isinstance(self.expected_diagnostics, TestParser.Diagnostics)
574+
if not self.expected_diagnostics.has_header:
575+
return
572576

573577
expected_diagnostics_per_file = self.expected_diagnostics.tests
574578

@@ -723,7 +727,14 @@ def run_testcase(self, testcase: TestParser.RequestAndResponse):
723727
if 'textDocument' not in requestBodyJson:
724728
requestBodyJson['textDocument'] = { 'uri': self.suite.get_test_file_uri(self.test_name, self.sub_dir) }
725729

726-
actualResponseJson = self.solc.call_method(testcase.method, requestBodyJson)
730+
actualResponseJson = self.solc.call_method(
731+
testcase.method,
732+
requestBodyJson,
733+
expects_response=testcase.response is not None
734+
)
735+
736+
if testcase.response is None:
737+
return
727738

728739
# simplify response
729740
if "result" in actualResponseJson:
@@ -1445,8 +1456,11 @@ def test_generic(self, solc: JsonRpcProcess) -> None:
14451456

14461457
for sub_dir in map(lambda filepath: filepath.name, sub_dirs):
14471458
tests = map(
1448-
lambda filename, sd=sub_dir: sd + "/" + filename[:-len(".sol")],
1449-
os.listdir(f"{self.project_root_dir}/{sub_dir}")
1459+
lambda file_object, sd=sub_dir: sd + "/" + file_object.name[:-len(".sol")],
1460+
filter(
1461+
lambda filepath: filepath.is_file() and filepath.name.endswith('.sol'),
1462+
os.scandir(f"{self.project_root_dir}/{sub_dir}")
1463+
)
14501464
)
14511465

14521466
tests = map(

0 commit comments

Comments
 (0)