• Stars
    star
    114
  • Rank 308,031 (Top 7 %)
  • Language
    C#
  • License
    Apache License 2.0
  • Created about 11 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Visual Studio - Format Document on Save

VSE-FormatDocumentOnSave

Enables auto formatting of the code when you save a file. Visual Studio supports auto formatting of the code with the CTRL+E,D or CTRL+E,F key shortcuts but with this extension the command Edit.FormatDocument is executed on Save.

Versions

Up until now the extension supported older versions of Visual Studio (2012-2019). Since Visual Studio 2022 there are a lot of breaking changes in the VSIX SDK and it is really hard to support older versions of Visual Studio. For that reason the extension is split into two:

Visual Studio 2022

Going forward this will be the version which will be supported and maintained. If possible, future versions of Visual Studio will be supported within this package.
https://marketplace.visualstudio.com/items?itemName=mynkow.FormatDocumentOnSave

Visual Studio 2012-2019

https://marketplace.visualstudio.com/items?itemName=mynkow.FormatDocumentOnSaveLegacy

Configuration

There are 5 settings which you could configure:

  • Command
  • Allowed extensions
  • Denied Extensions
  • Enable
  • Enable in Debug

Command

This is the Visual Studio command which will be invoked when a document is saved. For multiple values you could use space separated list.

Default

Edit.FormatDocument

CodeCleanup

Many people were asking how to execute a CodeCleanup on save. It is possible to replace the default command with Analyze.RunDefaultCodeCleanupOnSolution which executes all the commands configured in the default profile.

note: In rare occasions VisualStudio2019 enters in a infinite loop. A restart or extension reinstall helps. If you know how to reproduce this bug please log an issue.

Allowed extensions

Specifies all file extensions where the command is allowed to be executed. For multiple values you could use space separated list.

Default

allowed_extensions = .*

Denied extensions

Specifies all file extensions where the command is NOT allowed to be executed. For multiple values you could use space separated list.

Default

denied_extensions =

Debug mode

By default the plugin is disabled in debug mode. You could explicitly configure to have the extension enabled while in a debug session.

Default

enable_in_debug = false

Examples

Scenario 1

  • allowed_extensions = .*
  • denied_extensions = .cs

Result: All documents will be formatted because we explicitly specified that all extensions will be formatted using allowed_extensions = .*.

Scenario 2

  • allowed_extensions =
  • denied_extensions = .js

Result: All documents will be formatted except those with .js extension

Scenario 3

  • allowed_extensions =
  • denied_extensions = .*

Result: No documents will be formatted

Scenario 4

  • allowed_extensions = .cs
  • denied_extensions = .*

Result: Only documents with .cs extension will be formatted

Scenario 5

  • allowed_extensions = .cs
  • denied_extensions =

Result: All documents will be formatted because nothing is denied

Scenario 6

  • allowed_extensions = .cs
  • denied_extensions = .cs

Result: All documents will be formatted because there is a conflict

Visual Studio

You can configure these settings from the Visual Studio Options menu

Format Config

Create a .formatconfig file in the root of your project

Note: If you have a .formatconfig file, the VS options are ignored!

Example

root = true

[*.*]
enable = true
command = Edit.FormatDocument
allowed_extensions = 
denied_extensions = .js .html

Example with multiple commands

root = true

[*.*]

command = Edit.FormatDocument Edit.FormatDocument
allowed_extensions = 
denied_extensions = .js .html

Disable the extension

If you wish to temporarily disable to extension you could press CapsLock.
By default the extension is disabled while in a debug session. You could change that from the configuration. You can enable or disable the extension in the configuration, or disable in a .formatconfig file.

Contribute

To setup development environment follow the steps:

  • Install Visual Studio SDK from Visual Studio Installer https://prnt.sc/umv2ak

  • Clone the project

  • Configure debug Open project properties and go to the Debug tab. Select Start external program: and enter the path to your Visual Studio exe. For example C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\devenv.exe. In the Command line arguments: type /rootsuffix Exp https://prnt.sc/umv47r

  • Debug When you press F5 a new instance of Visual Studio will open. From there you need to load an exising solution, file or create a new one. When you press ctrl + s it will trigger break points you have set in the initial Visual Studio instance.

More Repositories

1

Cronus

Cronus is a lightweight framework for building event driven systems with DDD/CQRS in mind
C#
173
star
2

Hystrix.NET

C#
56
star
3

RedLock

C#
10
star
4

be-a-better-dev

C#
10
star
5

Curator-docker

Alpine image with recurring Elastic Search Curator job
Shell
7
star
6

FileStorage

File storage abstraction over AmazonS3, Azure FS and the file system
C#
7
star
7

Pushnotifications

C#
5
star
8

CountryCodes

C#
4
star
9

log4net.Appender.ElasticSearch

ElasticSearch appender for log4net
C#
4
star
10

ActivityStreams

C#
4
star
11

Cronus.Persistence.Cassandra

C#
3
star
12

Cronus.Transport.RabbitMQ

C#
3
star
13

RestSharp.IdentityModel.Extensions

C#
3
star
14

Khronos

Chronos (Khronos) - Automated time tracking
Swift
3
star
15

EldersSearchView

Custom search view for Android
Kotlin
3
star
16

Hystrix.NET.Dashboard

C#
2
star
17

Multithreading.Scheduler

C#
2
star
18

OAuth2.IdentityKit.Android

Kotlin
2
star
19

Cronus.Persistence.CosmosDb

C#
1
star
20

Elders.Web

C#
1
star
21

MeasureExecutionTime

C#
1
star
22

Cronus.Projection.ElasticSearch

C#
1
star
23

Cronus.Projections.Cassandra

C#
1
star
24

Cronus.DomainModeling

C#
1
star
25

Localizations

Localization abstractions and PhraseApp implementation for .NET applications
C#
1
star
26

Protoreg

Serializer wraping protobuff net.
C#
1
star
27

EldersFirebaseRemoteConfig

Convenience Firebase Remote Config + Combine + SwiftUI
Swift
1
star
28

Home

A starting point for people to learn about Elders' projects
1
star
29

Cronus.Api

C#
1
star
30

Cronus.AspNetCore

A package which gives you extended features for Cronus in Asp.NET Core
C#
1
star
31

Zeus

King of the Gods, god of the sky, symbolized by the thunderbolt. As the ruler of the Olympian gods, Zeus held enormous power and almost absolute authority. His role was primarily to watch over the activities of the other gods, and make sure they weren't exceeding their powers.
C#
1
star
32

Hystrix.NET.MetricsEventStream

Module which exposes metrics in a text/event-stream formatted stream that continues as long as a client holds the connection
C#
1
star
33

Pandora

Pandora was the first human woman in Greek mythology. She was created by the gods Hephaestus and Athena, following the instructions of Zeus, who wanted to punish Prometheus for stealing the fire from the gods to give it to humans. After Prometheus stole the fire and humans gratefully accepted the gift, Zeus decided to give humans a gift that would balance their acquisition of fire. He asked Hephaestus to create the first woman, who would be endowed with numerous seducing gifts that would plague humanity from then on. Athena dressed Pandora in a beautiful silvery gown, a veil and a crown, and taught her weaving. Other gods also contributed to Pandora's creation, by endowing her with such gifts as deceitful nature and a speech of lies. However, the natural gifts of Pandora were not the problem for humanity. The gods also offered her a jar that held within numerous evils, diseases and other pains. With the jar in hand, Pandora was given to Epimetheus, Prometheus' brother, who accepted the divine gift despite his brother's warnings. One day, out of curiosity and not of malice, Pandora opened the lid of the jar, releasing all evils into the world. Shocked by what had happened, she quickly tried to put the lid back, only managing to trap Hope in it. This is how the ancient Greeks believed there was evil in the world. The event of releasing the evils into the world marks the end of the so-called Golden Age of Man in the world, and the beginning of the Silver Age.
C#
1
star