markdown · 6726 bytes Raw Blame History

LSP Feature Test Files

These files are designed to test all LSP features in fac. Each file contains intentional errors and cross-references for comprehensive testing.

Files Overview

Python Files

  • calculator.py - Math functions with intentional errors

    • Undefined variable errors (reslt instead of result)
    • Missing import errors (math module)
    • Multiple functions for testing navigation
  • main.py - Main program importing calculator

    • Cross-file references for testing F12
    • Class structure for Document Symbols
    • Missing import error (divide function)

Fortran Files

  • math_utils.f90 - Math utilities module

    • Vector operations (add, dot product, magnitude)
    • Matrix multiplication
    • Intentional errors (uninitialized variables)
  • test_program.f90 - Program using math_utils

    • Cross-file references to test F12
    • Undefined variable error

C Files

  • utils.c - Utility functions

    • Factorial, fibonacci, array operations
    • Intentional errors (undefined variables, type mismatches)
  • main.c - Main program using utils

    • Cross-file function calls
    • Structure definition
    • Multiple intentional errors

Testing LSP Features

1. Diagnostics (F8)

Test: Open any file and check for error markers in the gutter.

Expected errors:

  • calculator.py: reslt undefined, math not imported
  • main.py: divide not imported
  • math_utils.f90: undefined_var in broken_routine
  • test_program.f90: undefined_result not declared
  • utils.c: undefined_var, type mismatch, missing return
  • main.c: undefined_function, type mismatch, undeclared_var

How to test:

fac calculator.py
# Press F8 to open diagnostics panel
# Navigate with j/k or ↑/↓
# Press Enter to jump to error

2. Go to Definition (F12)

Test: Cross-file navigation between importing files.

In main.py:

  1. Put cursor on add on line ~15
  2. Press F12
  3. Should jump to def add() in calculator.py

In test_program.f90:

  1. Put cursor on vector_add on line ~23
  2. Press F12
  3. Should jump to subroutine vector_add in math_utils.f90

In main.c:

  1. Put cursor on factorial on line ~28
  2. Press F12
  3. Should jump to int factorial() in utils.c

Return: Press Alt+, to jump back!

3. Find References (Shift+F12)

Test: Find all usages of a function.

In calculator.py:

  1. Put cursor on calculate_total function name
  2. Press Shift+F12
  3. Should show:
    • Definition in calculator.py
    • Usage in main.py (imported and called)

In math_utils.f90:

  1. Put cursor on vector_dot
  2. Press Shift+F12
  3. Should show usage in test_program.f90

4. Code Actions (Ctrl+.)

Test: Quick fixes for errors.

In calculator.py line ~48:

  1. Put cursor on reslt (undefined error)
  2. Press Ctrl+.
  3. Should offer to fix the typo or define reslt

In main.py line ~45:

  1. Put cursor on divide (not imported error)
  2. Press Ctrl+.
  3. Should offer to add divide to imports

5. Rename Symbol (F2)

Test: Rename across files.

In calculator.py:

  1. Put cursor on add function name
  2. Press F2
  3. Type new name (e.g., add_numbers)
  4. Press Enter
  5. Check:
    • Function renamed in calculator.py
    • Import statement updated in main.py
    • Function call updated in main.py

Undo: Press Ctrl+Z repeatedly to revert

6. Document Symbols (F4)

Test: See file outline.

In calculator.py:

  1. Press F4
  2. Should see:
    • add function
    • subtract function
    • multiply function
    • divide function
    • etc.
  3. Type "broken" to filter
  4. Press Enter to jump to function

In main.py:

  1. Press F4
  2. Should see:
    • DataProcessor class
    • process_data function
    • main function

7. Workspace Symbols (F6)

Test: Search symbols across ALL files.

  1. Press F6
  2. Type "add"
  3. Should see:
    • add function in calculator.py
    • vector_add in math_utils.f90
    • Maybe sum_array in utils.c (fuzzy match)
  4. Navigate with j/k
  5. Press Enter to jump (opens file if needed)

Try different searches:

  • "calc" → finds calculate_total, calculator, etc.
  • "vector" → finds all vector functions
  • "fact" → finds factorial

8. Signature Help

Test: Parameter hints while typing.

In any Python file:

  1. Type: calculate_total(
  2. Should see tooltip: calculate_total(items)
  3. As you type, current parameter is highlighted

In Fortran:

  1. Type: call vector_add(
  2. Should see signature with parameters

9. Document Formatting (Shift+Alt+F)

Test: Auto-format code.

In calculator.py:

  1. Mess up the formatting (add extra spaces, wrong indentation)
  2. Press Shift+Alt+F
  3. Code should be auto-formatted to PEP 8 style

In utils.c:

  1. Mess up braces and indentation
  2. Press Shift+Alt+F
  3. Code should be formatted with clang-format

10. Command Palette (Ctrl+P)

Test: Access commands without keybindings.

  1. Press Ctrl+P
  2. Type "format"
  3. Select "Format Document"
  4. Same as Shift+Alt+F

Or:

  1. Press Ctrl+P
  2. Type "def"
  3. Select "Go to Definition"
  4. Same as F12

Language Server Setup

To test these files, you need language servers installed:

Python:

pip install python-lsp-server

Fortran:

pip install fortls

C/C++:

# macOS
brew install llvm

# Linux
sudo apt install clangd

Expected Behavior

With Language Server Installed:

  • ✅ Red/yellow error markers in gutter
  • ✅ F12 jumps to definitions (even across files)
  • ✅ Shift+F12 shows all references
  • ✅ Ctrl+. offers quick fixes
  • ✅ F2 renames across files
  • ✅ F4 shows file outline
  • ✅ F6 searches all symbols
  • ✅ Shift+Alt+F formats code

Without Language Server:

  • ❌ No error markers
  • ❌ LSP features won't work
  • ✅ Basic editing still works
  • ✅ Syntax highlighting may work (if implemented separately)

Known Issues to Test

  1. Syntax highlighting for Fortran - Check if keywords are colored
  2. F8 vs Ctrl+D - Check if modifier keys work correctly
  3. Cross-file tabs - Check if F12 opens new tabs correctly
  4. Jump stack - Check if Alt+, returns to previous location

Quick Test Checklist

  • Open calculator.py and see diagnostics (red/yellow markers)
  • Press F8 and see error list
  • F12 on add in main.py → jumps to calculator.py
  • Alt+, → jumps back
  • Shift+F12 on calculate_total → shows references
  • F2 on multiply → rename and see it update in both files
  • F4 → see file outline
  • F6, type "vector" → find Fortran functions
  • Ctrl+. on an error → see quick fixes
  • Shift+Alt+F → format code
View source
1 # LSP Feature Test Files
2
3 These files are designed to test all LSP features in `fac`. Each file contains intentional errors and cross-references for comprehensive testing.
4
5 ## Files Overview
6
7 ### Python Files
8 - **calculator.py** - Math functions with intentional errors
9 - Undefined variable errors (`reslt` instead of `result`)
10 - Missing import errors (`math` module)
11 - Multiple functions for testing navigation
12
13 - **main.py** - Main program importing calculator
14 - Cross-file references for testing F12
15 - Class structure for Document Symbols
16 - Missing import error (`divide` function)
17
18 ### Fortran Files
19 - **math_utils.f90** - Math utilities module
20 - Vector operations (add, dot product, magnitude)
21 - Matrix multiplication
22 - Intentional errors (uninitialized variables)
23
24 - **test_program.f90** - Program using math_utils
25 - Cross-file references to test F12
26 - Undefined variable error
27
28 ### C Files
29 - **utils.c** - Utility functions
30 - Factorial, fibonacci, array operations
31 - Intentional errors (undefined variables, type mismatches)
32
33 - **main.c** - Main program using utils
34 - Cross-file function calls
35 - Structure definition
36 - Multiple intentional errors
37
38 ## Testing LSP Features
39
40 ### 1. Diagnostics (F8)
41
42 **Test:** Open any file and check for error markers in the gutter.
43
44 Expected errors:
45 - **calculator.py**: `reslt` undefined, `math` not imported
46 - **main.py**: `divide` not imported
47 - **math_utils.f90**: `undefined_var` in `broken_routine`
48 - **test_program.f90**: `undefined_result` not declared
49 - **utils.c**: `undefined_var`, type mismatch, missing return
50 - **main.c**: `undefined_function`, type mismatch, `undeclared_var`
51
52 **How to test:**
53 ```bash
54 fac calculator.py
55 # Press F8 to open diagnostics panel
56 # Navigate with j/k or ↑/↓
57 # Press Enter to jump to error
58 ```
59
60 ### 2. Go to Definition (F12)
61
62 **Test:** Cross-file navigation between importing files.
63
64 **In main.py:**
65 1. Put cursor on `add` on line ~15
66 2. Press `F12`
67 3. Should jump to `def add()` in calculator.py
68
69 **In test_program.f90:**
70 1. Put cursor on `vector_add` on line ~23
71 2. Press `F12`
72 3. Should jump to `subroutine vector_add` in math_utils.f90
73
74 **In main.c:**
75 1. Put cursor on `factorial` on line ~28
76 2. Press `F12`
77 3. Should jump to `int factorial()` in utils.c
78
79 **Return:** Press `Alt+,` to jump back!
80
81 ### 3. Find References (Shift+F12)
82
83 **Test:** Find all usages of a function.
84
85 **In calculator.py:**
86 1. Put cursor on `calculate_total` function name
87 2. Press `Shift+F12`
88 3. Should show:
89 - Definition in calculator.py
90 - Usage in main.py (imported and called)
91
92 **In math_utils.f90:**
93 1. Put cursor on `vector_dot`
94 2. Press `Shift+F12`
95 3. Should show usage in test_program.f90
96
97 ### 4. Code Actions (Ctrl+.)
98
99 **Test:** Quick fixes for errors.
100
101 **In calculator.py line ~48:**
102 1. Put cursor on `reslt` (undefined error)
103 2. Press `Ctrl+.`
104 3. Should offer to fix the typo or define `reslt`
105
106 **In main.py line ~45:**
107 1. Put cursor on `divide` (not imported error)
108 2. Press `Ctrl+.`
109 3. Should offer to add `divide` to imports
110
111 ### 5. Rename Symbol (F2)
112
113 **Test:** Rename across files.
114
115 **In calculator.py:**
116 1. Put cursor on `add` function name
117 2. Press `F2`
118 3. Type new name (e.g., `add_numbers`)
119 4. Press Enter
120 5. Check:
121 - Function renamed in calculator.py
122 - Import statement updated in main.py
123 - Function call updated in main.py
124
125 **Undo:** Press `Ctrl+Z` repeatedly to revert
126
127 ### 6. Document Symbols (F4)
128
129 **Test:** See file outline.
130
131 **In calculator.py:**
132 1. Press `F4`
133 2. Should see:
134 - `add` function
135 - `subtract` function
136 - `multiply` function
137 - `divide` function
138 - etc.
139 3. Type "broken" to filter
140 4. Press Enter to jump to function
141
142 **In main.py:**
143 1. Press `F4`
144 2. Should see:
145 - `DataProcessor` class
146 - `process_data` function
147 - `main` function
148
149 ### 7. Workspace Symbols (F6)
150
151 **Test:** Search symbols across ALL files.
152
153 1. Press `F6`
154 2. Type "add"
155 3. Should see:
156 - `add` function in calculator.py
157 - `vector_add` in math_utils.f90
158 - Maybe `sum_array` in utils.c (fuzzy match)
159 4. Navigate with j/k
160 5. Press Enter to jump (opens file if needed)
161
162 **Try different searches:**
163 - "calc" → finds `calculate_total`, `calculator`, etc.
164 - "vector" → finds all vector functions
165 - "fact" → finds `factorial`
166
167 ### 8. Signature Help
168
169 **Test:** Parameter hints while typing.
170
171 **In any Python file:**
172 1. Type: `calculate_total(`
173 2. Should see tooltip: `calculate_total(items)`
174 3. As you type, current parameter is highlighted
175
176 **In Fortran:**
177 1. Type: `call vector_add(`
178 2. Should see signature with parameters
179
180 ### 9. Document Formatting (Shift+Alt+F)
181
182 **Test:** Auto-format code.
183
184 **In calculator.py:**
185 1. Mess up the formatting (add extra spaces, wrong indentation)
186 2. Press `Shift+Alt+F`
187 3. Code should be auto-formatted to PEP 8 style
188
189 **In utils.c:**
190 1. Mess up braces and indentation
191 2. Press `Shift+Alt+F`
192 3. Code should be formatted with clang-format
193
194 ### 10. Command Palette (Ctrl+P)
195
196 **Test:** Access commands without keybindings.
197
198 1. Press `Ctrl+P`
199 2. Type "format"
200 3. Select "Format Document"
201 4. Same as Shift+Alt+F
202
203 Or:
204 1. Press `Ctrl+P`
205 2. Type "def"
206 3. Select "Go to Definition"
207 4. Same as F12
208
209 ## Language Server Setup
210
211 To test these files, you need language servers installed:
212
213 **Python:**
214 ```bash
215 pip install python-lsp-server
216 ```
217
218 **Fortran:**
219 ```bash
220 pip install fortls
221 ```
222
223 **C/C++:**
224 ```bash
225 # macOS
226 brew install llvm
227
228 # Linux
229 sudo apt install clangd
230 ```
231
232 ## Expected Behavior
233
234 ### With Language Server Installed:
235 - ✅ Red/yellow error markers in gutter
236 - ✅ F12 jumps to definitions (even across files)
237 - ✅ Shift+F12 shows all references
238 - ✅ Ctrl+. offers quick fixes
239 - ✅ F2 renames across files
240 - ✅ F4 shows file outline
241 - ✅ F6 searches all symbols
242 - ✅ Shift+Alt+F formats code
243
244 ### Without Language Server:
245 - ❌ No error markers
246 - ❌ LSP features won't work
247 - ✅ Basic editing still works
248 - ✅ Syntax highlighting may work (if implemented separately)
249
250 ## Known Issues to Test
251
252 1. **Syntax highlighting for Fortran** - Check if keywords are colored
253 2. **F8 vs Ctrl+D** - Check if modifier keys work correctly
254 3. **Cross-file tabs** - Check if F12 opens new tabs correctly
255 4. **Jump stack** - Check if Alt+, returns to previous location
256
257 ## Quick Test Checklist
258
259 - [ ] Open calculator.py and see diagnostics (red/yellow markers)
260 - [ ] Press F8 and see error list
261 - [ ] F12 on `add` in main.py → jumps to calculator.py
262 - [ ] Alt+, → jumps back
263 - [ ] Shift+F12 on `calculate_total` → shows references
264 - [ ] F2 on `multiply` → rename and see it update in both files
265 - [ ] F4 → see file outline
266 - [ ] F6, type "vector" → find Fortran functions
267 - [ ] Ctrl+. on an error → see quick fixes
268 - [ ] Shift+Alt+F → format code