|
| 1 | +# LSP Completion Testing Documentation |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This document describes the comprehensive testing framework for the SageMath Enhanced LSP completion functionality. The testing verifies that inputs like "Poly", "PolRin", "polR" return "PolynomialRing" with high priority in the completion results. |
| 6 | + |
| 7 | +## Testing Approach |
| 8 | + |
| 9 | +### 1. Automated LSP Client Testing (`test_lsp_completion.js`) |
| 10 | + |
| 11 | +This is the primary testing method that simulates a VS Code client interacting with the language server programmatically. |
| 12 | + |
| 13 | +#### How it Works |
| 14 | + |
| 15 | +1. **Server Process Management**: Spawns the compiled language server (`out/server/src/server.js`) with `--stdio` flag |
| 16 | +2. **LSP Protocol Implementation**: Implements a minimal LSP client that can: |
| 17 | + - Send and receive LSP messages via stdio |
| 18 | + - Handle JSON-RPC 2.0 protocol |
| 19 | + - Parse Content-Length headers |
| 20 | + - Manage request/response correlation |
| 21 | +3. **Configuration Handling**: Responds to server configuration requests with appropriate settings |
| 22 | +4. **Completion Testing**: Sends `textDocument/completion` requests for various test scenarios |
| 23 | + |
| 24 | +#### Test Scenarios |
| 25 | + |
| 26 | +| Input | Position | Expected Result | |
| 27 | +|-------|----------|----------------| |
| 28 | +| "Poly" | After "Poly" | PolynomialRing at position 1 | |
| 29 | +| "PolRin" | After "PolRin" | PolynomialRing at position 1 | |
| 30 | +| "polR" | After "polR" | PolynomialRing at position 1 | |
| 31 | +| "Polyno" | After "Polyno" | PolynomialRing at position 1 | |
| 32 | +| "P" | After "P" | PolynomialRing at position 1 | |
| 33 | + |
| 34 | +#### Verification Criteria |
| 35 | + |
| 36 | +- ✅ PolynomialRing must appear in completion results |
| 37 | +- ✅ PolynomialRing must be in top 5 results (preferably position 1) |
| 38 | +- ✅ Sort text should indicate proper prioritization (starts with "00" for highest priority) |
| 39 | + |
| 40 | +### 2. Manual Testing (`test_completion.sh` + `test_poly_completion.sage`) |
| 41 | + |
| 42 | +#### Interactive Shell Script |
| 43 | +- Provides options for automated, manual, or both test modes |
| 44 | +- Handles project compilation and VS Code setup |
| 45 | +- Offers user-friendly interface for test selection |
| 46 | + |
| 47 | +#### Manual Test File |
| 48 | +`test_poly_completion.sage` contains various completion scenarios: |
| 49 | +```sage |
| 50 | +# Test case 1: Simple completion |
| 51 | +Poly |
| 52 | + |
| 53 | +# Test case 2: Assignment context |
| 54 | +ring = PolRin |
| 55 | + |
| 56 | +# Test case 3: Lowercase partial |
| 57 | +polR |
| 58 | + |
| 59 | +# Test case 4: Function call context |
| 60 | +my_function(Polyno |
| 61 | + |
| 62 | +# Test case 5: Just 'P' |
| 63 | +P |
| 64 | +``` |
| 65 | + |
| 66 | +## LSP Communication Protocol |
| 67 | + |
| 68 | +### Message Flow |
| 69 | + |
| 70 | +1. **Initialization**: |
| 71 | + ``` |
| 72 | + Client → Server: initialize request |
| 73 | + Server → Client: initialize response |
| 74 | + Client → Server: initialized notification |
| 75 | + ``` |
| 76 | + |
| 77 | +2. **Configuration**: |
| 78 | + ``` |
| 79 | + Server → Client: workspace/configuration request |
| 80 | + Client → Server: configuration response with settings |
| 81 | + ``` |
| 82 | + |
| 83 | +3. **Document Operations**: |
| 84 | + ``` |
| 85 | + Client → Server: textDocument/didOpen notification |
| 86 | + Server → Client: textDocument/publishDiagnostics notification |
| 87 | + ``` |
| 88 | + |
| 89 | +4. **Completion Requests**: |
| 90 | + ``` |
| 91 | + Client → Server: textDocument/completion request |
| 92 | + Server → Client: completion response with items |
| 93 | + ``` |
| 94 | + |
| 95 | +### Configuration Settings |
| 96 | + |
| 97 | +The test client provides these settings to the server: |
| 98 | +```json |
| 99 | +{ |
| 100 | + "maxNumberOfProblems": 100, |
| 101 | + "enableDiagnostics": true, |
| 102 | + "enableCompletion": true, |
| 103 | + "sagePath": "sage" |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +## Expected Completion Behavior |
| 108 | + |
| 109 | +### Sorting Algorithm |
| 110 | + |
| 111 | +The enhanced sorting algorithm uses priority prefixes: |
| 112 | + |
| 113 | +- `00` - Highest priority for important functions with exact/partial matches |
| 114 | +- `0` - Exact prefix matches |
| 115 | +- `0.5` - Substring matches |
| 116 | +- `1` - Default priority |
| 117 | +- `1.5` - Methods with prefix match |
| 118 | +- `2` - Default method priority |
| 119 | + |
| 120 | +### PolynomialRing Priority Boost |
| 121 | + |
| 122 | +For inputs containing "Poly" or similar patterns, PolynomialRing receives special handling: |
| 123 | +- Gets `00` priority prefix (highest) |
| 124 | +- Appears at position 1 in results |
| 125 | +- Has enhanced fuzzy matching |
| 126 | + |
| 127 | +### Sample Results |
| 128 | + |
| 129 | +For input "Poly": |
| 130 | +``` |
| 131 | +1. PolynomialRing (00polynomialring) ← Priority boost |
| 132 | +2. LaurentPolynomialRing (0.5laurentpolynomialring) |
| 133 | +3. Polynomial (0polynomial) |
| 134 | +4. poly (0poly) |
| 135 | +5. polynomial (0polynomial) |
| 136 | +``` |
| 137 | + |
| 138 | +## Running the Tests |
| 139 | + |
| 140 | +### Automated Test Only |
| 141 | +```bash |
| 142 | +node test_lsp_completion.js |
| 143 | +``` |
| 144 | + |
| 145 | +### Interactive Test Menu |
| 146 | +```bash |
| 147 | +./test_completion.sh |
| 148 | +``` |
| 149 | +Choose option 1 for automated, 2 for manual, or 3 for both. |
| 150 | + |
| 151 | +### Prerequisites |
| 152 | +- Node.js installed |
| 153 | +- Project compiled (`npm run compile`) |
| 154 | +- All dependencies installed (`npm install`) |
| 155 | + |
| 156 | +## Troubleshooting |
| 157 | + |
| 158 | +### Common Issues |
| 159 | + |
| 160 | +1. **Server fails to start**: |
| 161 | + - Ensure project is compiled: `npm run compile` |
| 162 | + - Check server path exists: `out/server/src/server.js` |
| 163 | + |
| 164 | +2. **Completion timeout**: |
| 165 | + - Verify configuration handling in client |
| 166 | + - Check server stdout/stderr for errors |
| 167 | + |
| 168 | +3. **Incorrect results**: |
| 169 | + - Review sorting algorithm in `server/src/server.ts` |
| 170 | + - Verify priority boost logic for PolynomialRing |
| 171 | + |
| 172 | +### Debug Output |
| 173 | + |
| 174 | +The automated test provides detailed output: |
| 175 | +- Number of completion items found |
| 176 | +- Position of PolynomialRing in results |
| 177 | +- Sort text for verification |
| 178 | +- Top 5 completions for analysis |
| 179 | + |
| 180 | +## Integration with CI/CD |
| 181 | + |
| 182 | +The automated test can be integrated into continuous integration: |
| 183 | +```bash |
| 184 | +# In CI pipeline |
| 185 | +npm run compile |
| 186 | +node test_lsp_completion.js |
| 187 | +``` |
| 188 | + |
| 189 | +Exit codes: |
| 190 | +- `0` - All tests passed |
| 191 | +- `1` - One or more tests failed |
| 192 | + |
| 193 | +## Future Enhancements |
| 194 | + |
| 195 | +1. **Additional Test Cases**: More complex scenarios (nested completions, imports, etc.) |
| 196 | +2. **Performance Testing**: Measure completion response times |
| 197 | +3. **Fuzzy Matching Tests**: Verify edge cases in fuzzy matching algorithm |
| 198 | +4. **Configuration Variations**: Test with different settings combinations |
0 commit comments