Skip to content

Autoformat file on save #2714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spotlesscoder opened this issue Feb 10, 2021 · 5 comments
Closed

Autoformat file on save #2714

spotlesscoder opened this issue Feb 10, 2021 · 5 comments

Comments

@spotlesscoder
Copy link

spotlesscoder commented Feb 10, 2021

Take the following file

version: '3.8'

services: 
  elasticsearch:
    image: docker.elastic.co/elasticsearch
    ports: 
      - 9200:9200
    - 9300:9300

You see the indentation is incorrect. When I save the file it should automatically correct the indentation

@bwateratmsft
Copy link
Collaborator

Another good suggestion, thanks! I've added this one to #2539 as well.

@PavelSosin-320
Copy link

@bwateratmsft Before going on this adventure please, check:

  1. Formater and Linter use the same tokenizer and it is 100% reliable. Token list must be stable!
  2. Git: ignore whitespace is used overall.
  3. File is marked as modified after formatting, otherwise save may do nothing. Save after Linter warnings is possible or with approval, at least. Otherwise, if formatting can't be accomplished due to incomplete code changes the user will be stuck.
  4. Good luck!

@PavelSosin-320
Copy link

@bwateratmsft Sorry for returning to this issue!
The LSP assumes that the file is formatted by the Language server upon receiving the notification willSsave and the server must return all "edits" to the client. It turns the state of the file to "modified". If If the language server confirms server capability The linter and the formatter share the tokenizer and the tokens list. So, this PR should be redirected to the Language Server implementation. The client must send willSave, didSave. and process willSave response. Hopefully, VSCode does it.

@bwateratmsft
Copy link
Collaborator

That's the thing--right now, there is no language server for compose. The YAML extension provides a language server for YAML more generally, and probably supports formatting, but not for Compose specifically. We're probably gonna end up making a language server for compose, which is what #2539 is largely about.

@PavelSosin-320
Copy link

Yes, I think there is no alternative. EGamma will be very disappointed if it will be not done. But also shame to development teams that proposed languages without publishing their Language formal gramars in the BNF or ANTLR forms.

@vscodebot vscodebot bot locked and limited conversation to collaborators Mar 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants