mike-ward / VSColorOutput

Color highlighting to Visual Studio's Build and Debug Output Windows
MIT License
429 stars 93 forks source link

Functionality lost after saving Output Window as a text file. #68

Closed JohnTasler closed 4 years ago

JohnTasler commented 6 years ago

I recently needed to save my Output Window contents to a file, so I pressed Ctrl+S. In addition to saving to a file, it also caused the extension to stop working. All the timestamps disappeared and all the color formatting was lost. Functionaly was restored after restarting VS. This happened in VS2017 15.4.5. BTW, I LOVE, LOVE, LOVE this extension and, of course, have donated at least once.

mike-ward commented 6 years ago

Interesting. It seems to only kill it in the window you do the save from. If I save the debug bug output it behaves as you say, but ut the build window still has highlighting. Wonder if they are creating a new window and reassigning it?

Dmitry-Me commented 4 years ago

Here's some findings. I changed the ContentType on OutputClassifierProvider

[ContentType("output")]
>>>
[ContentType("text")]

and the coloring started working for all text, source code included, but it would survive saving the contents of the "output" window now.

So I put a breakpoint into GetClassifier() and stared into buffer variable for a while. Before the "output" window contents was first saved the buffer.ContentType is of "Output" type. After the "output" window contents was first saved the next calls to GetClassifier() would have buffer with buffer.ContentType of "plaintext" type. Even if the project is built again there're no new calls to GetClassifier() so it looks like the "output" continues to be of "plaintext" type from the very moment it is first saved to a file using Ctrl-S.

This looks weird. It looks like a Visual Studio bug. Why would content change it's type and why would it change it permanently?

Looks like there is a workaround however I'm not sure how reliable it is. When [ContentType] is set to "text" then GetClassifier() is invoked for whatever text. From inside GetClassifier() the buffer.ContentType can be checked and if it's something like "CSharp" then this need not be colored and returning null looks like a working way to say "no, thank you, I will not color this". If buffer.ContentType is "output" or "plaintext" then buffer.Properties can be inspected. For cases when it's a text file in the editor there're some properties such as LongestLineLength and WhitespaceManager which are not there for "output" window content. So if these properties are there then return null as in "won't color this, thank you".

mike-ward commented 4 years ago

Thanks @Dmitry-Me. Nice investigation and fix. Will include in release 2.7

mike-ward commented 4 years ago

Scheduled for v2.7