markdown · 3586 bytes Raw Blame History

LSP Tests

This directory contains tests for the Language Server Protocol (LSP) integration in the fac editor.

Test Files

Language-Specific Samples

  • sample.c - C/C++ test file with completion and hover test points
  • sample_errors.c - C file with intentional syntax errors for testing diagnostics
  • sample_python.py - Python test file with class/module completion tests
  • sample_rust.rs - Rust test file with struct and trait tests
  • sample_typescript.ts - TypeScript test file with interface and generic tests

Unit Tests

  • test_json.f90 - Tests the JSON parser implementation
  • test_lsp_init.f90 - Tests LSP server initialization and communication

Integration Tests (Expect Scripts)

  • test_initial_diagnostics.exp - Tests initial diagnostics when opening a file
  • test_realtime_diagnostics.exp - Tests real-time diagnostic updates
  • test_didsave_diagnostics.exp - Tests diagnostics after save (Ctrl+S)
  • test_diagnostics_debug.exp - Debug version with verbose output

Running Tests

Test JSON Parser

make test-lsp

Test LSP in Editor

make test-lsp-editor

Manual Testing

Open a supported file type in the editor:

./fac tests/lsp/sample.c   # Tests C/C++ with clangd
./fac tests/lsp/sample.py  # Tests Python with pylsp
./fac tests/lsp/sample.rs  # Tests Rust with rust-analyzer

Supported Languages

The editor currently supports LSP for:

  • C/C++ (clangd)
  • Python (pylsp)
  • Rust (rust-analyzer)
  • Go (gopls)
  • TypeScript/JavaScript (typescript-language-server)
  • Fortran (fortls)

Requirements

For LSP to work, you need the corresponding language servers installed:

  • C/C++: brew install llvm (provides clangd)
  • Python: pip install python-lsp-server
  • Rust: rustup component add rust-analyzer
  • Go: go install golang.org/x/tools/gopls@latest
  • TypeScript: npm install -g typescript typescript-language-server
  • Fortran: pip install fortls

Current Features

  • ✅ Automatic server startup when opening supported files
  • ✅ Server initialization handshake with capability detection
  • ✅ textDocument/didOpen notifications
  • ✅ textDocument/didChange notifications with debouncing (500ms)
  • ✅ textDocument/didSave notifications on file save
  • ✅ Code completion (Ctrl+Space) with popup UI
  • ✅ Hover information (Ctrl+H) with tooltip display
  • ✅ Diagnostics display with error/warning/info/hint markers
  • ✅ Diagnostics panel (Ctrl+Shift+D) showing all issues
  • ✅ Real-time document synchronization
  • ✅ Multi-language support (C/C++, Python, Rust, Go, TypeScript, Fortran)
  • ✅ JSON-RPC message handling
  • ✅ Response callback system

Keyboard Shortcuts

Action Key Description
Code Completion Ctrl+Space Show completion popup at cursor
Hover Info Ctrl+H Show type/doc tooltip at cursor
Diagnostics Panel Ctrl+Shift+D Toggle diagnostics panel
Save File Ctrl+S Save file (triggers LSP didSave)
Navigate Popup / Move through completion items
Navigate Panel j/k Move through diagnostics in panel
Jump to Diagnostic Enter Go to selected diagnostic location
Select Item Enter Insert selected completion
Dismiss Popup Escape Close any popup/tooltip/panel

Planned Features

  • Go to definition (Ctrl+])
  • Find references (Shift+F12)
  • Code actions and quick fixes (Ctrl+.)
  • Rename symbol (F2)
  • Document symbols outline (Ctrl+Shift+O)
  • Signature help
  • Document formatting
View source
1 # LSP Tests
2
3 This directory contains tests for the Language Server Protocol (LSP) integration in the fac editor.
4
5 ## Test Files
6
7 ### Language-Specific Samples
8 - `sample.c` - C/C++ test file with completion and hover test points
9 - `sample_errors.c` - C file with intentional syntax errors for testing diagnostics
10 - `sample_python.py` - Python test file with class/module completion tests
11 - `sample_rust.rs` - Rust test file with struct and trait tests
12 - `sample_typescript.ts` - TypeScript test file with interface and generic tests
13
14 ### Unit Tests
15 - `test_json.f90` - Tests the JSON parser implementation
16 - `test_lsp_init.f90` - Tests LSP server initialization and communication
17
18 ### Integration Tests (Expect Scripts)
19 - `test_initial_diagnostics.exp` - Tests initial diagnostics when opening a file
20 - `test_realtime_diagnostics.exp` - Tests real-time diagnostic updates
21 - `test_didsave_diagnostics.exp` - Tests diagnostics after save (Ctrl+S)
22 - `test_diagnostics_debug.exp` - Debug version with verbose output
23
24 ## Running Tests
25
26 ### Test JSON Parser
27 ```bash
28 make test-lsp
29 ```
30
31 ### Test LSP in Editor
32 ```bash
33 make test-lsp-editor
34 ```
35
36 ### Manual Testing
37 Open a supported file type in the editor:
38 ```bash
39 ./fac tests/lsp/sample.c # Tests C/C++ with clangd
40 ./fac tests/lsp/sample.py # Tests Python with pylsp
41 ./fac tests/lsp/sample.rs # Tests Rust with rust-analyzer
42 ```
43
44 ## Supported Languages
45
46 The editor currently supports LSP for:
47 - C/C++ (clangd)
48 - Python (pylsp)
49 - Rust (rust-analyzer)
50 - Go (gopls)
51 - TypeScript/JavaScript (typescript-language-server)
52 - Fortran (fortls)
53
54 ## Requirements
55
56 For LSP to work, you need the corresponding language servers installed:
57 - C/C++: `brew install llvm` (provides clangd)
58 - Python: `pip install python-lsp-server`
59 - Rust: `rustup component add rust-analyzer`
60 - Go: `go install golang.org/x/tools/gopls@latest`
61 - TypeScript: `npm install -g typescript typescript-language-server`
62 - Fortran: `pip install fortls`
63
64 ## Current Features
65 - ✅ Automatic server startup when opening supported files
66 - ✅ Server initialization handshake with capability detection
67 - ✅ textDocument/didOpen notifications
68 - ✅ textDocument/didChange notifications with debouncing (500ms)
69 - ✅ textDocument/didSave notifications on file save
70 - ✅ Code completion (`Ctrl+Space`) with popup UI
71 - ✅ Hover information (`Ctrl+H`) with tooltip display
72 - ✅ Diagnostics display with error/warning/info/hint markers
73 - ✅ Diagnostics panel (`Ctrl+Shift+D`) showing all issues
74 - ✅ Real-time document synchronization
75 - ✅ Multi-language support (C/C++, Python, Rust, Go, TypeScript, Fortran)
76 - ✅ JSON-RPC message handling
77 - ✅ Response callback system
78
79 ## Keyboard Shortcuts
80 | Action | Key | Description |
81 |--------|-----|-------------|
82 | Code Completion | `Ctrl+Space` | Show completion popup at cursor |
83 | Hover Info | `Ctrl+H` | Show type/doc tooltip at cursor |
84 | Diagnostics Panel | `Ctrl+Shift+D` | Toggle diagnostics panel |
85 | Save File | `Ctrl+S` | Save file (triggers LSP didSave) |
86 | Navigate Popup | `↑`/`↓` | Move through completion items |
87 | Navigate Panel | `j`/`k` | Move through diagnostics in panel |
88 | Jump to Diagnostic | `Enter` | Go to selected diagnostic location |
89 | Select Item | `Enter` | Insert selected completion |
90 | Dismiss Popup | `Escape` | Close any popup/tooltip/panel |
91
92 ## Planned Features
93 - [ ] Go to definition (`Ctrl+]`)
94 - [ ] Find references (`Shift+F12`)
95 - [ ] Code actions and quick fixes (`Ctrl+.`)
96 - [ ] Rename symbol (`F2`)
97 - [ ] Document symbols outline (`Ctrl+Shift+O`)
98 - [ ] Signature help
99 - [ ] Document formatting