Closed gerhardol closed 5 years ago
@gerhardol I don't know this format in particular, but does it not start with an XML-like preamble? There are so many XML formats out there that it might be more robust to detect XML data rather than trying to list all known formats. I thought we already did this to be honest, but I may misremember.
but does it not start with an XML-like preamble?
Yes, but that does not seem to be detected, not sure if it is even attempted. User configuration would be nice too, this is the simplest way right now.
Auto-detection of JSON files would also be possible and could catch a lot of cases.
For XML, something like the following should help:
using (var reader = XmlReader.Create(stream))
{
// Try reading nodes to see if this is XML. If we can read 10 nodes, assume the rest is XML.
try
{
int nodes = 0;
while (reader.Read() && nodes++ < 10) { }
return true;
}
catch (XmlException)
{
return false;
}
}
Auto detection will be more difficult on diff view etc.
Auto detection will be more difficult on diff view etc.
I think we use a special 'diff' syntax for diff views, and ignore the file extension. I may misremember.
I think we use a special 'diff' syntax for diff views, and ignore the file extension. I may misremember.
I can only find that the highlight strategy is set from the filename also for diff, like:
internalFileViewer.SetHighlightingForFile(filename);
For normal files, the content blob is available (even if not yet when when highlight syntax is set). For diff the blob must be retrieved separately.
I do not think this is very important and adding some formats manually is not a big issue. Opened https://github.com/gitextensions/gitextensions/issues/7323
This is the diff/patch handling I was thinking of:
This is the diff/patch handling I was thinking of:
In master, there is no highlight in diff at all. That line just resets the highlighting (confusing though, first sets in internalFileViewer.SetHighlightingForFile(fileName), then overrides in ResetForDiff). This handling is changed in https://github.com/gitextensions/gitextensions/pull/7291 (even on not this line). (This line may also handle just the extension .diff etc too, may not be needed.)
XML format, see autosar.org