Python · 1516 bytes Raw Blame History
1 """
2 Simple calculator module for testing LSP features.
3
4 Test these features:
5 - Diagnostics: See the intentional errors below
6 - Go to Definition: F12 on function calls
7 - Find References: Shift+F12 on function names
8 - Rename: F2 on any function/variable
9 - Code Actions: Ctrl+. on errors
10 - Document Symbols: Ctrl+Shift+O to see outline
11 - Formatting: Shift+Alt+F to format
12 """
13
14
15 def add(x, y):
16 """Add two numbers together."""
17 return x + y
18
19
20 def subtract(x, y):
21 """Subtract y from x."""
22 return x - y
23
24
25 def multiply(x, y):
26 """Multiply two numbers."""
27 return x * y
28
29
30 def divide(x, y):
31 """Divide x by y."""
32 if y == 0:
33 raise ValueError("Cannot divide by zero")
34 return x / y
35
36
37 def calculate_total(items):
38 """Calculate total from a list of numbers."""
39 total = 0
40 for item in items:
41 total = total + item
42 return total
43
44
45 # Intentional error for diagnostics testing
46 def broken_function():
47 """This function has an error - undefined variable."""
48 result = add(5, 3)
49 print(f"Result: {reslt}") # ERROR: typo - should be 'result'
50 return reslt
51
52
53 # Another intentional error - missing import
54 def use_math():
55 """Uses math module without importing it."""
56 return math.sqrt(16) # ERROR: 'math' is not defined
57
58
59 # Test code
60 if __name__ == "__main__":
61 # These work fine
62 print(add(10, 5))
63 print(subtract(10, 5))
64 print(multiply(10, 5))
65 print(divide(10, 5))
66
67 # This will show diagnostic errors
68 broken_function()
69 use_math()