Skip to main content

An SSH config formatter, usable as a Language Server Protocol (LSP) plugin.

Project description

SSH config formatter

Python badge MIT License

Packager: uv Linter/Formatter: ruff Type checker: ty

Little side project to start learning Rust and explore LSP.

✨ Features

  • Formatting of SSH config files via the sshfmt format command
  • Language server started with sshfmt server, following the LSP protocol

📦 Installation

You can install the tool easily with pipx or uv:

uv tool install git+https://gitlab.com/nifra/ssh-config-ls

🔧 Configuration

The language server accepts the following options from the client (e.g. Neovim):

{
    formatter = {
        indent = "    ",  -- Indentation for directives inside Host and Match blocks
        separator = " ",  -- Separator between a keyword and its arguments
        sort_directives = true, -- Sort directives within blocks
    }
}

Formateur de config SSH — Plan de projet

Étape 1 — Prototype Python

Objectif : valider la logique de parsing et de formatage sans se battre contre un nouveau langage.

Note : Couvrir les cas limites (commentaires inline, blocs Host/Match, lignes vides multiples) et garder les tests sur le comportement observable (entrée/sortie texte) — ils serviront de spec pour la réécriture Rust.

Fonctionnalités à implémenter :

Lexer :

  • Ajouter des tests sur le tokenizer
  • Implémenter un tokenizer pour le cœur de la config
  • Ajouter les commentaires dans le tokenizer
  • Écrire tous les tests vicieux imaginables

Parser :

  • Ajouter des tests sur le parser
  • Implémenter un parser
  • Parser les blocs Host et Match
  • Écrire tous les tests vicieux imaginables

Formatage :

  • Préserver les commentaires et automatises les lignes vides
  • Normaliser l'indentation (4 espaces)
  • Canonicaliser la casse des clés (hostnameHostname)
  • Écrire tous les tests vicieux imaginables

CLI :

  • sshls format <file> — formate en place
  • sshls format --check <file> — exit code non-zéro si non formaté (CI)
  • sshls format --diff <file> — affiche le diff

LSP :

  • Lib : pygls
  • Créer le serveur
  • Ajouter textDocument/formatting

Hors scope pour l'instant :

  • Gérer les directives Include
  • Trier les blocs (* en dernier)

Étape 2 — Apprentissage Rust

Avant de réécrire, poser les bases du langage.

  • Lire les chapitres fondamentaux de The Book, en particulier sur l'ownership et les enums
  • Faire quelques exercices Rustlings pour la syntaxe
  • Libs à connaître pour ce projet : pest ou winnow (parsing), clap (CLI)

Étape 3 — Réécriture en Rust

Réécrire le formateur en Rust en s'appuyant sur les tests Python comme spec.

  • Reprendre exactement les mêmes fonctionnalités et la même interface CLI
  • Les tests Python guident l'implémentation et valident la parité de comportement

Étape 4 — Serveur LSP

Transformer le formateur en serveur LSP avec uniquement la capacité de formatage (textDocument/formatting).

  • Lib : tower-lsp pour abstraire le protocole JSON-RPC
  • Intégration Neovim via vim.lsp.start() ou nvim-lspconfig — pas de plugin dédié nécessaire

Références

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ssh_config_ls-0.7.4.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ssh_config_ls-0.7.4-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file ssh_config_ls-0.7.4.tar.gz.

File metadata

  • Download URL: ssh_config_ls-0.7.4.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Alpine Linux","version":"3.23.5","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ssh_config_ls-0.7.4.tar.gz
Algorithm Hash digest
SHA256 0aeaf36feefec5e80ddf023f791a2898530e7f0f2ddbb6b29621e6692106726e
MD5 812bd0c457d31072cee5ed0a7895271b
BLAKE2b-256 48ea0278dcd75efcbb8d9dcdf42224731576dbb4970aad8316aa151b18e1280a

See more details on using hashes here.

File details

Details for the file ssh_config_ls-0.7.4-py3-none-any.whl.

File metadata

  • Download URL: ssh_config_ls-0.7.4-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Alpine Linux","version":"3.23.5","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ssh_config_ls-0.7.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9cfaa298e44a0f2ae449e5771b3010432c347b62505c24fea177bbdc182b92c8
MD5 11d586ad8f36477bb4dc13d261ec1ddc
BLAKE2b-256 0a0ec2db1fa6b754d206e4c8838518dc9a01ceede5717de02d8433569cc6a1db

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page