Ansible-mode + lsp for yaml - #2281
Open
Pythonpoison48 wants to merge 1 commit into
Open
Conversation
Contributor
|
✅ Code Contractor Validation: PASSED 📌 Result for commit 📋 Contract Configuration: contract (Source: Repository)version: 2
trigger:
paths:
- "extensions/**"
- "frontends/**/*.lisp"
- "src/**"
- "tests/**"
- "contrib/**"
- "**/*.asd"
head_branches:
exclude:
- 'revert-*'
validation:
limits:
max_total_changed_lines: 400
max_delete_ratio: 0.5
max_files_changed: 10
severity: warning
ai:
system_prompt: |
You are a senior Common Lisp engineer reviewing code for Lem editor.
Lem is a text editor with multiple frontends (ncurses, SDL2, webview).
Focus on maintainability, consistency with existing code, and Lem-specific conventions.
rules:
# === File Structure ===
- name: defpackage_rule
prompt: |
First form must be `defpackage` or `uiop:define-package`.
Package name should match filename (e.g., `foo.lisp` → `:lem-ext/foo` or `:lem-foo`).
Extensions must use `lem-` prefix (e.g., `:lem-python-mode`).
- name: file_structure_rule
prompt: |
File organization (top to bottom):
1. defpackage
2. defvar/defparameter declarations
3. Key bindings (define-key, define-keys)
4. Class/struct definitions
5. Functions and commands
Only flag violations when elements appear OUT OF ORDER (e.g., key bindings AFTER functions, or defvar AFTER functions).
Key bindings appearing BEFORE functions is correct and expected.
# === Style ===
- name: loop_keywords_rule
prompt: |
Loop keywords must use colons: `(loop :for x :in list :do ...)`
NOT: `(loop for x in list do ...)`
- name: naming_conventions_rule
prompt: |
Naming conventions:
- Functions/variables: kebab-case (e.g., `find-buffer`)
- Special variables: *earmuffs* (e.g., `*global-keymap*`)
- Constants: +plus-signs+ (e.g., `+default-tab-size+`)
- Predicates: -p suffix for functions (e.g., `buffer-modified-p`)
- Do NOT use -p suffix for user-configurable variables
# === Documentation ===
- name: docstring_rule
prompt: |
Required docstrings for:
- Exported functions, methods, classes
- `define-command` (explain what the command does)
- Generic functions (`:documentation` option)
Important functions should explain "why", not just "what".
severity: warning
# === Lem-Specific ===
- name: internal_symbol_rule
prompt: |
Use exported symbols from `lem` or `lem-core` package.
Avoid `lem::internal-symbol` access.
If internal access is necessary, document why.
- name: error_handling_rule
prompt: |
- `error`: Internal/programming errors
- `editor-error`: User-facing errors (displayed in echo area)
Always use `editor-error` for messages shown to users.
- name: frontend_interface_rule
prompt: |
Frontend-specific code must use `lem-if:*` protocol.
Do not call frontend implementation directly from core.
severity: warning
# === Functional Style ===
- name: functional_style_rule
prompt: |
Prefer explicit function arguments over dynamic variables.
Avoid using `defvar` for state passed between functions.
Exception: Well-documented cases like `*current-buffer*`.
- name: dynamic_symbol_call_rule
prompt: |
Avoid `uiop:symbol-call`. Rethink architecture instead.
If unavoidable, document the reason.
# === Libraries ===
- name: alexandria_usage_rule
prompt: |
Alexandria utilities allowed: `if-let`, `when-let`, `with-gensyms`, etc.
Avoid: `alexandria:curry` (use explicit lambdas)
Avoid: `alexandria-2:*` functions not yet used in codebase
# === Macros ===
- name: macro_style_rule
prompt: |
Keep macros small. For complex logic, use `call-with-*` pattern:
```lisp
(defmacro with-foo (() &body body)
`(call-with-foo (lambda () ,@body)))
```
Prefer `list` over backquote outside macros.📚 About Code ContractorDeclarative Code Standards That Learn and Improve Define domain-specific validation rules in YAML. Want this for your repo? |
There was a problem hiding this comment.
Pull request overview
This PR adds Ansible editing support to Lem by introducing a new ansible-mode that builds on the existing YAML mode, and it wires up LSP configurations for both YAML and Ansible language servers.
Changes:
- Register the new
lem-ansible-modeextension in the main extensions system. - Add a YAML LSP language spec (
yaml-language-server) and wire it intolem-yaml-mode. - Introduce
ansible-mode(derived fromyaml-mode) plus an Ansible LSP language spec (ansible-language-server) and user-facing README.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
lem.asd |
Registers lem-ansible-mode as part of lem/extensions. |
extensions/yaml-mode/yaml-mode.lisp |
Exports *yaml-syntax-table* so other modes (Ansible) can reuse it. |
extensions/yaml-mode/lsp-config.lisp |
Adds YAML LSP spec and initialization options. |
extensions/yaml-mode/lem-yaml-mode.asd |
Adds lem-lsp-mode dependency and includes the new lsp-config component. |
extensions/ansible-mode/README.md |
Documents ansible-mode features and suggested setup steps. |
extensions/ansible-mode/ansible-mode.lisp |
Implements ansible-mode and heuristic detection hook to switch from yaml-mode. |
extensions/ansible-mode/lsp-config.lisp |
Adds Ansible LSP spec (parented from YAML spec). |
extensions/ansible-mode/lem-ansible-mode.asd |
Declares the new extension system and its dependencies/components. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+14
to
+15
| (defmethod spec-initialization-options ((spec yaml-spec)) | ||
| (make-lsp-map "yaml.format.enable" +true+)) |
Comment on lines
+15
to
+19
| (setf (variable-value 'enable-syntax-highlight) t | ||
| (variable-value 'indent-tabs-mode) nil | ||
| (variable-value 'tab-width) 2 | ||
| (variable-value 'calc-indent-function) 'nil | ||
| (variable-value 'line-comment) "#")) |
Comment on lines
+39
to
+56
| Once `ansible-language-server` is installed on your system, start LSP support in the current buffer: | ||
|
|
||
| ``` | ||
| M-x lsp-mode | ||
| ``` | ||
|
|
||
| To automatically start LSP whenever `ansible-mode` is activated, add a hook to your initialization file. | ||
|
|
||
| ## Configuration | ||
|
|
||
| Add the following to your Lem configuration file (`~/.lem/init.lisp` or `~/.config/lem/init.lisp`): | ||
|
|
||
| ### Automatic LSP Activation | ||
|
|
||
| ```lisp | ||
| (add-hook lem-ansible-mode:*ansible-mode-hook* | ||
| 'lem-lsp-mode:lsp-mode) | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pr adds a mode for ansible via ansible-language-server . Ansible mode reuse the yaml mode .It also adds a lsp for yaml