๐Ÿ“ฆ joeriddles / nats-server-lsp

โ˜… 0 stars โ‘‚ 0 forks ๐Ÿ‘ 0 watching
๐Ÿ“ฅ Clone https://github.com/joeriddles/nats-server-lsp.git
HTTPS git clone https://github.com/joeriddles/nats-server-lsp.git
SSH git clone git@github.com:joeriddles/nats-server-lsp.git
CLI gh repo clone joeriddles/nats-server-lsp
joeriddles joeriddles wip eaa95e1 1 days ago ๐Ÿ“ History
๐Ÿ“‚ main View all commits โ†’
๐Ÿ“ src
๐Ÿ“ test
๐Ÿ“ vscode-extension
๐Ÿ“„ .gitignore
๐Ÿ“„ jest.config.js
๐Ÿ“„ package.json
๐Ÿ“„ README.md
๐Ÿ“„ tsconfig.json
๐Ÿ“„ README.md

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

npm install -g nats-config-lsp

Or use locally:

npm install
npm run build

Usage

The LSP communicates over stdio. Configure your editor to use:

nats-config-lsp --stdio

VS Code

Install the NATS Configuration extension from the vscode-extension directory:

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:

# nats-config
port = 4222
host: "localhost"

Neovim (with nvim-lspconfig)

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:

# 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

npm install
npm run build
npm run watch  # Watch mode
npm test       # Run tests

VS Code Extension

# 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