heku / Kool.VsDiff

Another open source Visual Studio extension to make file/code comparison easier.
MIT License
17 stars 5 forks source link

Could you add the comparison of last two opened document tabs? #7

Closed ycherkes closed 2 years ago

ycherkes commented 2 years ago

I think it will be very useful to have an option to compare two last opened document tabs like it's done in a Compare plugin of notepad++. Because it's not necessary that the opened file is a part of the solution. It can be externally opened in Visual Studio. Is that possible?

heku commented 2 years ago

I'm not sure if it's possible to detect what tabs are last opened twos, I need investigate. If this is possible, where to display the 'Compare ...' context menu?

ycherkes commented 2 years ago

This menu item can be added not to the context menu but rather to the main "File" menu.

ycherkes commented 2 years ago

The code from the TidyTabs extension can help to figure out the tab opening order.

heku commented 2 years ago

Thanks, I will take a look.

ycherkes commented 2 years ago

Hi @heku, I think it can be even better to add the context menu "Compare to right tab" and "Compare to left tab". Example can be found here https://github.com/billpratt/CloseTabsToRight. What do you think?

heku commented 2 years ago

This way, user always need move the tab to compare to eithor left or right of current tab firstly, I think this is not more friendly than current approcah - copy the content then 'Compare with Clipboard', let's think again to find if there's any better way.

ycherkes commented 2 years ago

Let me describe the root of my problem: I have an extension - Object Dumper. It creates the dumps of debugged objects and opens them as separate documents. Those documents are not part of the solution. But I would like to have the ability to compare two of the generated documents. The 'Compare with Clipboard' approach won't work in this case.

ycherkes commented 2 years ago

I know that the "Miscellaneous Files" can be shown in Solution Explorer, but this option is disabled by default, and not so many people know about that:

image

image

ycherkes commented 2 years ago

Also, there is an issue because both of them are temporary unsaved files.

ComparisonIssue

Please pay attention to file names in a comparison window:

274

heku commented 2 years ago

I see the file name issue, I think I need to look up some vsix docs to fix it.

ycherkes commented 2 years ago

Yup and not file name issue only - it takes the document's text for an active item from the document, but for the second tries to get it from the file, but the file is empty. That's why I'm asking about the comparison of the two tabs.

heku commented 2 years ago

Hi @ycherkes , after a little research, I think we need update our code together to resolve this problem.

Currently this extension supports both VS's builtin file compare service and external tools, these are all based on physical files, i.e. the core API is something like diff(file1, file2).

So, if the physical file contains nothing but VS hold its unsaved changes, then it won't work as your expect, but it looks reasonable to me, for external tools, it's reasonable that they don't know these unsaved content.

And from my test, although VS's builtin diff service take two files path as parameters, seems VS treats them differently, VS loads left file content from physical file, but loads right file with cache (VS unsaved content), that's why left side is empty in your last screenshot.

I also checked your extension's code, looks like you can change this line https://github.com/ycherkes/ObjectDumper/blob/main/src/ObjectDumper/DumpAsCommandHelper.cs#L140 to

newDocument.Save();

Then VS will save the content to pyhsical temp file too, this should fix the issue you have.

Regarding the file name issue, I'll enhance the code, pass the display name to diff tool.

ycherkes commented 2 years ago

Hey @heku, Thanks a lot for your research. I've already fixed the document saving issue - bbf47f505b1af57b89b61f985297cca518fcc34b Thanks a lot, it's amazing :)

heku commented 2 years ago

@ycherkes np, thx for the feedback too.

heku commented 2 years ago

Hi @ycherkes, the file name issue fixed, could you please test the latest dev branch build https://dev.azure.com/heku/d55bc262-1377-4ae3-9410-4c98cfa53de8/_apis/build/builds/149/artifacts?artifactName=drop&api-version=7.0&%24format=zip Thanks.

ycherkes commented 2 years ago

Hi @heku, I've tested a VsDiff.2022.vsix, all works fine! Thank you!

heku commented 2 years ago

@ycherkes Thanks.