1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159# NATS Config LSP
Language Server Protocol implementation for NATS server configuration files.
## Features
- **Syntax validation** - Detects syntax errors in NATS config files
- **Schema validation** - Validates configuration against the full NATS server schema
- **Completions** - Context-aware auto-completions for config keys and values
- **Hover information** - Documentation on hover for configuration options
- **Diagnostics** - Warnings for unknown keys, type mismatches, deprecated options
## Installation
```bash
npm install -g nats-config-lsp
```
Or use locally:
```bash
npm install
npm run build
```
## Usage
The LSP communicates over stdio. Configure your editor to use:
```bash
nats-config-lsp --stdio
```
### VS Code
Install the NATS Configuration extension from the `vscode-extension` directory:
```bash
cd vscode-extension
npm install
npm run package
code --install-extension nats-config-0.1.0.vsix
```
The extension automatically activates for:
- Files named `nats.conf`, `nats-server.conf`, or `srv.conf`
- Files with `.nats.conf` extension
**Modeline support:** Add `# nats-config` to the first line of any `.conf` file to enable NATS config mode:
```conf
# nats-config
port = 4222
host: "localhost"
```
### Neovim (with nvim-lspconfig)
```lua
local lspconfig = require('lspconfig')
local configs = require('lspconfig.configs')
configs.nats_config = {
default_config = {
cmd = { 'nats-config-lsp', '--stdio' },
filetypes = { 'nats-config' },
root_dir = lspconfig.util.find_git_ancestor,
settings = {},
},
}
lspconfig.nats_config.setup{}
```
## Supported Configuration
The LSP validates against the full NATS server configuration schema:
### Top-Level Options
- Server identity: `server_name`, `server_tags`
- Connectivity: `host`, `port`, `listen`, `client_advertise`
- Limits: `max_connections`, `max_payload`, `max_pending`, `max_subscriptions`
- Timeouts: `ping_interval`, `ping_max`, `write_deadline`
- Logging: `debug`, `trace`, `logfile`, `logtime`
- Monitoring: `http_port`, `https_port`
### Configuration Blocks
- `tls` - TLS/SSL configuration
- `cluster` - Cluster configuration
- `jetstream` - JetStream persistence
- `authorization` - Authentication and authorization
- `accounts` - Multi-tenancy accounts
- `leafnodes` - Leaf node connections
- `gateway` - Super-cluster gateways
- `mqtt` - MQTT protocol support
- `websocket` - WebSocket support
## NATS Config Syntax
The NATS config format supports flexible syntax:
```conf
# Comments with # or //
port = 4222 # equals assignment
host: "localhost" # colon assignment
debug true # whitespace assignment
# Blocks
cluster {
name: "my-cluster"
routes: [
"nats://node1:6222"
"nats://node2:6222"
]
}
# Variables
TOKEN: "secret"
auth_token: $TOKEN
# Includes
include ./auth.conf
# Size units: K, KB, M, MB, G, GB, T, TB
max_payload: 1MB
# Duration units: s, m, h
ping_interval: 2m
```
## Development
### LSP Server
```bash
npm install
npm run build
npm run watch # Watch mode
npm test # Run tests
```
### VS Code Extension
```bash
# Build the LSP server first
npm run build
# Set up the extension
cd vscode-extension
npm install
npm run copy-server
```
To test the extension, open the `vscode-extension` folder in VS Code and press F5 to launch the Extension Development Host. The extension will compile automatically, but you need to run `npm run copy-server` again if you change the LSP server code.
## License
MIT