#systemd-unit #language-server #systemd #language #lsp #language-server-protocol #server

bin+lib systemd-language-server

A Rust and Language Server Protocol (LSP) based language server for systemd unit files

1 unstable release

new 0.1.0 Mar 7, 2025

#124 in Text editors

MIT license

32KB
485 lines

Systemd Language Server

English🇺🇸 | 简体中文🇨🇳

Crates.io Build Status codecov License: MIT Downloads Rust Version dependency status

A Rust and Language Server Protocol (LSP) based language server for systemd unit files, providing syntax highlighting, auto-completion, error checking, and more.

Features

  • Syntax highlighting for systemd unit files
  • Intelligent auto-completion suggestions
  • Real-time syntax error checking
  • Support for jumping to definitions
  • Hover documentation tooltips

Installation

Building from Source

Ensure you have the Rust toolchain installed, then run:

git clone https://github.com/10fish/systemd-language-server-rs.git
cd systemd-language-server-rs
cargo build --release

The compiled binary will be located at target/release/systemd-language-server.

Installing with Cargo

cargo install systemd-language-server

Usage

Running as a Standalone Server

systemd-language-server

Editor Integration

VS Code

  1. Install the vscode-languageclient extension
  2. Configure the systemd-language-server path in settings

Neovim

Use nvim-lspconfig configuration:

require'lspconfig'.systemd_ls.setup{
  cmd = { "systemd-language-server" },
  filetypes = { "systemd" },
  root_dir = function() return vim.loop.cwd() end
}

Configuration Options

You can configure the following options in the .systemd-ls.json file:

{
  "systemd": {
    "unitSearchPaths": ["/etc/systemd/system", "/usr/lib/systemd/system"],
    "diagnostics": {
      "enabled": true
    }
  }
}

Development

Dependencies

  • Rust 1.70+
  • tokio async runtime
  • tower-lsp library

Building and Testing

# Build the project
cargo build

# Run tests
cargo test

# Run linter
cargo clippy

Testing

The project includes several types of tests to ensure code quality and functionality:

Unit Tests

Unit tests verify the core functionality of parsing and validating systemd unit files:

  • tests/systemd_unit_tests.rs: Tests for various systemd unit file types (service, socket, timer, mount)
  • tests/diagnostics_tests.rs: Tests for error detection and validation

Integration Tests

A simplified integration test is included in tests/integration_tests.rs. This serves as a placeholder and can be expanded in the future when needed.

To run a specific test:

cargo test --test systemd_unit_tests

To run tests with detailed output:

cargo test -- --nocapture

Contributing

Pull Requests and Issues are welcome! Please ensure:

  1. Add tests for new features
  2. Update documentation
  3. Follow the project's code style

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements

  • tower-lsp - LSP implementation for Rust
  • systemd - Provides the unit file specification

Dependencies

~8–16MB
~188K SLoC