| 1 | # LSP Test 5: Find References (Shift+F12) |
| 2 | # ======================================== |
| 3 | # |
| 4 | # Instructions: |
| 5 | # 1. Place cursor on a symbol |
| 6 | # 2. Press Shift+F12 to find all references |
| 7 | # 3. A list of locations should appear |
| 8 | # 4. Navigate the list to jump to each reference |
| 9 | # |
| 10 | # This file has symbols used multiple times for testing: |
| 11 | |
| 12 | |
| 13 | # A function that is called multiple times |
| 14 | def calculate(value: int) -> int: |
| 15 | """Calculate something with the value.""" |
| 16 | return value * 2 + 1 |
| 17 | |
| 18 | |
| 19 | # Test: Find all references to "calculate" |
| 20 | # Place cursor on any "calculate" and press Shift+F12 |
| 21 | result1 = calculate(10) |
| 22 | result2 = calculate(20) |
| 23 | result3 = calculate(30) |
| 24 | combined = calculate(result1) + calculate(result2) |
| 25 | |
| 26 | |
| 27 | # A class used in multiple places |
| 28 | class Counter: |
| 29 | """A simple counter class.""" |
| 30 | |
| 31 | def __init__(self): |
| 32 | self.count = 0 |
| 33 | |
| 34 | def increment(self): |
| 35 | self.count += 1 |
| 36 | |
| 37 | def get_count(self): |
| 38 | return self.count |
| 39 | |
| 40 | |
| 41 | # Test: Find all references to "Counter" |
| 42 | counter1 = Counter() |
| 43 | counter2 = Counter() |
| 44 | counters = [Counter(), Counter(), Counter()] |
| 45 | |
| 46 | # Test: Find all references to "increment" |
| 47 | counter1.increment() |
| 48 | counter1.increment() |
| 49 | counter2.increment() |
| 50 | for c in counters: |
| 51 | c.increment() |
| 52 | |
| 53 | |
| 54 | # A variable used throughout |
| 55 | MULTIPLIER = 10 |
| 56 | |
| 57 | # Test: Find all references to "MULTIPLIER" |
| 58 | value1 = 5 * MULTIPLIER |
| 59 | value2 = 3 * MULTIPLIER |
| 60 | value3 = MULTIPLIER * MULTIPLIER |
| 61 | |
| 62 | |
| 63 | def use_multiplier(x): |
| 64 | return x * MULTIPLIER |
| 65 | |
| 66 | |
| 67 | # A parameter used multiple times in a function |
| 68 | def process_data(data): |
| 69 | """Process data in multiple ways.""" |
| 70 | # Test: Find references to "data" parameter |
| 71 | if data is None: |
| 72 | return None |
| 73 | length = len(data) |
| 74 | first = data[0] if data else None |
| 75 | last = data[-1] if data else None |
| 76 | return {"data": data, "length": length, "first": first, "last": last} |
| 77 | |
| 78 | |
| 79 | # Call the function |
| 80 | process_data([1, 2, 3]) |
| 81 | process_data(["a", "b", "c"]) |