Skip to content

[#1655] Fix and enable LSP formatting

Sorokin-Anton requested to merge Sorokin-Anton/#1655-cst-formatting into dev

Motivation and Context

Our LSP is reading file from disk while executing formatting requests, so some changes can be lost. Because of this, formatting is temporarily disabled. Related Issue(s):

Checklist for the LIGO Language Server

  • I checked whether I need to update the file for the plugin and did so if necessary
  • I checked that my changes work in Emacs, Vim, and Visual Studio Code
  • (Before merging) The commit history is squashed and prettified, and follows the Serokell commit policy, or the MR is set to squash the commits


Formatting was implemented as parsing a CST and then printing it by calling different functions from LIGO API. Now we pretty print a CST using Parsing_(...).Pretty.print directly, sending contents of an actual doc to it. Enable formatting. Also now LSP doesn't need to depend on printing part of LIGO API, so we can remove it from Ligo_interface.LIGO_API module type.


  • compiler
  • website
  • webide
  • vscode-plugin
  • debugger

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Performance improvement (non-breaking change that improves performance)
  • None (change with no changelog)


Added support for document formatting request to ligo lsp.


  • Changes follow the existing coding style (use dune @fmt to check).
  • Tests for the changes have been added (for bug fixes / feature).
  • Documentation has been updated.
  • Changelog description has been added (if appropriate).
  • Start titles under ## Changelog section with #### (if appropriate).
  • There is no image or uploaded file in changelog
  • Examples in changed behaviour have been added to the changelog (for breaking change / feature).
Edited by Sorokin-Anton

Merge request reports