Skip to content

RiccardoSagramoni/vscode-format-document-with-implicit-indent

Repository files navigation

VSCode: format document with implicit indentation

Visual Studio Code TypeScript NodeJS NPM

stability-alpha License: MIT


VS Code extension which is a wrapper for the Format Document command. It automatically indent to the correct level every empty lines after formatting the document.

Features

The extension define a new command Format Document with implicit indent (format-with-implicit-indent.format) which format the current document and apply implicit indentation.

Why?

This extension aims to solve an issue common to the majority of formatting utilities, i.e. removing the indentation from all the empty lines. This can be a very annoying inconvenience for developers who uses IDEs like VS Code, which don't work well when indents are stripped from empty lines, making navigation confusing. (See issue rust-lang/rustfmt#887)

The extension implicit-indent already solves this issue in a clever way, by automatically adding indentation when cursor moves on empty lines.

My extension tries a different approach, by automatically adding indentation to all the empty lines of the document after formatting the document.

Installation

  1. Clone this repository.
  2. Install NodeJS and NPM.
  3. Install extension dependencies
    sudo npm install -g @vscode/vsce
    npm install 
  4. Build the extension
    vsce package
  5. Install the extension
    code --install-extension format-with-implicit-indent-0.0.1.vsix

VS Code configuration

I suggest configuring the IDE with the following setting:

"editor.trimAutoWhitespace": false

In this way, the editor will not automatically trim the whitespaces on empty lines (thus making this extension useless).

Roadmap

  • Optimize indentation algorithm
  • Prepare project for release on VS Code marketplace
    • Documentation
    • Configuration
    • Reduce minimum required IDE version
  • Release v1.0.0

Acknowledgements

About

VS Code extension for formatting the currently opened document and then automatically apply implicit indentation on all the empty lines

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published