WinMerge / winmerge

WinMerge is an Open Source differencing and merging tool for Windows. WinMerge can compare both folders and files, presenting differences in a visual text format that is easy to understand and handle.
https://winmerge.org/
GNU General Public License v2.0
6.56k stars 801 forks source link

WinMerge 2.16.12.0 Ignore comment difference / Completely unhighlight the ignored differences does not work when comparing yaml files with # comments #820

Open Andreas-Schniertshauer opened 3 years ago

Andreas-Schniertshauer commented 3 years ago

When comparing two yaml files: m1.yaml

` # m1.yaml --- # Favorite movies

m2.yaml

` # m2yaml --- # My Favorite movies

sdottaka commented 3 years ago

The 'Ignore comment differences' feature uses the syntax highlighter feature of the built-in editor. Unfortunately, the built-in editor doesn't yet support YAML, so '#' in .yaml files aren't recognized as comments.

It may not work, but if you just want to consider '#' as a comment, select View → Syntax Highlighting → Shell menu item and it will recognize '#' as a comment.

image

Petewg commented 3 years ago

@sdottaka Hi, that's an interesting workaround, thank you! but needs to select highlighter any time we enter editor. I wonder whether is possible to permanently set a syntax highlighter (f.e. the C/C++ one) as default? (a possibly better solution could be the ability to add recognizable file extensions to existing highlighter(s), which would eliminate the need for new built-in highlighters. --a similar feature is already implemented in plugins -> plugin settings -> file filters)

regards, Pete

Andreas-Schniertshauer commented 3 years ago

@sdottaka thanks for the hint, it works with the Shell highlighter. Is it possible to implement a special yaml syntax highlighter? Thanks, Andreas.

sdottaka commented 3 years ago

that's an interesting workaround, thank you! but needs to select highlighter any time we enter editor. I wonder whether is possible to permanently set a syntax highlighter (f.e. the C/C++ one) as default? (a possibly better solution could be the ability to add recognizable file extensions to existing highlighter(s), which would eliminate the need for new built-in highlighters. --a similar feature is already implemented in plugins -> plugin settings -> file filters)

Try registering the extension yaml in Shell in the Editor → Syntax category of the Options dialog.

image

sdottaka commented 3 years ago

Is it possible to implement a special yaml syntax highlighter?

I want to implement YAML syntax highlighter, but I don't think it will be implemented soon.

Petewg commented 3 years ago

Try registering the extension yaml in Shell in the Editor → Syntax category of the Options dialog.

Great tip, it works fine. Thank you!

Andreas-Schniertshauer commented 3 years ago

This works fine when comparing .yaml files directly, but I have a .xml file in a .zip, I open the .zip and compare the containing .xml that I convert and display in .yaml format with the help of a plugin using function CWinMergeScript::UnpackFile. WinMerge still uses the .xml Syntax highlighting - maybe because filename extensions shown in WinMerge are still .xml. Is it possible to switch the syntax highlighter of WinMerge programmatically from within a Plugin or to change the extension of the files shown in WinMerge?

sdottaka commented 3 years ago

In recent versions, if the Unpacker plugin defines the PluginUnpackedFileExtension property, it refers to that property to determine the file extension. The example used is as follows.

https://github.com/WinMerge/winmerge/blob/83f3bb964b9cec177db94fe548e461c245567d4d/Plugins/dlls/CompareMSExcelFiles.sct#L389-L391

Andreas-Schniertshauer commented 3 years ago

Thanks for the hint, I use the c++ plugin and implemeted the function as: STDMETHODIMP CWinMergeScript::get_PluginUnpackedFileExtension(BSTR* pVal) noexcept and it get's called, but 4 times see instead of one (see issue https://github.com/WinMerge/winmerge/issues/827#issue-922314711), maybe for every file in my zip (it contains 4 files), but I have different files with different extensions in the zip and only one .xml file. Because I don't know for which file the function is called I return .yaml in all cases. When UnpackFile is called the fileDst parameter has the correct .tmp.yaml extension, but WinMerge still uses syntax highlight XML instead of Shell. It also uses XML syntax highlighting when comparing two xml files directly. Update: I looked into the src of WinMerge and found that the extensions returned by PluginUnpackedFileExtension (called in PluginInfo::MakeInfo) is assigned to PluginInfo::m_ext and that is used only for SetDestFileExtension in fileTransform.cpp::Unpacking, so it can't help with syntax highlighting. Update: I looked into MergeDoc.cpp and found in CMergeDoc::OpenDocs a m_pInfoUnpacker->m_textType that is used as extension if not empty, but this is only set to "xml" in FileTransform.cpp in function Unpacking if handler->m_PluginOrPredifferMode == PLUGIN_MODE::PLUGIN_BUILTIN_XML. A few lines down in FileTransform.cpp in function Unpacking the PluginInfo * plugin is returned and it contains the member m_ext (with content ".yaml" in my case) that can be assigned to handler->m_textType and the syntax highlighting may work.

sdottaka commented 3 years ago

Oh. I'm sorry. The PluginUnpackedFileExtension only determined which window type (text / table / binary / image) to open the file expanded by the Unpacker plugin. I will modify it later so that the obtained extension is reflected in the syntax highlighting.

Andreas-Schniertshauer commented 3 years ago

Thanks a lot, commit https://github.com/WinMerge/winmerge/commit/3a4f7ea5e291a943c0dcdc481e00171fefd308c9 works in all cases: comparing yaml, xml -> yaml and xml in zip -> yaml.