microsoft / VS-PPT

Productivity Power Tools - a set of Visual Studio extensions improving developer productivity.
http://aka.ms/extendvs
Other
886 stars 146 forks source link

Copy As Html doesn't copy C# or F# colour #271

Closed ploeh closed 5 months ago

ploeh commented 9 months ago

When using the Copy As Html extension with C#, it no longer includes any colour information.

Let's say I'd like to copy this line of code: image Using Edit, Copy Html Markup, this is what I get:

var zeroes = new byte[k];

No colour information about any of the keywords.

The same is true if I try to copy some F# code.

Surprisingly, however, the extension does work with Python code: image If I copy this as HTML, I get this:

<span style="color:green;">#!/usr/bin/env&nbsp;python</span>
<span style="color:blue;">import</span>&nbsp;numpy
<span style="color:blue;">import</span>&nbsp;matplotlib.pyplot&nbsp;<span style="color:blue;">as</span>&nbsp;plt

Even more surprising, it also works with Haskell, for which I've manually installed a TextMate bundle: image becomes

<span style="color:#2b91af;">average</span>&nbsp;<span style="color:blue;">::</span>&nbsp;<span style="color:blue;">Integral</span>&nbsp;a&nbsp;<span style="color:blue;">=&gt;</span>&nbsp;<span style="color:blue;">NE</span>.<span style="color:blue;">NonEmpty</span>&nbsp;a&nbsp;<span style="color:blue;">-&gt;</span>&nbsp;a
average&nbsp;nel&nbsp;=&nbsp;<span style="color:blue;">sum</span>&nbsp;nel&nbsp;`div`&nbsp;<span style="color:blue;">fromIntegral</span>&nbsp;(NE.<span style="color:blue;">length</span>&nbsp;nel)

Like the OP of #252 I've modified the BeforeCodeSnippet and AfterCodeSnippet options. I've removed both (setting them to blank values), which explains why the generated code has no surrounding <pre> tag.

As far as I can tell, it looks as though the languages that have 'native' colouring by Visual Studio somehow break the extension. I haven't tried with Visual Basic, but this seems to apply to both C# and F# in both light and dark mode.

ploeh commented 9 months ago

Here's another observation: The setting UnindentToRemoveExtraLeadingWhitespace is set to True, which I believe is the default. This setting, however, is not consistently applied.

Here's what I highlight: image Here's what I get:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;double&nbsp;value1&nbsp;=&nbsp;100.00D;
double&nbsp;value2&nbsp;=&nbsp;15.99D;
double&nbsp;result&nbsp;=&nbsp;client.Add(value1,&nbsp;value2);
ploeh commented 9 months ago

I've managed to reset the extension to use default values (i.e. defaults for BeforeCodeSnippet and AfterCodeSnippet), but that doesn't help.

BertanAygun commented 8 months ago

Hi @ploeh, can you confirm if you have this option enabled:

We added support for accurate classification for more accurate colors based on Tools -> Options -> Text Editor -> Advanced -> "Use accurate classifier" setting. Please note that copy operations can be slower when this setting is enabled.

Thanks, Bertan

ploeh commented 8 months ago

It's getting late here in Copenhagen, so it's possible that I'm just too tired, but where do I find that setting?

image

BertanAygun commented 8 months ago

I also just realized that setting no longer exists in product so I will have to investigate and reply back here.

Thanks, Bertan

olegtk commented 8 months ago

"Use accurate classifier" setting was really bad perf-wise in general case and was removed in 17.9. I suggest either just make CopyAsHTML always call accurate classifier or introduce it's own CopyAsHTML-specific option to control whether to use accurate classification, and make it default.

olegtk commented 8 months ago

I have a fix for CopyAsHTML, will push an update soon. The root cause turned to be this change in Roslyn behavior: https://developercommunity.visualstudio.com/t/ITagAggregatorIClassificationTag-no-lo/10595181

ploeh commented 8 months ago

I have a fix for CopyAsHTML, will push an update soon.

Looking forward to it!

The root cause turned to be this change in Roslyn behavior: https://developercommunity.visualstudio.com/t/ITagAggregatorIClassificationTag-no-lo/10595181

Ooh, a breaking change in a Microsoft product!

ploeh commented 8 months ago

Any news on when we can expect the update?

ploeh commented 7 months ago

ping

iccfish commented 7 months ago

Seems this extension out of maintenance?

heiligerdankgesang commented 7 months ago

Thanks for following up, folks. While we do have a fix, there’s some additional work that needs to be completed before we can update the extension with the fix and make it available for use. We don’t yet have a timeline for release, but please keep an eye on this issue for further updates.

ploeh commented 5 months ago

It works again! Thank you; I'm very happy.