Code Monkey home page Code Monkey logo

compose-language-service's Introduction

Docker Compose Language Service

Node CI Build and Test

Overview

This project contains a language service for Docker Compose, implementing the Language Server Protocol. It is shipped in the Docker extension for Visual Studio Code.

Features

The Compose Language Service offers some common language service features like completions, signatures, diagnostics, document formatting, and hover hints. In addition, it contains some Docker-specific features like image names becoming hyperlinks to their corresponding pages on Docker Hub.

The language service is intended to work primarily for the Compose file version 3 spec--it will not support properties specific to versions 1 or 2--but it shouldn't interfere with development in such documents either.

The language service is a work-in-progress, and will continue adding new features and functionality each release.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Telemetry

VS Code collects usage data and sends it to Microsoft to help improve our products and services. Read our privacy statement to learn more. If you don’t wish to send usage data to Microsoft, you can set the telemetry.enableTelemetry setting to false. Learn more in our FAQ.

This language service will emit VS Code-specific telemetry events. If using the service outside of VS Code (e.g. in Vim), these telemetry events can be safely ignored.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

compose-language-service's People

Contributors

bwateratmsft avatar dependabot[bot] avatar microsoftopensource avatar uchenkadicode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

compose-language-service's Issues

Use Intellisense to cut down on service attribute suggestion list

Rather than having multiple duplicate selections when a user presses ctrl + space eg, port short version, port long, build short, build long, command for echo or command for [echo, hello], I think it would be great to only give the user just one suggestion of that attribute then we put their cursor at a place where the next hit of Space, will bring up the suggestions available, then they can easily scroll through it.

I'd love most of the behavior to be coalesced into the example below.

User sees just one suggestion for volumes
image

Instead of giving them this:
image

We instead start their cursor right next to the dash
image

And then hitting space button does this automaticaly in VS Code
image

Adding this for most if not all of the duplicate selections will help cut down on confusion navigating through the tree of possible completions, and provide the user a better in-line authoring experience.

Right now we have quite a few duplicates in the selection and I can see this list growing over time
image

Formatting Documents does not fix indentation

When the compose file looks like this
image

Pressing shift alt F gives me this

image

Also, a weird quirky bug, but after I format the document, sometimes when hitting control Z (undo)

I get null on some of the attributes. This may be because I hadn't put a value there yet but I'm not totally sure

More Opinionated spacings on formatting Compose file

In this example, values under an attribute remain spaced out. I think that attribute names can remain spaced such as ports and volumes, but for the value under volumes, it should be thrown right under the volumes attribute

BAD_INDENT false positive if alias is used as mapping key in Docker Compose file

When alias is used as a key in services: mapping, e.g.

version: "3.8"

x-service:
- &foo_service foo

services:
  *foo_service:
    image: alpine

  bar:
    image: busybox
    depends_on:
    - *foo_service

...extension reports Problems:

[{
	"resource": "/C:/Users/i-ky/docker-compose.yml",
	"owner": "_generated_diagnostic_collection_name_#1",
	"code": "BAD_INDENT",
	"severity": 8,
	"message": "All mapping items must start at the same column",
	"startLineNumber": 8,
	"startColumn": 1,
	"endLineNumber": 8,
	"endColumn": 2
},{
	"resource": "/C:/Users/i-ky/docker-compose.yml",
	"owner": "_generated_diagnostic_collection_name_#1",
	"code": "BAD_INDENT",
	"severity": 8,
	"message": "All mapping items must start at the same column",
	"startLineNumber": 9,
	"startColumn": 1,
	"endLineNumber": 9,
	"endColumn": 2
}]

The config file is actually fine and no diagnostics should be emitted:

PS C:\Users\i-ky> docker-compose config
services:
  bar:
    depends_on:
      foo:
        condition: service_started
    image: busybox
  foo:
    image: alpine
version: '3.8'

Extension version: 1.19.0
VS Code version: 1.63.2

Format Document command inserts unnecessary `null` values into the docker-compose.yml file

There is an issue when calling 'Format Document' on a Docker compose file in Docker plugin v1.18.0
When called additional null values are added to the file.

Reproduction Scenario

  1. Create docker-compose.yml file with the following content
version: "3"
services:

  service:
    image: service

networks:
  a-net:
  b-net:

volumes:
  a-data:
  b-data:
  c-data:
  d-data:
  1. In VsCode invoke a 'Format Document' command
  2. Note the added null values to the file:
version: "3"
services:

  service:
    image: service

networks:
  a-net: null
  b-net:

    null
volumes:
  a-data: null
  b-data: null
  c-data: null
  d-data: null

VsCode Version

Version: 1.62.3 (system setup)
Commit: ccbaa2d27e38e5afa3e5c21c1c7bef4657064247
Date: 2021-11-17T08:11:14.551Z
Electron: 13.5.2
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Windows_NT x64 10.0.19042

Map keys must be unique (DUPLICATE_KEY) on anchors

The following yaml is a valid docker-compose.yaml declaration but vscode shows a "Map keys must be unique (DUPLICATE_KEY)" error on the <<: *bar line.

version: 3.8

x-foo: &foo
  FOO: FOO

x-bar: &bar
  BAR: BAR

services:
  foo-bar:
    image: my-image
    environment:
      <<: *foo
      <<: *bar

Disabling the docker extension ms-azuretools.vscode-docker make the error disappear.

This issue is fixed in the YAML parser, see eemeli/yaml#21

Everything needs unit tests

Add unit tests for tons of things:

  • Compose document (especially pathing logic)
  • KeyHoverProvider
  • Completion providers
    • Root
    • Service
    • Volumes
    • Ports
  • Diagnostic provider
  • Formatting provider
  • Image link provider
  • Utilities
    • debounce
    • Lazy
    • ActionContext
    • yamlRangeToLspRange
    • Telemetry
      • TelemetryAggregator
      • logNormal

Prioritization of Compose Language Service Improvements V1

This list is in Priority order. We want to have snippets that help our customers and then give them examples of the various signatures that could complete their statement.

  • Image links
  • Hover help
  • Volume snippets
  • Port snippets
  • (Validation) Syntax (indentation, etc.)
  • #57
  • #58

Volume signatures
Port signatures

Formatting Docker Compose files removes the YAML document end

Hi all!

I noticed that formatting a Docker Compose file strips away the YAML end document marker (...). This doesn't happen if you manually set a Docker Compose file as a YAML file, and format it.

Steps to reproduce:

  1. Create a Docker Compose file named compose.yaml (although any other file name recognized by the dockercompose language definition would work).
  2. Ensure that VS Code recognizes the file compose.yaml file as a Docker Compose file (look for the Compose language mode in the status bar (bottom right).
  3. Paste the following content in the file:
    ---
    services:
      test-service-1:
    ...
  4. Save the file.
  5. Format the file (if you don't have "Format on Save" enabled).

The resulting, formatted file is:

---
services:
  test-service-1:

While I was expecting:

---
services:
  test-service-1:
...

Is this behavior something I can configure? Or is it a bug?

Thanks!

compose.yaml image link support for other container registries

Currently if you have for example image: browserless/chrome in your compose.yaml it will be Ctrl+Clickable directing to https://hub.docker.com/r/browserless/chrome

Would be nice if it could also offer the same for other container registries, like image: ghcr.io/browserless/chrome. I think it doesn't need much work, because http://ghcr.io/browserless/chrome will redirects you to https://github.com/browserless/browserless/pkgs/container/chrome, but other registries might not provide redirect to human readable websites, would need to test what else is out there.

Idea: IntelliSense for selecting the correct file path in Volumes in Compose

As the user aims to type their volumes command in compose, we provide them with

volumes:
- hostFilePath:/containerPath

As the user types their volume in composefile (as seen below)

volumes:
- ./src/Services/DomainAPI/data/mssql:/scripts/

We provide them the context and tab completion of both their host directory and their container directory (if possible). Even if they start from β€œC://User/”. The example above is a relative path.

Compose Format Document rounds big numbers

Let's say I have this (fake for the example) key-value in my compose.yaml:

environment:
  discord_id: 1147053346671102335

When I select Format Document it will round 1147053346671102335 to 1147053346671102300, which I don't think I need to explain why is bad.

Of course I can quote it to make into a string, but was blindsided by this behavior, would be nice to save others from it.

How to change environment variables to map syntax

Hello, when the extension auto-suggests an environment variable, it always writes them in the array form, like in the picture. I'd like to change it to write the variables in map syntax.

From this:
image

To this:

environment:
    VAR: value

Version: 1.22.1 - 30 June 2022

How to disable telemetry for clients other than VSCode?

I am using Neovim and its build in LSP client. That client allows me to pass in settings object that I believe are used to configure server. From documentation:

                  β€’ settings: Map with language server specific settings.
                    These are returned to the language server if requested via
                    `workspace/configuration`. Keys are case-sensitive.

I have therefore configured it as such, based on https://github.com/microsoft/compose-language-service#telemetry:

vim.lsp.start {
    name = 'docker-compose',
    cmd = { 'docker-compose-langserver', '--stdio' },
    root_dir = vim.fs.dirname(vim.fs.find({ '.git' }, { upward = true })[1]),
    settings = { telemetry = { enableTelemetry = false } },
}

hoping that this will disable telemetry. It did not. Following events still get logged:

.../vim/lsp/rpc.lua:387    "rpc.receive"   {  jsonrpc = "2.0",  method = "telemetry/event",  params = {    eventName = "KeyHoverProvider",    groupingStrategy = "eventNameAndProperties",    measurements  […]

How should telemetry be disabled correctly? Thanks!

Idea: Compose schema validation

Add functionality for validating a document against the Compose schema, to ensure it is not just valid YAML, but a valid Compose document too.

Improve UT fragility

While working on #98, I found a test failure due to a new Node version. There was a slight change to the error message that Node.js would output.

This isn't great; ideally it would be more flexible to changes like this.

Idea: Image autocomplete suggestions

OS: All
Build Version: 20210204.1

Repro Steps:

  1. Create a project and open in VS Code -> Open the docker-compose.yml file.
  2. Type the following into the docker-compose.yml file:
     version: '2'
     redis:
         image: 
  1. Press CTRL+SPACE -> Select "centos" -> Press CTRL+SPACE -> Select an image.
  2. Cursor is placed after "centos" -> Press CTRL+SPACE -> Select an image(same/different).
  3. Check whether the image is replaced automatically.

Actual:
The image is not replaced automatically.
ima

Suggestion:
It would be better to replace the image automatically.

Please add a binary to launch the server

Would it be possible to add a binary docker-compose-language-service to launch the server?

Right now we have to execute node @microsoft/compose-language-service from the terminal.

We created a wrapper here, an exectuable docker-compose-language-service with:

#!/usr/bin/env bash

exec node $PATH_TO_MODULES/@microsoft/compose-language-service/lib/server.js" "$@"

We try to automate the configuration of the server here and it assumes the wrapper exists.

Things would be simpler if the binary existed already :-)

Thank you in advance

Compose language service doesn't recognize `restart` option

Example compose file:

version: '3.4'

services:
  test:
    restart: always
...
  1. Howering over restart doesn't yield any results
  2. If you remove always and try to invoke completions there, no results are shown, even though restart in docker compose has a finite set of well-known values: no, always, on-failure, unless-stopped

Docker Compose: Wrapping of Lines >80 characters

I'm running into an issue where lines that are longer than 80 characters are automatically wrapped and indented and ignores other editor settings (e.g. wordWrapColumn, minimap.maxColumn, etc.). The only way that I can get the file to stop wrapping when formatted is to set docker.enableDockerComposeLanguageService to false, which kind of defeats the purpose. Is there a setting somewhere I'm overlooking that changes the auto-wrapping applied to files set to the dockercompose language?

Idea: Linting support for docker-compose.yml files

It would make it a lot simpler to author Dockerfile and docker-compose.yml files if you could view actionable linting errors from within VS Code. For example, Docker Compose includes JSON schema files for its various formats (e.g. v2.0) that document how to determine whether a compose file is valid or not.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.