Skip to content

Adding Dockerfile mode - #2279

Open
Pythonpoison48 wants to merge 2 commits into
lem-project:mainfrom
Pythonpoison48:Dockerfile
Open

Adding Dockerfile mode#2279
Pythonpoison48 wants to merge 2 commits into
lem-project:mainfrom
Pythonpoison48:Dockerfile

Conversation

@Pythonpoison48

Copy link
Copy Markdown

Hello I propose to add a dockerfile-mode.

Currently it has lsp via docker-language-server on nodejs.
The mode has tree-sitter support.

Copilot AI lite review requested due to automatic review settings August 27, 2026 19:26
@code-contractor-app

code-contractor-app Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Commit 0dcf72b has not been validated yet. The results below are for a previous commit. Comment /rerun (keeps dismissed violations dismissed) or @code-contractor-app to re-validate.

❌ Code Contractor Validation: FAILED

📌 Result for commit 4a5a147

=== Contract: contract ===

✓ Code Contractor Validation Result
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

📋 Contract Source: Repository

📊 Statistics:
  Files Changed:    6
  Lines Added:      238
  Lines Deleted:    0
  Total Changed:    238
  Delete Ratio:     0.00 (0%)

Status: FAILED ❌

🤖 AI Providers:
  - codex — model: (Codex default)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠️ Violations Found (3):

[ERROR] file_structure_rule
  AI check failed: "file_structure_rule"
  ❌ Reason:
    `defvar` appears after function definitions in `dockerfile-mode.lisp`,
    which violates the required top-to-bottom file organization.

[ERROR] dynamic_symbol_call_rule
  AI check failed: "dynamic_symbol_call_rule"
  ❌ Reason:
    The added test system uses `symbol-call`, which the rule disallows
    unless unavoidable and documented; no justification is provided in the
    diff.

[ERROR] macro_style_rule
  AI check failed: "macro_style_rule"
  ❌ Reason:
    Backquote is used in ordinary function code outside a macro, where the
    rule prefers explicit list construction.
📋 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.

💬 Feedback

Reply to a violation comment with:

  • /dismiss <reason> - Report false positive or not applicable

🔁 Re-validation

Validation does not re-run automatically when you push fixes. Trigger it with one of:

  • Comment /rerun to re-run validation (dismissed violations stay dismissed)
  • Click Run Validation on the Code Contractor check in the Checks tab
  • Comment @code-contractor-app on this pull request

To reset all dismissals and re-judge every violation, comment /revalidate instead (restores previously dismissed violations; requires write permission).

📚 About Code Contractor

Declarative Code Standards That Learn and Improve

Define domain-specific validation rules in YAML.
Your contracts document team knowledge and evolve into more accurate AI enforcement.

Want this for your repo?
Install Code Contractor

@code-contractor-app code-contractor-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Contractor validation failed ❌ — see the sticky comment for full results.

(make-tmlanguage :patterns patterns)))


(defvar *dockerfile-syntax-table*

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Contractor: file_structure_rule

Contract: contract

AI check failed: "file_structure_rule"

Reason:
defvar appears after function definitions in dockerfile-mode.lisp, which violates the required top-to-bottom file organization.


💬 Reply /dismiss <reason> to dismiss this violation.

:depends-on ("lem-dockerfile-mode" "rove")
:components ((:module "tests"
:components ((:file "main"))))
:perform (test-op (op c) (symbol-call :rove '#:run c))) No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Contractor: dynamic_symbol_call_rule

Contract: contract

AI check failed: "dynamic_symbol_call_rule"

Reason:
The added test system uses symbol-call, which the rule disallows unless unavoidable and documented; no justification is provided in the diff.


💬 Reply /dismiss <reason> to dismiss this violation.

(defun tokens (boundary strings)
"Create a regex alternation pattern from STRINGS, optionally wrapped with BOUNDARY."
(let ((alternation
`(:alternation ,@(sort (copy-list strings) #'> :key #'length))))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Contractor: macro_style_rule

Contract: contract

AI check failed: "macro_style_rule"

Reason:
Backquote is used in ordinary function code outside a macro, where the rule prefers explicit list construction.


💬 Reply /dismiss <reason> to dismiss this violation.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new lem-dockerfile-mode extension to Lem, providing Dockerfile/Containerfile editing support with syntax highlighting, tree-sitter highlighting queries, and LSP integration via dockerfile-language-server-nodejs.

Changes:

  • Register the new lem-dockerfile-mode system in the main lem.asd.
  • Add a Dockerfile major mode (syntax table + TextMate-style patterns) with optional tree-sitter highlighting.
  • Add LSP language spec configuration and basic rove tests for mode registration/comment syntax.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lem.asd Adds lem-dockerfile-mode to the set of included systems.
extensions/dockerfile-mode/dockerfile-mode.lisp Implements dockerfile-mode, syntax table, and tree-sitter enablement hook.
extensions/dockerfile-mode/lsp-config.lisp Adds LSP language spec for Dockerfile via docker-langserver --stdio.
extensions/dockerfile-mode/tree-sitter/highlights.scm Provides tree-sitter highlight queries for Dockerfile grammar nodes/tokens.
extensions/dockerfile-mode/lem-dockerfile-mode.asd Declares the extension system and its test system.
extensions/dockerfile-mode/tests/main.lisp Adds initial rove tests for mode registration and comment variables.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread extensions/dockerfile-mode/dockerfile-mode.lisp Outdated
Comment on lines +5 to +8
(deftest test-mode-activates
(testing "mode activates for Dockerfile and Containerfile"
(ok (lem:find-mode "Dockerfile")
"Mode should be registered as Dockerfile")))
At first while implementing I thought about using dockerfmt to format the dockerfile. But since it's not bundled with docker or the lsp, so I thought it was better to use formatting bundled with the lsp but I forgot to remove the formatter from the mode definition

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants