Python · 1636 bytes Raw Blame History
1 # LSP Test 2: Code Completion (Ctrl+Space)
2 # =========================================
3 #
4 # Instructions:
5 # 1. Place cursor after a dot or partial word
6 # 2. Press Ctrl+Space to trigger completion
7 # 3. Use Up/Down arrows to navigate suggestions
8 # 4. Press Enter or Tab to accept a completion
9 # 5. Press Escape to dismiss without completing
10 #
11 # Try completing at the marked positions below:
12
13 import os
14 import json
15 from pathlib import Path
16
17 # Test 1: Module completions
18 # Place cursor after "os." and press Ctrl+Space
19 path = os. # <- complete here (try: getcwd, path, environ)
20
21 # Test 2: String method completions
22 # Place cursor after "text." and press Ctrl+Space
23 text = "hello world"
24 upper = text. # <- complete here (try: upper, lower, split, strip)
25
26 # Test 3: List method completions
27 numbers = [3, 1, 4, 1, 5]
28 numbers. # <- complete here (try: append, sort, reverse, pop)
29
30 # Test 4: Dict method completions
31 data = {"name": "test", "value": 42}
32 keys = data. # <- complete here (try: keys, values, items, get)
33
34 # Test 5: Path object completions
35 p = Path("/tmp")
36 p. # <- complete here (try: exists, is_file, read_text, mkdir)
37
38 # Test 6: Partial word completion
39 # Type "pri" and press Ctrl+Space to complete to "print"
40 # pri # <- uncomment and complete
41
42 # Test 7: Import completion
43 # from pathlib import P # <- complete after P (Path, PurePath, etc.)
44
45
46 class MyClass:
47 def __init__(self):
48 self.value = 100
49 self.name = "test"
50
51 def process(self):
52 # Test 8: Self completions
53 return self. # <- complete here (try: value, name)
54
55
56 obj = MyClass()
57 obj. # <- complete here (try: value, name, process)