C · 1472 bytes Raw Blame History
1 /*
2 * Simple utility functions for testing LSP features
3 *
4 * Test:
5 * - Diagnostics: Intentional errors marked below
6 * - Go to Definition: F12 on function calls
7 * - Find References: Shift+F12 on function names
8 * - Code Actions: Ctrl+. on errors
9 * - Formatting: Shift+Alt+F
10 */
11
12 #include <stdio.h>
13 #include <stdlib.h>
14
15 // Calculate factorial
16 int factorial(int n) {
17 if (n <= 1) {
18 return 1;
19 }
20 return n * factorial(n - 1);
21 }
22
23 // Calculate fibonacci number
24 int fibonacci(int n) {
25 if (n <= 1) {
26 return n;
27 }
28 return fibonacci(n - 1) + fibonacci(n - 2);
29 }
30
31 // Sum array elements
32 int sum_array(int *arr, int size) {
33 int total = 0;
34 for (int i = 0; i < size; i++) {
35 total += arr[i];
36 }
37 return total;
38 }
39
40 // Find maximum in array
41 int find_max(int *arr, int size) {
42 if (size <= 0) {
43 return 0;
44 }
45
46 int max = arr[0];
47 for (int i = 1; i < size; i++) {
48 if (arr[i] > max) {
49 max = arr[i];
50 }
51 }
52 return max;
53 }
54
55 // Intentional error function for diagnostics
56 int broken_function() {
57 int x = 10;
58 int y = 20;
59
60 // ERROR: undefined variable
61 int result = x + y + undefined_var;
62
63 // ERROR: incompatible pointer type
64 char *str = result;
65
66 printf("Result: %d\n", result);
67 return result;
68 }
69
70 // Another error - missing return
71 int missing_return(int x) {
72 if (x > 0) {
73 return x * 2;
74 }
75 // ERROR: missing return statement for x <= 0
76 }