JFryy/systemd-lsp
关于
适用于 systemd 单元文件的语言服务器,内置文档,并以 Rust 完整实现 LSP。
其他项目可以做什么
- Syntax Analysis - Complete parsing of systemd unit file structure
- Context Aware - Context aware automcompletion for directives for corresponding sections
- Diagnostics - Error detection and validation for sections, directives, directive fields and warnings for non-conventional configurations
- Autocompletion - Context-aware suggestions for sections and directives
实测星标增长
- 24小时
- 0
- 7天
- +3
- 15天
- +4
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文systemd-lsp
A Language Server Protocol (LSP) implementation for systemd unit files, providing editing support with syntax highlighting, diagnostics, autocompletion, and documentation.
Features

Core Language Server Features
- Syntax Analysis - Complete parsing of systemd unit file structure
- Context Aware - Context aware automcompletion for directives for corresponding sections
- Diagnostics - Error detection and validation for sections, directives, directive fields and warnings for non-conventional configurations
- Autocompletion - Context-aware suggestions for sections and directives
- Rich Documentation - Comprehensive hover information and goto definition
- Code Formatting - Formatting of unit files
Installation
Prerequisites
- Rust toolchain (install via rustup)
Install via Cargo
cargo install systemd-lsp
The binary will be installed to ~/.cargo/bin/systemd-lsp (or %USERPROFILE%\.cargo\bin\systemd-lsp on Windows).
Building from source
git clone https://github.com/jfryy/systemd-lsp.git
cd systemd-lsp
cargo build --release
The binary will be available at target/release/systemd-lsp.
Compilation
The project is built using Cargo, Rust's package manager. The --release flag optimizes the build for performance. For development, you can use cargo build for faster compilation times with debug information.
Usage
Neovim
Add this configuration to your Neovim setup:
do
---@param t table<string,string[]> {filetype, patterns[]}
---@return table<string,string>
local function populate_table(t)
local tmp = {}
for filetype, files in pairs(t) do
for _, file in pairs(files) do
tmp[file] = filetype
end
end
return tmp
end
--defines systemd and podman quadlet filetypes
local ext_patterns = {
systemd = {
"service", "socket", "timer", "mount", "automount",
"swap", "target", "path", "slice", "scope", "device",
},
podman = {
"container", "volume", "network", "kube", "pod", "build", "image"
}
}
vim.filetype.add {
extension = populate_table(ext_patterns),
filename = {},
pattern = {}
}
vim.lsp.config ["systemd_lsp"] = {
cmd = {os.getenv "HOME".."/.cargo/bin/systemd-lsp"}, -- for linux
-- cmd = {os.getenv "USERPROFILE".."\\.cargo\\bin\\systemd-lsp"}, -- for windows
filetypes = {"systemd", "podman"}
}
vim.lsp.enable "systemd_lsp"
end
Vim
With LSP, add to your vimrc
call LspAddServer([#{name: 'systemd_ls',
\ filetype: 'systemd',
\ path: 'systemd-lsp',
\ }])
Emacs
(with-eval-after-load 'eglot
(add-to-list 'eglot-server-programs
'(systemd-mode "/path/to/systemd-lsp")))
Replace /path/to/systemd-lsp with the actual path to your built binary.
Helix
Works out of the box, just make sure the systemd-lsp binary is in your PATH variable.
Verify that Helix detects systemd-lsp with hx --health systemd.
Manual execution
You can run the language server directly, although there is little reason to do so except for debugging purposes. An editor typically starts and stops the server implicitly.
./target/release/systemd-lsp
Architecture
- Embedded Documentation - All manual pages built into the binary
- No External Dependencies - Single binary with everything included
- Cross-Platform - Works on Linux, macOS, and Windows
- LSP Standard Compliant - Compatible with all LSP-capable editors
About
This project is designed to simplify the editing of Unit files by providing validation, autocompletion, and formatting features commonly available for modern languages and file formats. Inspired by systemd-language-server, it offers enhanced functionality and improved performance, leveraging Rust's memory safety and efficiency. I don't always have a ton of time for staying up to date with all the changes that occur to systemd, so contributions or other maintainers of this language server are greatly appreciated. This language server has the somewhat unique difficulty of maintaing a large static list of directives for sections that can change on occasion rather than having the challenge of maintaining an AST for an actual programming language. Any systemD experts would be appreciated for their input, feedback, or maintaining of this language server while the latter half of bugs are squashed out.
Contributing
Contributions are always encouraged and welcome. See CONTRIBUTING.md for setup, CI checks, and how to update directives from the systemd manuals.
探索相关项目
加载中…