Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

test lsp server routing diagnostics #570

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions jaclang/langserve/tests/fixtures/circle_pure_syntax_err.impl.jac
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Enum for shape types"""

:enum:ShapeType {
CIRCLE = "Circle",
UNKNOWN = "Unknown"
}

"""Function to calculate the area of a circle."""
:can:calculate_area
(radius: float) -> float
return math.pi * radius * radius;
}

:obj:Circle:can:init
(radius: float) {
self.radius = radius;
super.init(ShapeType.CIRCLE);
}

"""Overridden method to calculate the area of the circle."""
:obj:Circle:can:area -> float {
return math.pi * self.radius * self.radius;
}

:can:main_run {
print(
f"Area of a circle with radius {RAD} using function: {calculate_area(RAD)}"
);
print(
f"Area of a {c.shape_type.value} with radius {RAD} using class: {c.area()}"
);
}
34 changes: 34 additions & 0 deletions jaclang/langserve/tests/fixtures/circle_pure_syntax_err.jac
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
This module demonstrates a simple circle class and a function to calculate
the area of a circle in all of Jac's glory.
"""

import:py math;

enum ShapeType;

can calculate_area(radius: float) -> float;
can main_run;

"""Base class for a shape."""
obj Shape {
has shape_type: ShapeType;

can area -> float abs;
}

"""Circle class inherits from Shape."""
obj Circle :Shape: {
has radius: float;

can init(radius: float);
can area -> float;
}
# Radius of the demo circle

glob RAD = 5, c = Circle(radius=RAD);

"""Here we run the main program."""
with entry:__main__ {
main_run();
}
30 changes: 30 additions & 0 deletions jaclang/langserve/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,36 @@ def test_impl_auto_discover(self) -> None:
lsp.get_hover_info(circle_impl_file, pos).contents.value,
)

def test_impl_syntax_diagnosis(self) -> None:
"""Test that the server shows an error if there is a syntax error in impl."""
lsp = JacLangServer()
# Set up the workspace path to "fixtures/"
workspace_path = self.fixture_abs_path("")
workspace = Workspace(workspace_path, lsp)
lsp.lsp._workspace = workspace
circle_impl_syn_err_impl_file = uris.from_fs_path(
self.fixture_abs_path("circle_pure_syntax_err.impl.jac")
)
status = lsp.quick_check(circle_impl_syn_err_impl_file)
self.assertEqual(False, status)

def test_syntax_diagnosis(self) -> None:
"""Test that the server shows an error if there is a syntax error."""
lsp = JacLangServer()
# Set up the workspace path to "fixtures/"
workspace_path = self.fixture_abs_path("")
workspace = Workspace(workspace_path, lsp)
lsp.lsp._workspace = workspace
circle_impl_syn_err_file = uris.from_fs_path(
self.fixture_abs_path("circle_pure_syntax_err.jac")
)
lsp.deep_check(circle_impl_syn_err_file)
pos = lspt.Position(10, 5)
quick_status = lsp.quick_check(circle_impl_syn_err_file)
deep_status = lsp.deep_check(circle_impl_syn_err_file, pos)
self.assertEqual(True, quick_status)
self.assertEqual(False, deep_status)

def test_show_type_impl(self) -> None:
"""Test that the server doesn't run if there is a syntax error."""
lsp = JacLangServer()
Expand Down
Loading