Monday, March 16, 2020

Introducing: Clearly Editable - making it clear which documents can be edited in Visual Studio

The way some people* use Visual Studio means that they may use or open generated or read-only documents.

There can be lots of reasons for this:

  • They might generate code with a tool.
  • They may need to debug the compiler-generated code.
  • They might use a version control tool that locks files by making them read-only.
  • Many other, valid, reasons...

When working with such files, it can be REALLY frustrating when:

  • you start typing in a document but nothing happens (because it's read-only.) or
  • you make some changes in a generated document (because you don't realize it's generated) and those changes are lost when the file is regenerated.


Visual Studio already has some ways to try and help avoid the above scenarios but they're not always enough.

When a read-only file is open this icon is shown in the tab.
But it's small and easy to miss.

Generated documents typically have a comment in the header of the document to point out that it's been generated and should not be edited directly.
//---------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//---------------------------------------------------------
But, comments aren't always read, or even visible. It can also be easy to forget that a document is generated when switching between documents or if it's been open for a long time.


I present an alternative solution.

It changes the background color of the editor to make it harder to forget or miss if a file is read-only or generated.

The image below shows three open documents.

  • The document on the left is a generated file and has the background set to a pale green color.
  • The middle document is a read-only file and has the background set to a pale red color.
  • The document on the right is neither generated or read-only, just like most files you work with and so there are no modifications to the configured theme colors.



The intention here is that different background colors are harder to miss.

The colors are configurable.

Change them to what you prefer and what works with your other theme/color settings.

You can set the color by specifying a color name or an RGB HEX code.
Opacity is set by providing a percentage so that is can work with named colors and because calculating RGBA (or ARGB) isn't the simplest thing in the world for everyone.
You can also disable the highlighting of either type of file. Or, disable all functionality without having to uninstall the extension and restart Visual Studio.

Go to Tools > Options > Clearly Editable

Options dialog showing the default settings.


Give it a try by installing it from the Visual Studio Marketplace.
If you like it, please leave a review.
If you encounter any problems or have suggestions, please open an issue on GitHub.



* If this isn't you, that's fine. I have other extensions that might be useful to you.

0 comments:

Post a Comment

I get a lot of comment spam :( - moderation may take a while.