Skip to content

Commit

Permalink
Revert "test modified"
Browse files Browse the repository at this point in the history
This reverts commit 2a96447.
  • Loading branch information
kugesan1105 committed Oct 14, 2024
1 parent 2a96447 commit 19c6151
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 35 deletions.
45 changes: 20 additions & 25 deletions jac/jaclang/langserve/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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."""
Expand All @@ -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:
Expand Down
38 changes: 28 additions & 10 deletions jac/jaclang/langserve/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -576,27 +590,31 @@ 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."""
lsp = JacLangServer()
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,
)

0 comments on commit 19c6151

Please sign in to comment.