Skip to content

[#1655] LSP: Implement range formatting for toplevel statements

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

Motivation and Context

Our formatting currently erase comments, so users may want to run formatting only on some range in a file. There is a range formatting LSP request that allows this.

Related issues

Resolves #1655 (closed) .

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


Implement range formatting via replacing all toplevel statements in given range with theit pretty-printed version. We should do the same with at least statements in local modules. To obtain ranges of toplevel statements, some changes in LIGO are required:

First, in some dialects there is no function that extracts range of a toplevel declaration in CST module.

Second, Region.cover was supposing that given regions are not intersecting, while in JsLIGO we can insert a semicolon with region intersecting the rigion of a statement during self-pass. Also we need to expose a function that prints a declaration for each dialect.

Also there is a commit that makes the output of LSP tests more readable.


  • 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 range formatting to LSP. It can be used to format all toplevel declarations in a given range.


  • 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