Skip to content

Commit 62a0480

Browse files
committed
docs: add LSP/formatter examples and troubleshooting section
- Add LSP server registry links and common server examples - Add formatter configuration examples (Prettier, Black, rustfmt, gofmt) - Add initializationOptions example for rust-analyzer - Add concise troubleshooting section with debug commands - Reference external docs instead of duplicating information Addresses remaining documentation gaps found during language pack testing.
1 parent e7f2a52 commit 62a0480

1 file changed

Lines changed: 107 additions & 5 deletions

File tree

docs/plugins/development/language-packs.md

Lines changed: 107 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,83 @@ The manifest configures the language pack:
7474
| `tabSize` | Default indentation width |
7575
| `useTabs` | Use tabs instead of spaces |
7676
| `autoIndent` | Enable automatic indentation |
77-
| `formatter.command` | Formatter command (e.g., `prettier`) |
78-
| `formatter.args` | Arguments for the formatter |
77+
| `formatter.command` | Formatter command (e.g., `prettier`, `rustfmt`) |
78+
| `formatter.args` | Arguments for the formatter (file path is passed automatically) |
79+
80+
**Formatter Examples:**
81+
82+
```json
83+
// Prettier (JavaScript/TypeScript/etc.)
84+
"formatter": {
85+
"command": "prettier",
86+
"args": ["--write"]
87+
}
88+
89+
// Prettier with plugin (Svelte, Vue, etc.)
90+
"formatter": {
91+
"command": "prettier",
92+
"args": ["--write", "--plugin", "prettier-plugin-svelte"]
93+
}
94+
95+
// Black (Python)
96+
"formatter": {
97+
"command": "black",
98+
"args": ["-"]
99+
}
100+
101+
// rustfmt (Rust)
102+
"formatter": {
103+
"command": "rustfmt",
104+
"args": []
105+
}
106+
107+
// gofmt (Go)
108+
"formatter": {
109+
"command": "gofmt",
110+
"args": ["-w"]
111+
}
112+
```
113+
114+
**Note:** The file path is automatically appended to the args by Fresh. Some formatters expect stdin (use `"-"` as arg), others expect file path.
79115

80116
### LSP Configuration
81117

82118
| Field | Description |
83119
|-------|-------------|
84-
| `command` | LSP server executable |
85-
| `args` | Arguments to pass to the server |
120+
| `command` | LSP server executable (e.g., `rust-analyzer`, `typescript-language-server`) |
121+
| `args` | Arguments to pass to the server (e.g., `["--stdio"]`) |
86122
| `autoStart` | Start server when opening matching files |
87-
| `initializationOptions` | Custom LSP initialization options |
123+
| `initializationOptions` | Custom LSP initialization options (language-specific JSON) |
124+
125+
**Finding LSP Servers:**
126+
- [Language Server Protocol Implementations](https://microsoft.github.io/language-server-protocol/implementors/servers/) - Official registry
127+
- [langserver.org](https://langserver.org/) - Community directory
128+
129+
**Common LSP Servers:**
130+
131+
| Language | Server | Command | Installation |
132+
|----------|--------|---------|--------------|
133+
| Rust | rust-analyzer | `rust-analyzer` | `rustup component add rust-analyzer` |
134+
| TypeScript/JavaScript | typescript-language-server | `typescript-language-server` | `npm install -g typescript-language-server` |
135+
| Python | pyright | `pyright-langserver` | `npm install -g pyright` |
136+
| Go | gopls | `gopls` | `go install golang.org/x/tools/gopls@latest` |
137+
| C/C++ | clangd | `clangd` | System package manager |
138+
139+
**Example with initialization options:**
140+
```json
141+
"lsp": {
142+
"command": "rust-analyzer",
143+
"args": [],
144+
"autoStart": true,
145+
"initializationOptions": {
146+
"cargo": {
147+
"buildScripts": {
148+
"enable": true
149+
}
150+
}
151+
}
152+
}
153+
```
88154

89155
## Finding Existing Grammars
90156

@@ -261,6 +327,42 @@ Always validate your package before publishing:
261327
fresh --check-plugin /path/to/your-language-pack
262328
```
263329

330+
## Troubleshooting
331+
332+
### Debugging Commands
333+
334+
```bash
335+
# Show log locations
336+
fresh --show-paths
337+
338+
# View Fresh logs
339+
tail -f ~/.local/state/fresh/logs/fresh-*.log
340+
341+
# Check LSP logs
342+
tail -f ~/.local/state/fresh/logs/lsp/<language>-*.log
343+
344+
# Validate package
345+
./validate.sh
346+
fresh --check-plugin /path/to/your-language-pack
347+
```
348+
349+
### Common Issues
350+
351+
**Syntax highlighting not working:**
352+
- Check logs for `Failed to parse grammar` - most often caused by `extends` directive (see compatibility warning)
353+
- Verify file extension in package.json: use `["py"]` not `[".py"]`
354+
- Confirm grammar file path is correct
355+
356+
**LSP server not starting:**
357+
- Verify server is installed: `which <server-command>`
358+
- Check LSP logs for error messages
359+
- See [LSP server registry](https://microsoft.github.io/language-server-protocol/implementors/servers/) for correct invocation
360+
361+
**Formatter not working:**
362+
- Verify formatter is installed: `which <formatter>`
363+
- Test manually: `<formatter> <args> <file>`
364+
- Check formatter documentation for correct arguments
365+
264366
## Publishing
265367

266368
1. Push your package to a public Git repository

0 commit comments

Comments
 (0)