From 19c61514959960d8056a41d60276dfadd56efb33 Mon Sep 17 00:00:00 2001 From: kugesan1105 Date: Mon, 14 Oct 2024 16:04:05 +0530 Subject: [PATCH] Revert "test modified" This reverts commit 2a964475f8f8b3bd2666cfeea6086225b36941cb. --- jac/jaclang/langserve/engine.py | 45 ++++++++++------------ jac/jaclang/langserve/tests/test_server.py | 38 +++++++++++++----- 2 files changed, 48 insertions(+), 35 deletions(-) diff --git a/jac/jaclang/langserve/engine.py b/jac/jaclang/langserve/engine.py index 856685dbb..5e1aa5037 100644 --- a/jac/jaclang/langserve/engine.py +++ b/jac/jaclang/langserve/engine.py @@ -80,28 +80,23 @@ def update_modules( impl_parent=self.modules[file_path], ) - def quick_check(self, file_path: str) -> tuple[bool, list[lspt.Diagnostic]]: + def quick_check(self, file_path: str) -> bool: """Rebuild a file.""" try: document = self.workspace.get_text_document(file_path) build = jac_str_to_pass( jac_str=document.source, file_path=document.path, schedule=[] ) - diagnostics = gen_diagnostics( - file_path, build.errors_had, build.warnings_had - ) self.publish_diagnostics( file_path, - diagnostics, + gen_diagnostics(file_path, build.errors_had, build.warnings_had), ) - return len(build.errors_had) == 0, diagnostics + return len(build.errors_had) == 0 except Exception as e: self.log_error(f"Error during syntax check: {e}") - return False, [] + return False - def deep_check( - self, file_path: str, annex_view: Optional[str] = None - ) -> tuple[bool, list[lspt.Diagnostic] | Exception]: + def deep_check(self, file_path: str, annex_view: Optional[str] = None) -> bool: """Rebuild a file and its dependencies.""" try: start_time = time.time() @@ -122,27 +117,29 @@ def deep_check( return self.deep_check( uris.from_fs_path(discover), annex_view=file_path ) - diagnostics = gen_diagnostics( - annex_view if annex_view else file_path, - build.errors_had, - build.warnings_had, - ) + self.publish_diagnostics( annex_view if annex_view else file_path, - diagnostics, + gen_diagnostics( + annex_view if annex_view else file_path, + build.errors_had, + build.warnings_had, + ), ) if annex_view: - diagnostics = gen_diagnostics( + self.publish_diagnostics( file_path, - build.errors_had, - build.warnings_had, + gen_diagnostics( + file_path, + build.errors_had, + build.warnings_had, + ), ) - self.publish_diagnostics(file_path, diagnostics) self.log_py(f"PROFILE: Deep check took {time.time() - start_time} seconds.") - return len(build.errors_had) == 0, diagnostics + return len(build.errors_had) == 0 except Exception as e: self.log_error(f"Error during deep check: {e}") - return False, e + return False async def launch_quick_check(self, uri: str) -> None: """Analyze and publish diagnostics.""" @@ -154,9 +151,7 @@ async def launch_deep_check(self, uri: str) -> None: """Analyze and publish diagnostics.""" async def run_in_executor( - func: Callable[ - [str, Optional[str]], tuple[bool, list[lspt.Diagnostic] | Exception] - ], + func: Callable[[str, Optional[str]], bool], file_path: str, annex_view: Optional[str] = None, ) -> None: diff --git a/jac/jaclang/langserve/tests/test_server.py b/jac/jaclang/langserve/tests/test_server.py index 613232297..61b5af77b 100644 --- a/jac/jaclang/langserve/tests/test_server.py +++ b/jac/jaclang/langserve/tests/test_server.py @@ -9,6 +9,20 @@ class TestJacLangServer(TestCase): + def _run_check_and_capture_logs(self, file_path, check_method): + file_uri = uris.from_fs_path(self.fixture_abs_path(file_path)) + import logging + import io + + log_capture = io.StringIO() + handler = logging.StreamHandler(log_capture) + logger = logging.getLogger() + logger.addHandler(handler) + logger.setLevel(logging.DEBUG) + status = check_method(file_uri) + log_output = log_capture.getvalue() + return status, log_output + def test_formatting(self) -> None: with LspSession() as s: s.initialize() @@ -576,15 +590,15 @@ def test_syntax_diagnosis(self) -> None: workspace_path = self.fixture_abs_path("") workspace = Workspace(workspace_path, lsp) lsp.lsp._workspace = workspace - file_path = "circle_pure_syntax_err.impl.jac" - file_uri = uris.from_fs_path(self.fixture_abs_path(file_path)) - status, log_output = lsp.quick_check(file_uri) + status, log_output = self._run_check_and_capture_logs( + "circle_pure_syntax_err.impl.jac", lsp.quick_check + ) self.assertEqual(False, status) self.assertIn( "message=\"Syntax Error: Unexpected token Token('KW_RETURN', 'return'", - str(log_output), + log_output, ) - self.assertIn("[Diagnostic(range=10:4-10:5,", str(log_output)) + self.assertIn("diagnostics=[Diagnostic(range=10:4-10:5", log_output) def test_impl_syntax_diagnosis(self) -> None: """Test that the server shows an error if there is a syntax error.""" @@ -592,11 +606,15 @@ def test_impl_syntax_diagnosis(self) -> None: workspace_path = self.fixture_abs_path("") workspace = Workspace(workspace_path, lsp) lsp.lsp._workspace = workspace - file_path = "circle_pure_syntax_err.jac" - file_uri = uris.from_fs_path(self.fixture_abs_path(file_path)) - status, log_output = lsp.deep_check(file_uri) + status, log_output = self._run_check_and_capture_logs( + "circle_pure_syntax_err.jac", lsp.deep_check + ) self.assertEqual(False, status) self.assertIn( - "empty body on ClassDef", - str(log_output), + "circle_pure_syntax_err.jac, line 10, col 1: Ability has no body. ", + log_output, + ) + self.assertIn( + "/circle_pure_syntax_err.impl.jac, line 11, col 5: Syntax Error:", + log_output, )