microsoft / compose-language-service

Language service for Docker Compose documents
https://www.npmjs.com/package/@microsoft/compose-language-service
MIT License
53 stars 5 forks source link

Feature Request: Sorting Keywords in Docker Compose Files #151

Open Marly212 opened 3 days ago

Marly212 commented 3 days ago

I would like to request a new feature for the VS Code Docker extension that allows for automatic sorting of keywords in Docker Compose files.

Current Behavior

When copying and pasting Docker Compose configurations from various sources (e.g., GitHub repositories), the order of keywords within service definitions is often inconsistent. This inconsistency makes it challenging to quickly read and understand the configuration, especially when working with multiple services or comparing different Compose files.

Proposed Feature

Add an option to automatically sort the keywords within each service definition in a Docker Compose file. This feature would:

  1. Allow users to define a custom sorting order for keywords.
  2. Provide a default sorting order (e.g., image, container_name, environment, volumes, ports, etc.).
  3. Be accessible through a command in the Command Palette or a context menu option when editing Docker Compose files.

Example

Before sorting:

services:
  myapp:
    ports:
      - "8080:80"
    environment:
      - NODE_ENV=production
    image: myapp:latest
    container_name: myapp-container
    volumes:
      - ./data:/app/data`

After sorting (with a predefined order):

services:  
  myapp: 
    image: myapp:latest 
    container_name: myapp-container 
    environment: 
      - NODE_ENV=production 
    volumes: 
     - ./data:/app/data 
    ports: 
     - "8080:80"

Benefits

Implementation Suggestions

bwateratmsft commented 3 days ago

Moving this to the compose language service repo. Thanks for the request!