Skip to content

Syntax highlighting for .arxml #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2019
Merged

Syntax highlighting for .arxml #15

merged 1 commit into from
Oct 18, 2019

Conversation

gerhardol
Copy link
Member

XML format, see autosar.org

@ghost ghost assigned gerhardol Oct 16, 2019
@drewnoakes
Copy link
Member

@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.

@gerhardol
Copy link
Member Author

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.

@drewnoakes
Copy link
Member

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;
    }
}

@gerhardol
Copy link
Member Author

Auto detection will be more difficult on diff view etc.

@drewnoakes
Copy link
Member

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.

@gerhardol
Copy link
Member Author

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 gitextensions/gitextensions#7323

@drewnoakes
Copy link
Member

@gerhardol
Copy link
Member Author

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 gitextensions/gitextensions#7291 (even on not this line).
(This line may also handle just the extension .diff etc too, may not be needed.)

@pmiossec pmiossec merged commit 9b0b997 into master Oct 18, 2019
@pmiossec pmiossec deleted the feature/arxml branch October 18, 2019 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants