| 1 | /* |
| 2 | * Main program using utility functions |
| 3 | * |
| 4 | * Test cross-file navigation: |
| 5 | * - F12 on 'factorial' should jump to utils.c |
| 6 | * - Shift+F12 on 'fibonacci' should show all usages |
| 7 | * - Ctrl+Shift+T and search "sum" to find sum_array |
| 8 | */ |
| 9 | |
| 10 | #include <stdio.h> |
| 11 | |
| 12 | // Forward declarations from utils.c |
| 13 | int factorial(int n); |
| 14 | int fibonacci(int n); |
| 15 | int sum_array(int *arr, int size); |
| 16 | int find_max(int *arr, int size); |
| 17 | |
| 18 | // Structure for testing Document Symbols (Ctrl+Shift+O) |
| 19 | typedef struct { |
| 20 | int id; |
| 21 | char name[50]; |
| 22 | double value; |
| 23 | } Record; |
| 24 | |
| 25 | // Test: F12 on this function name to jump to definition |
| 26 | void process_records(Record *records, int count) { |
| 27 | printf("Processing %d records\n", count); |
| 28 | for (int i = 0; i < count; i++) { |
| 29 | printf("Record %d: %s = %.2f\n", |
| 30 | records[i].id, |
| 31 | records[i].name, |
| 32 | records[i].value); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | int main() { |
| 37 | printf("Testing LSP features in C\n\n"); |
| 38 | |
| 39 | // Test factorial |
| 40 | // F12 on 'factorial' should jump to utils.c |
| 41 | int fact = factorial(5); |
| 42 | printf("factorial(5) = %d\n", fact); |
| 43 | |
| 44 | // Test fibonacci |
| 45 | // Shift+F12 on 'fibonacci' should show all usages |
| 46 | int fib = fibonacci(7); |
| 47 | printf("fibonacci(7) = %d\n", fib); |
| 48 | |
| 49 | // Test array functions |
| 50 | int numbers[] = {5, 2, 8, 1, 9, 3}; |
| 51 | int size = sizeof(numbers) / sizeof(numbers[0]); |
| 52 | |
| 53 | // F12 on 'sum_array' should jump to definition |
| 54 | int total = sum_array(numbers, size); |
| 55 | printf("sum_array() = %d\n", total); |
| 56 | |
| 57 | // F12 on 'find_max' should jump to definition |
| 58 | int max = find_max(numbers, size); |
| 59 | printf("find_max() = %d\n", max); |
| 60 | |
| 61 | // Test with records |
| 62 | Record records[2] = { |
| 63 | {1, "Alpha", 3.14}, |
| 64 | {2, "Beta", 2.71} |
| 65 | }; |
| 66 | process_records(records, 2); |
| 67 | |
| 68 | // Intentional errors for diagnostics |
| 69 | // ERROR: undefined function |
| 70 | int result = undefined_function(10); |
| 71 | |
| 72 | // ERROR: type mismatch |
| 73 | char *str = fact; |
| 74 | |
| 75 | // ERROR: undeclared variable |
| 76 | printf("Value: %d\n", undeclared_var); |
| 77 | |
| 78 | return 0; |
| 79 | } |