Python · 1984 bytes Raw Blame History
1 #!/usr/bin/env python3
2 """
3 LSP Test File for Python (pylsp)
4 Tests code completion, hover, and diagnostics
5
6 Required: pip install python-lsp-server
7 """
8
9 import os
10 import sys
11 from typing import List, Dict, Optional
12
13
14 class Employee:
15 """Sample class to test hover and completion"""
16
17 def __init__(self, name: str, age: int, salary: float):
18 self.name = name
19 self.age = age
20 self.salary = salary
21
22 def get_info(self) -> str:
23 """Returns employee information as a string"""
24 return f"{self.name}, {self.age} years, ${self.salary:.2f}"
25
26 def give_raise(self, percentage: float) -> None:
27 """Increases salary by given percentage"""
28 self.salary *= (1 + percentage / 100)
29
30
31 def process_employees(employees: List[Employee]) -> Dict[str, float]:
32 """Process employee data and return salary statistics"""
33 if not employees:
34 return {"average": 0, "total": 0}
35
36 total = sum(emp.salary for emp in employees)
37
38 # Test completion: Type 'emp.' and press Ctrl+Space
39 # Should show: name, age, salary, get_info, give_raise
40 emp = employees[0]
41 emp.
42
43 return {
44 "average": total / len(employees),
45 "total": total,
46 "count": len(employees)
47 }
48
49
50 def main():
51 # Test hover: Position cursor on 'Employee' and press Ctrl+H
52 # Should show class docstring and constructor signature
53 employees = [
54 Employee("Alice", 30, 75000),
55 Employee("Bob", 35, 85000),
56 Employee("Charlie", 28, 65000)
57 ]
58
59 # Test completion: Type 'os.' and press Ctrl+Space
60 # Should show os module members
61 current_dir = os.
62
63 # Test completion: Type 'sys.' and press Ctrl+Space
64 # Should show sys module members
65 version = sys.
66
67 stats = process_employees(employees)
68 print(f"Statistics: {stats}")
69
70 # Intentional error for diagnostics test
71 # Should show: undefined variable 'undefined_var'
72 print(undefined_var)
73
74
75 if __name__ == "__main__":
76 main()